@@ -1218,24 +1218,41 @@ def test_delete_organization_with_active_projects(
12181218 assert organization_service .delete_organization .calls == []
12191219 assert db_request .route_path .calls == []
12201220
1221+ @pytest .mark .parametrize (
1222+ ("subscription_status" , "should_cancel" ),
1223+ [
1224+ ("active" , True ),
1225+ ("past_due" , True ),
1226+ ("canceled" , False ),
1227+ ("incomplete_expired" , False ),
1228+ ],
1229+ )
12211230 def test_delete_organization_with_subscriptions (
12221231 self ,
12231232 db_request ,
12241233 pyramid_user ,
1234+ billing_service ,
12251235 organization_service ,
12261236 user_service ,
12271237 monkeypatch ,
1238+ subscription_status ,
1239+ should_cancel ,
12281240 ):
12291241 organization = OrganizationFactory .create ()
12301242 stripe_customer = StripeCustomerFactory .create ()
12311243 OrganizationStripeCustomerFactory .create (
12321244 organization = organization , customer = stripe_customer
12331245 )
1234- subscription = StripeSubscriptionFactory .create (customer = stripe_customer )
1246+ subscription = StripeSubscriptionFactory .create (
1247+ customer = stripe_customer , status = subscription_status
1248+ )
12351249 OrganizationStripeSubscriptionFactory .create (
12361250 organization = organization , subscription = subscription
12371251 )
12381252
1253+ cancel_subscription = pretend .call_recorder (lambda * a , ** kw : None )
1254+ monkeypatch .setattr (billing_service , "cancel_subscription" , cancel_subscription )
1255+
12391256 db_request .POST = {"confirm_organization_name" : organization .name }
12401257 db_request .route_path = pretend .call_recorder (
12411258 lambda * a , ** kw : "/manage/organizations/"
@@ -1265,6 +1282,9 @@ def test_delete_organization_with_subscriptions(
12651282
12661283 assert isinstance (result , HTTPSeeOther )
12671284 assert result .headers ["Location" ] == "/manage/organizations/"
1285+ assert cancel_subscription .calls == (
1286+ [pretend .call (subscription .subscription_id )] if should_cancel else []
1287+ )
12681288 assert organization_service .delete_organization .calls == [
12691289 pretend .call (organization .id )
12701290 ]
0 commit comments