129129 }
130130]
131131
132+
132133class MockSubscriptionPlan (object ):
133134 def __init__ (self , params ):
134135 self .id = params ["new_plan" ]
135- self .interval = 'year'
136+ self .interval = "year"
137+
136138
137139class MockSubscription (object ):
138140 def __init__ (self , subscription_params ):
139141 self .schedule = subscription_params ["schedule_id" ]
140142 self .current_period_start = subscription_params ["start_date" ]
141143 self .current_period_end = subscription_params ["end_date" ]
142- self .plan = MockSubscriptionPlan (subscription_params ["plan" ]) if subscription_params .get ("plan" ) is not None else None
144+ self .plan = (
145+ MockSubscriptionPlan (subscription_params ["plan" ])
146+ if subscription_params .get ("plan" ) is not None
147+ else None
148+ )
143149 self .items = {
144150 "data" : [
145151 {
146152 "quantity" : subscription_params ["quantity" ],
147153 "id" : subscription_params ["id" ],
148- "plan" : {"id" : subscription_params ["name" ], "interval" : subscription_params .get ("plan" , {}).get ("interval" , "month" )},
154+ "plan" : {
155+ "id" : subscription_params ["name" ],
156+ "interval" : subscription_params .get ("plan" , {}).get (
157+ "interval" , "month"
158+ ),
159+ },
149160 }
150161 ]
151162 }
@@ -163,6 +174,7 @@ def __init__(self, subscription_params):
163174 def __getitem__ (self , key ):
164175 return getattr (self , key )
165176
177+
166178class StripeServiceTests (TestCase ):
167179 def setUp (self ):
168180 self .user = OwnerFactory ()
@@ -317,7 +329,11 @@ def test_delete_subscription_without_schedule_modifies_subscription_to_delete_at
317329 @patch ("services.billing.stripe.Subscription.retrieve" )
318330 @patch ("services.billing.stripe.SubscriptionSchedule.release" )
319331 def test_delete_subscription_with_schedule_releases_schedule_and_cancels_subscription_at_end_of_billing_cycle_if_valid_plan (
320- self , schedule_release_mock , retrieve_subscription_mock , modify_mock , create_refund_mock
332+ self ,
333+ schedule_release_mock ,
334+ retrieve_subscription_mock ,
335+ modify_mock ,
336+ create_refund_mock ,
321337 ):
322338 plan = PlanName .CODECOV_PRO_YEARLY .value
323339 stripe_subscription_id = "sub_1K77Y5GlVGuVgOrkJrLjRnne"
@@ -361,7 +377,14 @@ def test_delete_subscription_with_schedule_releases_schedule_and_cancels_subscri
361377 @patch ("services.billing.stripe.Subscription.retrieve" )
362378 @patch ("services.billing.stripe.SubscriptionSchedule.release" )
363379 def test_delete_subscription_with_schedule_releases_schedule_and_cancels_subscription_with_grace_month_refund_if_valid_plan (
364- self , schedule_release_mock , retrieve_subscription_mock , cancel_sub_mock , list_invoice_mock , create_refund_mock , modify_customer_mock , modify_sub_mock
380+ self ,
381+ schedule_release_mock ,
382+ retrieve_subscription_mock ,
383+ cancel_sub_mock ,
384+ list_invoice_mock ,
385+ create_refund_mock ,
386+ modify_customer_mock ,
387+ modify_sub_mock ,
365388 ):
366389 with open ("./services/tests/samples/stripe_invoice.json" ) as f :
367390 stripe_invoice_response = json .load (f )
@@ -387,16 +410,20 @@ def test_delete_subscription_with_schedule_releases_schedule_and_cancels_subscri
387410 "new_quantity" : 7 ,
388411 "subscription_id" : "sub_123" ,
389412 "interval" : "month" ,
390- }
413+ },
391414 }
392415
393416 retrieve_subscription_mock .return_value = MockSubscription (subscription_params )
394417 self .stripe .delete_subscription (owner )
395418 schedule_release_mock .assert_called_once_with (stripe_schedule_id )
396419 cancel_sub_mock .assert_called_once_with (stripe_subscription_id )
397- list_invoice_mock .assert_called_once_with (subscription = stripe_subscription_id , status = "paid" )
420+ list_invoice_mock .assert_called_once_with (
421+ subscription = stripe_subscription_id , status = "paid"
422+ )
398423 self .assertEqual (create_refund_mock .call_count , 2 )
399- modify_customer_mock .assert_called_once_with (owner .stripe_customer_id , balance = 0 )
424+ modify_customer_mock .assert_called_once_with (
425+ owner .stripe_customer_id , balance = 0
426+ )
400427 modify_sub_mock .assert_not_called ()
401428
402429 owner .refresh_from_db ()
@@ -414,7 +441,14 @@ def test_delete_subscription_with_schedule_releases_schedule_and_cancels_subscri
414441 @patch ("services.billing.stripe.Subscription.retrieve" )
415442 @patch ("services.billing.stripe.SubscriptionSchedule.release" )
416443 def test_delete_subscription_with_schedule_releases_schedule_and_cancels_subscription_with_grace_year_refund_if_valid_plan (
417- self , schedule_release_mock , retrieve_subscription_mock , cancel_sub_mock , list_invoice_mock , create_refund_mock , modify_customer_mock , modify_sub_mock
444+ self ,
445+ schedule_release_mock ,
446+ retrieve_subscription_mock ,
447+ cancel_sub_mock ,
448+ list_invoice_mock ,
449+ create_refund_mock ,
450+ modify_customer_mock ,
451+ modify_sub_mock ,
418452 ):
419453 with open ("./services/tests/samples/stripe_invoice.json" ) as f :
420454 stripe_invoice_response = json .load (f )
@@ -440,16 +474,20 @@ def test_delete_subscription_with_schedule_releases_schedule_and_cancels_subscri
440474 "new_quantity" : 7 ,
441475 "subscription_id" : "sub_123" ,
442476 "interval" : "year" ,
443- }
477+ },
444478 }
445479
446480 retrieve_subscription_mock .return_value = MockSubscription (subscription_params )
447481 self .stripe .delete_subscription (owner )
448482 schedule_release_mock .assert_called_once_with (stripe_schedule_id )
449483 cancel_sub_mock .assert_called_once_with (stripe_subscription_id )
450- list_invoice_mock .assert_called_once_with (subscription = stripe_subscription_id , status = "paid" )
484+ list_invoice_mock .assert_called_once_with (
485+ subscription = stripe_subscription_id , status = "paid"
486+ )
451487 self .assertEqual (create_refund_mock .call_count , 2 )
452- modify_customer_mock .assert_called_once_with (owner .stripe_customer_id , balance = 0 )
488+ modify_customer_mock .assert_called_once_with (
489+ owner .stripe_customer_id , balance = 0
490+ )
453491 modify_sub_mock .assert_not_called ()
454492
455493 owner .refresh_from_db ()
0 commit comments