@@ -234,17 +234,53 @@ def test_provider_handles_captured_payment(self, mocked_post):
234
234
self .assertEqual (self .payment .status , PaymentStatus .CONFIRMED )
235
235
236
236
@patch ("requests.post" )
237
- def test_provider_refunds_payment (self , mocked_post ):
237
+ def test_provider_refunds_payment_fully (self , mocked_post ):
238
238
data = MagicMock ()
239
- data .return_value = {
240
- "token_type" : "test_token_type" ,
241
- "access_token" : "test_access_token" ,
242
- }
239
+ data .side_effect = [
240
+ {
241
+ "token_type" : "test_token_type" ,
242
+ "access_token" : "test_access_token" ,
243
+ },
244
+ {"amount" : {"total" : "220.00" , "currency" : "USD" }},
245
+ ]
243
246
post = MagicMock ()
244
247
post .json = data
245
248
post .status_code = 200
246
249
mocked_post .return_value = post
247
250
self .provider .refund (self .payment )
251
+ mocked_post .assert_called_with (
252
+ "http://refund.com" ,
253
+ headers = {
254
+ "Content-Type" : "application/json" ,
255
+ "Authorization" : "test_token_type test_access_token" ,
256
+ },
257
+ data = "{}" ,
258
+ )
259
+ self .assertEqual (self .payment .status , PaymentStatus .REFUNDED )
260
+
261
+ @patch ("requests.post" )
262
+ def test_provider_refunds_payment_partially (self , mocked_post ):
263
+ data = MagicMock ()
264
+ data .side_effect = [
265
+ {
266
+ "token_type" : "test_token_type" ,
267
+ "access_token" : "test_access_token" ,
268
+ },
269
+ {"amount" : {"total" : "1.00" , "currency" : "USD" }},
270
+ ]
271
+ post = MagicMock ()
272
+ post .json = data
273
+ post .status_code = 200
274
+ mocked_post .return_value = post
275
+ self .provider .refund (self .payment , amount = Decimal (1 ))
276
+ mocked_post .assert_called_with (
277
+ "http://refund.com" ,
278
+ headers = {
279
+ "Content-Type" : "application/json" ,
280
+ "Authorization" : "test_token_type test_access_token" ,
281
+ },
282
+ data = '{"amount": {"currency": "USD", "total": "1.00"}}' ,
283
+ )
248
284
self .assertEqual (self .payment .status , PaymentStatus .REFUNDED )
249
285
250
286
@patch ("requests.post" )
0 commit comments