diff --git a/corporate/tests/stripe_fixtures/downgrade_with_no_subscription:Customer.create.1.json b/corporate/tests/stripe_fixtures/downgrade_with_no_subscription:Customer.create.1.json new file mode 100644 index 0000000000..cf059bbcd6 Binary files /dev/null and b/corporate/tests/stripe_fixtures/downgrade_with_no_subscription:Customer.create.1.json differ diff --git a/corporate/tests/stripe_fixtures/downgrade_with_no_subscription:Customer.retrieve.1.json b/corporate/tests/stripe_fixtures/downgrade_with_no_subscription:Customer.retrieve.1.json new file mode 100644 index 0000000000..cf059bbcd6 Binary files /dev/null and b/corporate/tests/stripe_fixtures/downgrade_with_no_subscription:Customer.retrieve.1.json differ diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py index 3d48907768..78c8c7ed1d 100644 --- a/corporate/tests/test_stripe.py +++ b/corporate/tests/test_stripe.py @@ -822,18 +822,17 @@ class StripeTest(ZulipTestCase): event_type=RealmAuditLog.STRIPE_PLAN_CHANGED).values_list('extra_data', flat=True).first()), {'plan': None, 'quantity': 123}) - @patch("stripe.Customer.save") - @patch("stripe.Customer.retrieve", side_effect=mock_create_customer) - def test_downgrade_with_no_subscription( - self, mock_retrieve_customer: Mock, mock_save_customer: Mock) -> None: - realm = get_realm('zulip') - Customer.objects.create( - realm=realm, stripe_customer_id=self.stripe_customer_id, has_billing_relationship=True) - self.login(self.example_email('iago')) - response = self.client_post("/json/billing/downgrade", {}) + @mock_stripe("Customer.retrieve", "Customer.create") + def test_downgrade_with_no_subscription(self, mock2: Mock, mock1: Mock) -> None: + user = self.example_user("iago") + do_create_customer(user) + self.login(user.email) + with patch("stripe.Customer.save") as mock_save_customer: + with patch("corporate.lib.stripe.billing_logger.error"): + response = self.client_post("/json/billing/downgrade", {}) + mock_save_customer.assert_not_called() self.assert_json_error_contains(response, 'Please reload') self.assertEqual(ujson.loads(response.content)['error_description'], 'downgrade without subscription') - mock_save_customer.assert_not_called() @patch("stripe.Subscription.delete") @patch("stripe.Customer.retrieve", side_effect=mock_customer_with_account_balance(1234))