@@ -50,18 +50,85 @@ def test_add_interceptor(self):
5050 consumer_key = 'uLXKmWNmIkzIGKfA2injnNQqpZaxaBSKxa3ixEVu2f283c95!33b9b2bd960147e387fa6f3f238f07170000000000000000'
5151
5252 signing_layer1 = get_signing_layer (self , requests )
53-
5453 add_signing_layer (self , requests , key_file , key_password , consumer_key )
55-
5654 signing_layer2 = get_signing_layer (self , requests )
57-
5855 self .assertNotEqual (signing_layer1 , signing_layer2 )
59-
60-
6156 else :
6257 print ("Please add a ./test_key_container.p12 file to enable key tests" )
6358
6459
6560
61+ """ these will fail because the test keys can't access the service, you'll need to insert a valid key file, password, and consumer key """
62+ def test_without_interceptor (self ):
63+ if os .path .exists ('./test_key_container.p12' ):
64+ key_file = './test_key_container.p12'
65+ key_password = "Password1"
66+ consumer_key = 'uLXKmWNmIkzIGKfA2injnNQqpZaxaBSKxa3ixEVu2f283c95!33b9b2bd960147e387fa6f3f238f07170000000000000000'
67+ signing_key = authenticationutils .load_signing_key (key_file , key_password )
68+
69+ baseUrl = 'https://sandbox.api.mastercard.com'
70+
71+ queryMap = {
72+ "Format" : "JSON" , # change this to toggle between and XML or JSON response
73+ "fxDate" : "2016-09-30" ,
74+ "transCurr" : "ALL" ,
75+ "crdhldBillCurr" : "DZD" ,
76+ "bankFee" : "5" ,
77+ "transAmt" : "23"
78+ }
79+
80+ uri = baseUrl + "/settlement/currencyrate/conversion-rate?" + urlencode (queryMap )
81+ header = OAuth ().get_authorization_header (uri , 'GET' , None , consumer_key , signing_key )
82+ headers = {'Authorization' : header , 'Content-Type' : 'application/json' }
83+
84+ r = requests .get (uri , headers = headers )
85+ print (r .text )
86+
87+ """ these will fail because the test keys can't access the service, you'll need to insert a valid key file, password, and consumer key """
88+ def test_with_interceptor (self ):
89+ if os .path .exists ('./test_key_container.p12' ):
90+ key_file = './test_key_container.p12'
91+ key_password = "Password1"
92+ consumer_key = 'uLXKmWNmIkzIGKfA2injnNQqpZaxaBSKxa3ixEVu2f283c95!33b9b2bd960147e387fa6f3f238f07170000000000000000'
93+ signing_key = authenticationutils .load_signing_key (key_file , key_password )
94+
95+ baseUrl = 'https://sandbox.api.mastercard.com'
96+
97+ test_cli = APIClientForTest ()
98+ add_signing_layer (self , test_cli , key_file , key_password , consumer_key )
99+
100+ queryMap = {
101+ "Format" : "JSON" , # change this to toggle between and XML or JSON response
102+ "fxDate" : "2016-09-30" ,
103+ "transCurr" : "ALL" ,
104+ "crdhldBillCurr" : "DZD" ,
105+ "bankFee" : "5" ,
106+ "transAmt" : "23"
107+ }
108+
109+ uri = baseUrl + "/settlement/currencyrate/conversion-rate"
110+
111+ r = test_cli .request ('GET' , uri , query_params = queryMap )
112+ print (r .text )
113+
114+
66115if __name__ == '__main__' :
67116 unittest .main ()
117+
118+
119+
120+ class APIClientForTest ():
121+
122+
123+ def request (self , method , uri , query_params = None , headers = None , post_params = None , body = None , _preload_content = True , _request_timeout = None ):
124+ res = None
125+
126+ if query_params :
127+ uri += '?' + urlencode (query_params )
128+
129+ if method == 'GET' :
130+ res = requests .get (uri , headers = headers )
131+ if method == 'POST' :
132+ res = requests .post (uri , headers = headers , body = body )
133+
134+ return res
0 commit comments