1- import Adyen
1+ from unittest . mock import ANY
22import unittest
3+
34from BaseTest import BaseTest
5+ import Adyen
6+
7+
8+ REQUEST_KWARGS = {
9+ 'merchantAccount' : 'YourMerchantAccount' ,
10+ 'amount' : '1000'
11+ }
412
513
614class TestBinLookup (unittest .TestCase ):
@@ -14,11 +22,7 @@ class TestBinLookup(unittest.TestCase):
1422 client .app_name = "appname"
1523
1624 def test_get_cost_estimate_success (self ):
17- request = {
18- 'merchantAccount' : 'YourMerchantAccount' ,
19- 'amount' : '1000'
20- }
21-
25+ self .ady .client .http_client .request .reset_mock ()
2226 expected = {
2327 'cardBin' : {
2428 'bin' : '458012' ,
@@ -39,29 +43,40 @@ def test_get_cost_estimate_success(self):
3943
4044 self .ady .client = self .test .create_client_from_file (
4145 status = 200 ,
42- request = request ,
46+ request = REQUEST_KWARGS ,
4347 filename = 'test/mocks/binlookup/getcostestimate-success.json'
4448 )
4549
46- result = self .ady .binlookup .get_cost_estimate (request )
50+ result = self .ady .binlookup .get_cost_estimate (REQUEST_KWARGS )
4751 self .assertEqual (expected , result .message )
52+ self .ady .client .http_client .request .assert_called_once_with (
53+ 'https://pal-test.adyen.com/pal/servlet/'
54+ 'BinLookup/v50/getCostEstimate' ,
55+ headers = {},
56+ json = {
57+ 'merchantAccount' : 'YourMerchantAccount' ,
58+ 'amount' : '1000' , 'applicationInfo' : {
59+ 'adyenLibrary' : {
60+ 'name' : 'adyen-python-api-library' ,
61+ 'version' : ANY
62+ }
63+ }
64+ },
65+ password = 'YourWSPassword' ,
66+ username = 'YourWSUser'
67+ )
4868
4969 def test_get_cost_estimate_error_mocked (self ):
50- request = {
51- 'merchantAccount' : 'YourMerchantAccount' ,
52- 'amount' : '1000'
53- }
54-
5570 self .ady .client = self .test .create_client_from_file (
5671 status = 200 ,
57- request = request ,
72+ request = REQUEST_KWARGS ,
5873 filename = (
5974 "test/mocks/binlookup/"
6075 "getcostestimate-error-invalid-data-422.json"
6176 )
6277 )
6378
64- result = self .ady .binlookup .get_cost_estimate (request )
79+ result = self .ady .binlookup .get_cost_estimate (REQUEST_KWARGS )
6580 self .assertEqual (422 , result .message ['status' ])
6681 self .assertEqual ("101" , result .message ['errorCode' ])
6782 self .assertEqual ("Invalid card number" , result .message ['message' ])
0 commit comments