@@ -2253,10 +2253,13 @@ def test_upgrade_with_uncaught_exception(self, *mock_args: Any) -> None:
2253
2253
hamlet = self .example_user ("hamlet" )
2254
2254
self .login_user (hamlet )
2255
2255
self .add_card_to_customer_for_upgrade ()
2256
- with patch (
2257
- "corporate.lib.stripe.BillingSession.create_stripe_invoice_and_charge" ,
2258
- side_effect = Exception ,
2259
- ), self .assertLogs ("corporate.stripe" , "WARNING" ) as m :
2256
+ with (
2257
+ patch (
2258
+ "corporate.lib.stripe.BillingSession.create_stripe_invoice_and_charge" ,
2259
+ side_effect = Exception ,
2260
+ ),
2261
+ self .assertLogs ("corporate.stripe" , "WARNING" ) as m ,
2262
+ ):
2260
2263
response = self .upgrade (talk_to_stripe = False )
2261
2264
self .assertIn ("ERROR:corporate.stripe:Uncaught exception in billing" , m .output [0 ])
2262
2265
self .assertIn (m .records [0 ].stack_info , m .output [0 ])
@@ -2273,9 +2276,12 @@ def test_invoice_payment_succeeded_event_with_uncaught_exception(self, *mock_arg
2273
2276
self .login_user (hamlet )
2274
2277
self .add_card_to_customer_for_upgrade ()
2275
2278
2276
- with patch (
2277
- "corporate.lib.stripe.BillingSession.process_initial_upgrade" , side_effect = Exception
2278
- ), self .assertLogs ("corporate.stripe" , "WARNING" ):
2279
+ with (
2280
+ patch (
2281
+ "corporate.lib.stripe.BillingSession.process_initial_upgrade" , side_effect = Exception
2282
+ ),
2283
+ self .assertLogs ("corporate.stripe" , "WARNING" ),
2284
+ ):
2279
2285
response = self .upgrade ()
2280
2286
2281
2287
response_dict = self .assert_json_success (response )
@@ -2609,9 +2615,10 @@ def test_redirect_for_billing_page_downgrade_at_free_trial_end(self, *mocks: Moc
2609
2615
self .assert_in_response (substring , response )
2610
2616
2611
2617
# schedule downgrade
2612
- with time_machine .travel (self .now + timedelta (days = 3 ), tick = False ), self .assertLogs (
2613
- "corporate.stripe" , "INFO"
2614
- ) as m :
2618
+ with (
2619
+ time_machine .travel (self .now + timedelta (days = 3 ), tick = False ),
2620
+ self .assertLogs ("corporate.stripe" , "INFO" ) as m ,
2621
+ ):
2615
2622
response = self .client_billing_patch (
2616
2623
"/billing/plan" ,
2617
2624
{"status" : CustomerPlan .DOWNGRADE_AT_END_OF_FREE_TRIAL },
@@ -3927,9 +3934,10 @@ def test_reupgrade_by_billing_admin_after_downgrade(self) -> None:
3927
3934
expected_log = f"INFO:corporate.stripe:Change plan status: Customer.id: { stripe_customer_id } , CustomerPlan.id: { new_plan .id } , status: { CustomerPlan .DOWNGRADE_AT_END_OF_CYCLE } "
3928
3935
self .assertEqual (m .output [0 ], expected_log )
3929
3936
3930
- with self .assertRaises (BillingError ) as context , self .assertLogs (
3931
- "corporate.stripe" , "WARNING"
3932
- ) as m :
3937
+ with (
3938
+ self .assertRaises (BillingError ) as context ,
3939
+ self .assertLogs ("corporate.stripe" , "WARNING" ) as m ,
3940
+ ):
3933
3941
with time_machine .travel (self .now , tick = False ):
3934
3942
self .local_upgrade (
3935
3943
self .seat_count , True , CustomerPlan .BILLING_SCHEDULE_ANNUAL , True , False
@@ -7010,9 +7018,10 @@ def test_redirect_for_remote_realm_billing_page_downgrade_at_free_trial_end(
7010
7018
self .assert_in_response (substring , response )
7011
7019
7012
7020
# schedule downgrade
7013
- with time_machine .travel (self .now + timedelta (days = 3 ), tick = False ), self .assertLogs (
7014
- "corporate.stripe" , "INFO"
7015
- ) as m :
7021
+ with (
7022
+ time_machine .travel (self .now + timedelta (days = 3 ), tick = False ),
7023
+ self .assertLogs ("corporate.stripe" , "INFO" ) as m ,
7024
+ ):
7016
7025
response = self .client_billing_patch (
7017
7026
"/billing/plan" ,
7018
7027
{"status" : CustomerPlan .DOWNGRADE_AT_END_OF_FREE_TRIAL },
@@ -7400,8 +7409,9 @@ def test_upgrade_user_to_fixed_price_plan_pay_by_invoice(self, *mocks: Mock) ->
7400
7409
self .execute_remote_billing_authentication_flow (hamlet )
7401
7410
mock_invoice = MagicMock ()
7402
7411
mock_invoice .hosted_invoice_url = "payments_page_url"
7403
- with time_machine .travel (self .now , tick = False ), mock .patch (
7404
- "stripe.Invoice.retrieve" , return_value = mock_invoice
7412
+ with (
7413
+ time_machine .travel (self .now , tick = False ),
7414
+ mock .patch ("stripe.Invoice.retrieve" , return_value = mock_invoice ),
7405
7415
):
7406
7416
result = self .client_get (
7407
7417
f"{ self .billing_session .billing_base_url } /upgrade/?tier={ CustomerPlan .TIER_SELF_HOSTED_BASIC } " ,
@@ -8894,9 +8904,10 @@ def test_redirect_for_remote_server_billing_page_downgrade_at_free_trial_end(
8894
8904
self .assert_in_response (substring , response )
8895
8905
8896
8906
# schedule downgrade
8897
- with time_machine .travel (self .now + timedelta (days = 3 ), tick = False ), self .assertLogs (
8898
- "corporate.stripe" , "INFO"
8899
- ) as m :
8907
+ with (
8908
+ time_machine .travel (self .now + timedelta (days = 3 ), tick = False ),
8909
+ self .assertLogs ("corporate.stripe" , "INFO" ) as m ,
8910
+ ):
8900
8911
response = self .client_billing_patch (
8901
8912
"/billing/plan" ,
8902
8913
{"status" : CustomerPlan .DOWNGRADE_AT_END_OF_FREE_TRIAL },
@@ -9210,8 +9221,9 @@ def test_upgrade_server_to_fixed_price_plan_pay_by_invoice(self, *mocks: Mock) -
9210
9221
self .execute_remote_billing_authentication_flow (hamlet .delivery_email , hamlet .full_name )
9211
9222
mock_invoice = MagicMock ()
9212
9223
mock_invoice .hosted_invoice_url = "payments_page_url"
9213
- with time_machine .travel (self .now , tick = False ), mock .patch (
9214
- "stripe.Invoice.retrieve" , return_value = mock_invoice
9224
+ with (
9225
+ time_machine .travel (self .now , tick = False ),
9226
+ mock .patch ("stripe.Invoice.retrieve" , return_value = mock_invoice ),
9215
9227
):
9216
9228
result = self .client_get (
9217
9229
f"{ self .billing_session .billing_base_url } /upgrade/?tier={ CustomerPlan .TIER_SELF_HOSTED_BASIC } " ,
@@ -9663,9 +9675,11 @@ def test_legacy_plan_ends_on_plan_end_date(self, *mocks: Mock) -> None:
9663
9675
self .remote_server .plan_type , RemoteZulipServer .PLAN_TYPE_SELF_MANAGED_LEGACY
9664
9676
)
9665
9677
9666
- with mock .patch ("stripe.Invoice.create" ) as invoice_create , mock .patch (
9667
- "corporate.lib.stripe.send_email"
9668
- ) as send_email , time_machine .travel (plan_end_date , tick = False ):
9678
+ with (
9679
+ mock .patch ("stripe.Invoice.create" ) as invoice_create ,
9680
+ mock .patch ("corporate.lib.stripe.send_email" ) as send_email ,
9681
+ time_machine .travel (plan_end_date , tick = False ),
9682
+ ):
9669
9683
invoice_plans_as_needed ()
9670
9684
# Verify that for legacy plan with no next plan scheduled,
9671
9685
# invoice overdue email is not sent even if the last audit log
@@ -9730,9 +9744,11 @@ def test_invoice_scheduled_upgrade_server_legacy_plan(self, *mocks: Mock) -> Non
9730
9744
)
9731
9745
licenses = max (min_licenses , server_user_count )
9732
9746
9733
- with mock .patch ("stripe.Invoice.finalize_invoice" ) as invoice_create , mock .patch (
9734
- "corporate.lib.stripe.send_email"
9735
- ) as send_email , time_machine .travel (end_date , tick = False ):
9747
+ with (
9748
+ mock .patch ("stripe.Invoice.finalize_invoice" ) as invoice_create ,
9749
+ mock .patch ("corporate.lib.stripe.send_email" ) as send_email ,
9750
+ time_machine .travel (end_date , tick = False ),
9751
+ ):
9736
9752
invoice_plans_as_needed ()
9737
9753
# Verify that for legacy plan with next plan scheduled, invoice
9738
9754
# overdue email is sent if the last audit log is stale.
0 commit comments