Skip to content

Commit 6af8e51

Browse files
committed
fix failed unittests
1 parent 1197ec7 commit 6af8e51

31 files changed

+151
-138
lines changed

.travis.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ dist: bionic
33
python:
44
- "3.7"
55

6+
install:
7+
- virtualenv venv
8+
- source venv/bin/activate
9+
- pip install -e .[tests]
10+
611
script:
7-
- python setup.py test
12+
- python -m pytest -ra
813

914
deploy:
1015
provider: pypi

setup.py

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
with open("requirements.txt") as requirements:
1111
requires = list(requirements)
1212

13+
extras_requires = {
14+
'tests': ['pytest~=6.2.5']
15+
}
16+
1317
setup(
1418
name='iconsdk',
1519
version=version,
@@ -22,6 +26,7 @@
2226
url='https://github.com/icon-project/icon-sdk-python',
2327
packages=find_packages(exclude=['tests*']),
2428
install_requires=requires,
29+
extras_require=extras_requires,
2530
python_requires='~=3.7',
2631
license='Apache License 2.0',
2732
classifiers=[

tests/api_call/test_call.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,21 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15-
import requests_mock
1615
import json
17-
1816
from unittest import main
1917
from unittest.mock import patch
18+
19+
import requests_mock
20+
2021
from iconsdk.builder.call_builder import CallBuilder
2122
from tests.api_send.test_send_super import TestSendSuper
22-
from tests.example_config import BASE_DOMAIN_URL_V3_FOR_TEST
2323

2424

2525
@patch('iconsdk.providers.http_provider.HTTPProvider._make_id', return_value=1234)
2626
class TestCall(TestSendSuper):
2727

2828
def test_call(self, _make_id):
29+
2930
# with from
3031
test_call = CallBuilder() \
3132
.from_(self.setting["from"]) \
@@ -49,7 +50,7 @@ def test_call(self, _make_id):
4950
}
5051
}
5152

52-
m.post(f"{BASE_DOMAIN_URL_V3_FOR_TEST}/api/v3/", json=response_json)
53+
m.post(self.matcher, json=response_json)
5354
result = self.icon_service.call(test_call)
5455
actual_request = json.loads(m._adapter.last_request.text)
5556
self.assertEqual(expected_request, actual_request)
@@ -76,7 +77,7 @@ def test_call_without_params(self, _make_id):
7677
"from": self.setting["from"]
7778
}
7879
}
79-
m.post(f"{BASE_DOMAIN_URL_V3_FOR_TEST}/api/v3/", json=response_json)
80+
m.post(self.matcher, json=response_json)
8081
result = self.icon_service.call(test_call)
8182
actual_request = json.loads(m._adapter.last_request.text)
8283
self.assertEqual(expected_request, actual_request)
@@ -101,7 +102,7 @@ def test_call_without_from(self, _make_id):
101102
},
102103
}
103104
}
104-
m.post(f"{BASE_DOMAIN_URL_V3_FOR_TEST}/api/v3/", json=response_json)
105+
m.post(self.matcher, json=response_json)
105106
result = self.icon_service.call(test_call)
106107
actual_request = json.loads(m._adapter.last_request.text)
107108
self.assertEqual(expected_request, actual_request)

tests/api_debug/test_estimate_step.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import json
2+
import re
3+
from unittest.mock import patch
4+
25
import requests_mock
36

4-
from unittest.mock import patch
5-
from tests.example_config import BASE_DOMAIN_URL_V3_FOR_TEST
67
from iconsdk.builder.transaction_builder import DeployTransactionBuilder, CallTransactionBuilder
78
from iconsdk.builder.transaction_builder import TransactionBuilder, MessageTransactionBuilder
89
from tests.api_send.test_send_super import TestSendSuper
10+
from tests.example_config import BASE_DOMAIN_URL_V3_FOR_TEST
911

1012

1113
@patch('iconsdk.providers.http_provider.HTTPProvider._make_id', return_value=1234)
1214
class TestEstimateStep(TestSendSuper):
15+
matcher = re.compile(re.escape(f"{BASE_DOMAIN_URL_V3_FOR_TEST}/api/debug/v3/") + "?")
1316

1417
def test_estimate_step_with_send_icx_transaction(self, _make_id):
1518
icx_transaction = TransactionBuilder() \
@@ -46,7 +49,7 @@ def test_estimate_step_with_send_icx_transaction(self, _make_id):
4649
'id': 1234
4750
}
4851

49-
m.post(f"{BASE_DOMAIN_URL_V3_FOR_TEST}/api/debug/v3/", json=response_json)
52+
m.post(self.matcher, json=response_json)
5053
result = self.icon_service.estimate_step(icx_transaction)
5154
actual_request = json.loads(m._adapter.last_request.text)
5255

@@ -88,7 +91,7 @@ def test_estimate_step_with_message_transaction(self, _make_id):
8891
'id': 1234
8992
}
9093

91-
m.post(f"{BASE_DOMAIN_URL_V3_FOR_TEST}/api/debug/v3/", json=response_json)
94+
m.post(self.matcher, json=response_json)
9295
result = self.icon_service.estimate_step(message_transaction)
9396
actual_request = json.loads(m._adapter.last_request.text)
9497

@@ -138,7 +141,7 @@ def test_estimate_step_with_deploy_transaction(self, _make_id):
138141
'id': 1234
139142
}
140143

141-
m.post(f"{BASE_DOMAIN_URL_V3_FOR_TEST}/api/debug/v3/", json=response_json)
144+
m.post(self.matcher, json=response_json)
142145
result = self.icon_service.estimate_step(deploy_transaction)
143146
actual_request = json.loads(m._adapter.last_request.text)
144147

@@ -186,7 +189,7 @@ def test_estimate_step_with_call_transaction(self, _make_id):
186189
'result': hex(expected_step),
187190
'id': 1234
188191
}
189-
m.post(f"{BASE_DOMAIN_URL_V3_FOR_TEST}/api/debug/v3/", json=response_json)
192+
m.post(self.matcher, json=response_json)
190193
result = self.icon_service.estimate_step(call_transaction)
191194
actual_request = json.loads(m._adapter.last_request.text)
192195

tests/api_full_response/test_full_response_base.py

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15+
1516
from tests.api_send.test_send_super import TestSendSuper
1617

1718

tests/api_full_response/test_get_balance.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15-
import requests_mock
16-
import json
1715

16+
import json
1817
from unittest import main
1918
from unittest.mock import patch
20-
from tests.example_config import BASE_DOMAIN_URL_V3_FOR_TEST
21-
from tests.api_full_response.test_full_response_base import TestFullResponseBase
22-
from tests.api_full_response.example_response import result_success_v3
19+
20+
import requests_mock
21+
2322
from iconsdk.exception import AddressException
23+
from tests.api_full_response.example_response import result_success_v3
24+
from tests.api_full_response.test_full_response_base import TestFullResponseBase
2425

2526

2627
@patch('iconsdk.providers.http_provider.HTTPProvider._make_id', return_value=1234)
@@ -44,7 +45,7 @@ def test_get_balance_full_response(self, _make_id):
4445
'id': 1234
4546
}
4647

47-
m.post(f"{BASE_DOMAIN_URL_V3_FOR_TEST}/api/v3/", json=response_json)
48+
m.post(self.matcher, json=response_json)
4849
result_dict = self.icon_service.get_balance(self.setting['from'], full_response=True)
4950
actual_request = json.loads(m._adapter.last_request.text)
5051
result_keys = result_dict.keys()

tests/api_full_response/test_get_block_by_hash.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414
# limitations under the License.
1515

1616
import json
17-
import requests_mock
18-
19-
from unittest.mock import patch
20-
from tests.example_config import BASE_DOMAIN_URL_V3_FOR_TEST
2117
from unittest import main
18+
from unittest.mock import patch
19+
20+
import requests_mock
2221

2322
from iconsdk.utils.validation import is_block
2423
from tests.api_full_response.example_response import result_error_v3, result_success_v3
@@ -46,7 +45,7 @@ def test_get_block_by_hash_full_response(self, _make_id):
4645
'id': 1234
4746
}
4847

49-
m.post(f"{BASE_DOMAIN_URL_V3_FOR_TEST}/api/v3/", json=response_json)
48+
m.post(self.matcher, json=response_json)
5049
result_dict = self.icon_service.get_block(self.block_hash, full_response=True)
5150
actual_request = json.loads(m._adapter.last_request.text)
5251
result_keys = result_dict.keys()
@@ -70,7 +69,7 @@ def test_get_block_by_wrong_hash(self, _make_id):
7069
'id': 1234
7170
}
7271

73-
m.post(f"{BASE_DOMAIN_URL_V3_FOR_TEST}/api/v3/", json=response_json, status_code=400)
72+
m.post(self.matcher, json=response_json, status_code=400)
7473
result_dict = self.icon_service.get_block(invalid_block_hash, full_response=True)
7574
self.assertEqual(result_dict.keys(), result_error_v3.keys())
7675

tests/api_full_response/test_get_block_by_height.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414
# limitations under the License.
1515

1616
import json
17-
import requests_mock
18-
19-
from unittest.mock import patch
20-
from tests.example_config import BASE_DOMAIN_URL_V3_FOR_TEST
2117
from unittest import main
18+
from unittest.mock import patch
19+
20+
import requests_mock
2221

2322
from iconsdk.utils.validation import is_block
2423
from tests.api_full_response.example_response import result_error_v3, result_success_v3
@@ -46,7 +45,7 @@ def test_get_block_by_height_full_response(self, _make_id):
4645
'id': 1234
4746
}
4847

49-
m.post(f"{BASE_DOMAIN_URL_V3_FOR_TEST}/api/v3/", json=response_json)
48+
m.post(self.matcher, json=response_json)
5049
result_dict = self.icon_service.get_block(self.block_height, full_response=True)
5150
actual_request = json.loads(m._adapter.last_request.text)
5251
result_keys = result_dict.keys()
@@ -70,7 +69,7 @@ def test_get_block_by_wrong_height(self, _make_id):
7069
"id": 1234
7170
}
7271

73-
m.post(f"{BASE_DOMAIN_URL_V3_FOR_TEST}/api/v3/", json=response_json, status_code=400)
72+
m.post(self.matcher, json=response_json, status_code=400)
7473
result_dict = self.icon_service.get_block(invalid_block_height, full_response=True)
7574
self.assertEqual(result_dict.keys(), result_error_v3.keys())
7675

tests/api_full_response/test_get_last_block.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414
# limitations under the License.
1515

1616
import json
17-
import requests_mock
18-
19-
from unittest.mock import patch
20-
from tests.example_config import BASE_DOMAIN_URL_V3_FOR_TEST
2117
from unittest import main
18+
from unittest.mock import patch
19+
20+
import requests_mock
2221

2322
from iconsdk.utils.validation import is_block
2423
from tests.api_full_response.example_response import result_success_v3
@@ -43,7 +42,7 @@ def test_get_last_block_full_response(self, _make_id):
4342
'id': 1234
4443
}
4544

46-
m.post(f"{BASE_DOMAIN_URL_V3_FOR_TEST}/api/v3/", json=response_json)
45+
m.post(self.matcher, json=response_json)
4746
result_dict = self.icon_service.get_block("latest", full_response=True)
4847
actual_request = json.loads(m._adapter.last_request.text)
4948
result_keys = result_dict.keys()

tests/api_full_response/test_get_score_api.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
import requests_mock
1716
import json
18-
19-
from unittest.mock import patch
2017
from unittest import main
18+
from unittest.mock import patch
19+
20+
import requests_mock
2121

2222
from iconsdk.utils.validation import is_score_apis
23-
from tests.example_config import BASE_DOMAIN_URL_V3_FOR_TEST
2423
from tests.api_full_response.example_response import result_success_v3, result_error_v3
2524
from tests.api_full_response.test_full_response_base import TestFullResponseBase
2625

@@ -40,7 +39,7 @@ def test_get_score_api_full_response(self, _make_id):
4039
}
4140
}
4241

43-
m.post(f"{BASE_DOMAIN_URL_V3_FOR_TEST}/api/v3/", json=response_governance_json)
42+
m.post(self.matcher, json=response_governance_json)
4443
result_dict = self.icon_service.get_score_api(governance_address, full_response=True)
4544
actual_request = json.loads(m._adapter.last_request.text)
4645
result_content = result_dict['result']
@@ -61,7 +60,7 @@ def test_get_score_api_by_wrong_address(self, _make_id):
6160
},
6261
"id": 1234
6362
}
64-
m.post(f"{BASE_DOMAIN_URL_V3_FOR_TEST}/api/v3/", json=response_json, status_code=400)
63+
m.post(self.matcher, json=response_json, status_code=400)
6564
result_dict = self.icon_service.get_score_api(wrong_address, full_response=True)
6665
self.assertEqual(result_dict.keys(), result_error_v3.keys())
6766

tests/api_full_response/test_get_total_supply.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
import requests_mock
1716
import json
18-
1917
from unittest import main
2018
from unittest.mock import patch
19+
20+
import requests_mock
21+
2122
from tests.api_full_response.example_response import result_success_v3
2223
from tests.api_full_response.test_full_response_base import TestFullResponseBase
23-
from tests.example_config import BASE_DOMAIN_URL_V3_FOR_TEST
2424

2525

2626
@patch('iconsdk.providers.http_provider.HTTPProvider._make_id', return_value=1234)
@@ -40,7 +40,7 @@ def test_get_total_supply(self, _make_id):
4040
'result': hex(supply),
4141
'id': 1234
4242
}
43-
m.post(f"{BASE_DOMAIN_URL_V3_FOR_TEST}/api/v3/", json=response_json)
43+
m.post(self.matcher, json=response_json)
4444
result_dict = self.icon_service.get_total_supply(full_response=True)
4545
actual_request = json.loads(m._adapter.last_request.text)
4646
result_content = result_dict['result']

tests/api_full_response/test_get_transaction_by_hash.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,15 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15-
import requests_mock
1615
import json
17-
1816
from unittest import main
1917
from unittest.mock import patch
2018

19+
import requests_mock
20+
2121
from iconsdk.utils.validation import is_transaction
2222
from tests.api_full_response.example_response import result_success_v3, result_error_v3
2323
from tests.api_full_response.test_full_response_base import TestFullResponseBase
24-
from tests.example_config import BASE_DOMAIN_URL_V3_FOR_TEST
2524

2625

2726
@patch('iconsdk.providers.http_provider.HTTPProvider._make_id', return_value=1234)
@@ -43,7 +42,7 @@ def test_get_transaction_by_hash(self, _make_id):
4342
"id": 1234
4443
}
4544

46-
m.post(f"{BASE_DOMAIN_URL_V3_FOR_TEST}/api/v3/", json=response_json)
45+
m.post(self.matcher, json=response_json)
4746
result_dict = self.icon_service.get_transaction(self.transaction_hash, full_response=True)
4847
actual_request = json.loads(m._adapter.last_request.text)
4948
result_content = result_dict['result']
@@ -64,7 +63,7 @@ def test_get_transaction_wrong_hash(self, _make_id):
6463
"id": 1234
6564
}
6665

67-
m.post(f"{BASE_DOMAIN_URL_V3_FOR_TEST}/api/v3/", json=response_json, status_code=400)
66+
m.post(self.matcher, json=response_json, status_code=400)
6867
result_dict = self.icon_service.get_block(wrong_tx_hash, full_response=True)
6968
self.assertEqual(result_dict.keys(), result_error_v3.keys())
7069

0 commit comments

Comments
 (0)