Skip to content

Commit 3316463

Browse files
committed
Updated test cases, Updated wallet model, Fixed payouts and refunds
1 parent 30957fb commit 3316463

File tree

5 files changed

+24
-21
lines changed

5 files changed

+24
-21
lines changed

src/bitpay/models/payout/payout.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ class Payout:
4646

4747
def __init__(self, amount=None, currency=None, ledger_currency=None, **kwargs):
4848
self.set_amount(amount)
49-
self.set_currency(currency)
49+
if currency:
50+
self.set_currency(currency)
5051
if ledger_currency:
5152
self.set_ledger_currency(ledger_currency)
5253

src/bitpay/models/payout/payout_batch.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ class PayoutBatch:
4747
def __init__(
4848
self, currency=None, effective_date=None, ledger_currency=None, **kwargs
4949
):
50-
self.set_currency(currency)
5150
self.set_effective_date(effective_date)
51+
if currency:
52+
self.set_currency(currency)
5253
if ledger_currency:
5354
self.set_ledger_currency(ledger_currency)
5455

src/bitpay/models/wallet/currencies.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __init__(self, **kwargs):
2323
for key, value in kwargs.items():
2424
try:
2525
if key in ["qr"]:
26-
klass = globals()[key[0].upper() + key[1:]]
26+
klass = CurrencyQr if key == "qr" else globals()[key[0].upper() + key[1:]]
2727
value = klass(**value)
2828
getattr(
2929
self, "set_%s" % key_utils.change_camel_case_to_snake_case(key)

src/bitpay/utils/rest_cli.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ def post(self, uri, form_data, signature_required=True):
4949
"""
5050
full_url = self.__baseurl + uri
5151
form_data = json.dumps(form_data)
52-
5352
if signature_required:
5453
self.__headers["x-signature"] = sign(full_url + form_data, self.__eckey)
5554
self.__headers["x-identity"] = get_compressed_public_key_from_pem(self.__eckey)
@@ -114,7 +113,7 @@ def update(self, uri, form_data):
114113
return json_response
115114

116115
def response_to_json_string(self, response):
117-
if not response:
116+
if not response.json():
118117
raise BitPayException("Error: HTTP response is null")
119118

120119
response_obj = response.json()

tests/test_bitpay.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def test_should_create_get_cancel_refund_request_new(self):
140140
)
141141
first_invoice = invoices[0]
142142
create_refund = self.client.create_refund(
143-
first_invoice.get_id(), 1.0, "BTC", True, False, False
143+
first_invoice.get_id(), first_invoice.get_price(), first_invoice.get_currency(), True, False, False
144144
)
145145
retrieved_refunds = self.client.get_refunds(first_invoice.get_id())
146146
last_refund = retrieved_refunds[-1]
@@ -150,15 +150,17 @@ def test_should_create_get_cancel_refund_request_new(self):
150150
last_refund.get_id()
151151
)
152152
cancel_refund = self.client.cancel_refund(last_refund.get_id())
153-
supported_wallets = self.client.get_supported_wallets()
154153

155154
self.assertIsNotNone(invoices)
156155
self.assertIsNotNone(create_refund.get_id())
157156
self.assertIsNotNone(retrieved_refunds)
158157
self.assertEqual("created", update_refund.get_status())
159158
self.assertEqual(last_refund.get_id(), retrieved_refund.get_id())
160159
self.assertTrue(notification_status)
161-
self.assertEqual("cancelled", cancel_refund.get_status())
160+
self.assertEqual("canceled", cancel_refund.get_status())
161+
162+
def test_should_get_supported_wallets(self):
163+
supported_wallets = self.client.get_supported_wallets()
162164
self.assertIsNotNone(supported_wallets)
163165

164166
def test_should_create_bill_usd(self):
@@ -417,7 +419,7 @@ def test_should_get_payout_recipient_id(self):
417419
recipients_list = []
418420

419421
payout_recipient = PayoutRecipient()
420-
payout_recipient.set_email("sandbox@bitpay.com")
422+
payout_recipient.set_email("nsoni@mailinator.com")
421423
payout_recipient.set_label("recipient1")
422424
payout_recipient.set_notification_url("https://hookb.in/QJOPBdMgRkukpp2WO60o")
423425
recipients_list.append(payout_recipient)
@@ -489,7 +491,7 @@ def test_should_request_payout_recipient_notification(self):
489491
def test_should_submit_payout(self):
490492
recipients = self.client.get_payout_recipients(None, 1)
491493
currency = Currency.USD
492-
ledger_currency = Currency.ETH
494+
ledger_currency = Currency.USD
493495

494496
payout = Payout(5.0, currency, ledger_currency)
495497
payout.set_recipient_id(recipients[0].get_id())
@@ -511,7 +513,7 @@ def test_should_get_payouts_by_status(self):
511513
def test_should_submit_get_and_delete_payout(self):
512514
recipients = self.client.get_payout_recipients(None, 1)
513515
currency = Currency.USD
514-
ledger_currency = Currency.ETH
516+
ledger_currency = Currency.USD
515517

516518
payout = Payout(5.0, currency, ledger_currency)
517519
payout.set_recipient_id(recipients[0].get_id())
@@ -529,7 +531,7 @@ def test_should_submit_get_and_delete_payout(self):
529531
def test_should_request_payout_notification(self):
530532
recipients = self.client.get_payout_recipients(None, 1)
531533
currency = Currency.USD
532-
ledger_currency = Currency.ETH
534+
ledger_currency = Currency.USD
533535

534536
payout = Payout(5.0, currency, ledger_currency)
535537
payout.set_recipient_id(recipients[0].get_id())
@@ -547,16 +549,16 @@ def test_should_request_payout_notification(self):
547549
self.assertTrue(cancel_payout)
548550

549551
def test_should_submit_payout_batch(self):
550-
recipients = self.client.get_payout_recipients(None, 2)
552+
recipients = self.client.get_payout_recipients("active", 2)
551553
currency = Currency.USD
552-
ledger_currency = Currency.ETH
554+
ledger_currency = Currency.USD
553555
effective_date = (date.today() + timedelta(days=3)).strftime("%Y-%m-%d")
554556
instructions = [
555557
PayoutInstruction(
556558
5.0, RecipientReferenceMethod.EMAIL, recipients[0].get_email()
557559
),
558560
PayoutInstruction(
559-
6.0, RecipientReferenceMethod.RECIPIENT_ID, recipients[1].get_email()
561+
6.0, RecipientReferenceMethod.RECIPIENT_ID, recipients[1].get_id()
560562
),
561563
]
562564
batch = PayoutBatch(currency, effective_date, ledger_currency)
@@ -569,17 +571,17 @@ def test_should_submit_payout_batch(self):
569571
self.assertTrue(cancel_batch)
570572

571573
def test_should_submit_get_and_delete_payout_batch(self):
572-
recipients = self.client.get_payout_recipients(None, 2)
574+
recipients = self.client.get_payout_recipients("active", 2)
573575
currency = Currency.USD
574-
ledger_currency = Currency.ETH
576+
ledger_currency = Currency.USD
575577
effective_date = (date.today() + timedelta(days=3)).strftime("%Y-%m-%d")
576578

577579
instructions = [
578580
PayoutInstruction(
579581
5.0, RecipientReferenceMethod.EMAIL, recipients[0].get_email()
580582
),
581583
PayoutInstruction(
582-
6.0, RecipientReferenceMethod.RECIPIENT_ID, recipients[1].get_email()
584+
6.0, RecipientReferenceMethod.RECIPIENT_ID, recipients[1].get_id()
583585
),
584586
]
585587
batch = PayoutBatch(currency, effective_date, ledger_currency)
@@ -597,17 +599,17 @@ def test_should_submit_get_and_delete_payout_batch(self):
597599
self.assertEqual(PayoutStatus.New, retrieve_batch.get_status())
598600

599601
def test_should_request_payout_batch_notification(self):
600-
recipients = self.client.get_payout_recipients(None, 2)
602+
recipients = self.client.get_payout_recipients("active", 2)
601603
currency = Currency.USD
602-
ledger_currency = Currency.ETH
604+
ledger_currency = Currency.USD
603605
effective_date = (date.today() + timedelta(days=3)).strftime("%Y-%m-%d")
604606

605607
instructions = [
606608
PayoutInstruction(
607609
5.0, RecipientReferenceMethod.EMAIL, recipients[0].get_email()
608610
),
609611
PayoutInstruction(
610-
6.0, RecipientReferenceMethod.RECIPIENT_ID, recipients[1].get_email()
612+
6.0, RecipientReferenceMethod.RECIPIENT_ID, recipients[1].get_id()
611613
),
612614
]
613615
batch = PayoutBatch(currency, effective_date, ledger_currency)

0 commit comments

Comments
 (0)