Skip to content

Commit 676b1e0

Browse files
committed
Fix tests
1 parent 502f29c commit 676b1e0

3 files changed

Lines changed: 29 additions & 4 deletions

File tree

pyCryptoPayAPI/api.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,13 @@ def get_currencies(self):
374374
:return: Returns array of currencies.
375375
"""
376376
method = "getCurrencies"
377-
return self.__request(method).get("result")
377+
result = self.__request(method).get("result")
378+
if not result:
379+
return []
380+
elif self.result_as_class:
381+
return [Currency(item) for item in result]
382+
else:
383+
return result
378384

379385
def create_check(
380386
self, asset, amount, pin_to_user_id = None, pin_to_username = None

pyCryptoPayAPI/classes.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,16 @@ def __init__(self, data):
137137
self.start_at = None # The date on which the statistics calculation was started in ISO 8601 format.
138138
self.end_at = None # The date on which the statistics calculation was ended in ISO 8601 format.
139139
super().__init__(data)
140+
141+
142+
class Currency(CrypoPayBase):
143+
"""Class representing a single currency (not officially declared in API)."""
144+
def __init__(self, data):
145+
self.is_blockchain = None # True, if the currency is a blockchain asset.
146+
self.is_stablecoin = None # True, if the currency is a stablecoin.
147+
self.is_fiat = None # True, if the currency is a fiat currency.
148+
self.name = None # Name of the currency.
149+
self.code = None # Code of the currency.
150+
self.url = None # URL of the currency's website.
151+
self.decimals = None # Number of decimals for the currency.
152+
super().__init__(data)

pyCryptoPayAPI/tests.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def run_and_print(f):
2424
raise e
2525
return None
2626

27-
def test_api_functions(result_as_class):
27+
def run_api_functions(result_as_class):
2828
client = pyCryptoPayAPI(api_token=test_api_token, print_errors=True, result_as_class=result_as_class)
2929
run_and_print(lambda: client.get_me())
3030
run_and_print(lambda: client.get_balance())
@@ -62,5 +62,11 @@ def test_api_functions(result_as_class):
6262
count=10,
6363
))
6464

65-
test_api_functions(False)
66-
test_api_functions(True)
65+
def test_api_functions_raw():
66+
run_api_functions(False)
67+
68+
def test_api_functions_class():
69+
run_api_functions(True)
70+
71+
test_api_functions_raw()
72+
test_api_functions_class()

0 commit comments

Comments
 (0)