@@ -216,6 +216,23 @@ def test_reverse_valid(self, mock_post, mock_response):
216
216
self .assertEqual (payment .processor_fields [- 1 ].value , "00" )
217
217
self .assertEqual (payment .processor_fields [- 1 ].keyword , "b24" )
218
218
219
+ @patch ("requests.post" )
220
+ @RedirectResponseMock .mock_response_decorator ("invalidate_token_response_successful" )
221
+ def test_invalidate_token_succssful (self , mock_post , mock_response ):
222
+ mock_post .return_value = mock_response
223
+
224
+ instrument = Instrument (
225
+ token = Token (
226
+ token = "5caef08ecd1230088a12e8f7d9ce20e9134dc6fc049c8a4857c9ba6e942b16b2" , subtoken = "test_subtoken"
227
+ )
228
+ )
229
+ invalidate_token_request = {"locale" : "en_US" , "instrument" : instrument }
230
+ result = self .checkout .invalidateToken (invalidate_token_request )
231
+
232
+ self .assertEqual (result .status , "APPROVED" )
233
+ self .assertEqual (result .reason , "00" )
234
+ self .assertEqual (result .message , "The petition has been successfully approved" )
235
+
219
236
@patch ("requests.post" )
220
237
@RedirectResponseMock .mock_response_decorator ("redirect_response_fail_authentication" , 401 )
221
238
def test_request_fails_bad_request (self , mock_post , mock_response ):
@@ -283,3 +300,19 @@ def test_reverse_fails_when_transaction_not_found(self, mock_post, mock_response
283
300
self .assertEqual ("FAILED" , error_details ["status" ]["status" ])
284
301
self .assertEqual ("request_not_valid" , error_details ["status" ]["reason" ])
285
302
self .assertEqual ("No existe la transacción que busca" , error_details ["status" ]["message" ])
303
+
304
+ @patch ("requests.post" )
305
+ @RedirectResponseMock .mock_response_decorator ("invalidate_token_response_fails_token_not_valid" , 400 )
306
+ def test_invalidate_fails_when_token_is_not_valid (self , mock_post , mock_response ):
307
+ mock_post .return_value = mock_response
308
+
309
+ instrument = Instrument (token = Token (token = "not_valid_token" , subtoken = "test_subtoken" ))
310
+ invalidate_token_request = {"locale" : "en_US" , "instrument" : instrument }
311
+
312
+ with self .assertRaises (ClientErrorException ) as context :
313
+ self .checkout .invalidateToken (invalidate_token_request )
314
+
315
+ error_details = json .loads (str (context .exception ))["error_details" ]
316
+ self .assertEqual ("FAILED" , error_details ["status" ]["status" ])
317
+ self .assertEqual ("XN" , error_details ["status" ]["reason" ])
318
+ self .assertEqual ("The token used is invalid" , error_details ["status" ]["message" ])
0 commit comments