mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	billing: Don't check for stripe key and plan objects in tests.
Stripe already returns an appropriate error in prod, and these checks are just a hassle in tests. Also fixes an error where the check for Plan.objects.exists() was missing a "not".
This commit is contained in:
		@@ -69,15 +69,14 @@ class StripeError(JsonableError):
 | 
				
			|||||||
def catch_stripe_errors(func: CallableT) -> CallableT:
 | 
					def catch_stripe_errors(func: CallableT) -> CallableT:
 | 
				
			||||||
    @wraps(func)
 | 
					    @wraps(func)
 | 
				
			||||||
    def wrapped(*args: Any, **kwargs: Any) -> Any:
 | 
					    def wrapped(*args: Any, **kwargs: Any) -> Any:
 | 
				
			||||||
        if not settings.TEST_SUITE and STRIPE_PUBLISHABLE_KEY is None:
 | 
					        if settings.DEVELOPMENT and not settings.TEST_SUITE:  # nocoverage
 | 
				
			||||||
            # Dev-only message; no translation needed.
 | 
					            if STRIPE_PUBLISHABLE_KEY is None:
 | 
				
			||||||
            raise StripeError(
 | 
					                raise AssertionError(
 | 
				
			||||||
                "Missing Stripe config. See https://zulip.readthedocs.io/en/latest/subsystems/billing.html.")
 | 
					                    "Missing Stripe config. "
 | 
				
			||||||
 | 
					                    "See https://zulip.readthedocs.io/en/latest/subsystems/billing.html.")
 | 
				
			||||||
        if not Plan.objects.exists():
 | 
					            if not Plan.objects.exists():
 | 
				
			||||||
            # Dev-only message; no translation needed.
 | 
					                raise AssertionError(
 | 
				
			||||||
            raise StripeError(
 | 
					                    "Plan objects not created. Please run ./manage.py setup_stripe")
 | 
				
			||||||
                "Plan objects not created. Please run ./manage.py setup_stripe")
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            return func(*args, **kwargs)
 | 
					            return func(*args, **kwargs)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -74,24 +74,6 @@ class StripeTest(ZulipTestCase):
 | 
				
			|||||||
            raise_exception()
 | 
					            raise_exception()
 | 
				
			||||||
        mock_billing_logger_error.assert_called()
 | 
					        mock_billing_logger_error.assert_called()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @mock.patch("zilencer.lib.stripe.STRIPE_PUBLISHABLE_KEY", None)
 | 
					 | 
				
			||||||
    def test_no_stripe_keys(self) -> None:
 | 
					 | 
				
			||||||
        @catch_stripe_errors
 | 
					 | 
				
			||||||
        def foo() -> None:
 | 
					 | 
				
			||||||
            pass  # nocoverage
 | 
					 | 
				
			||||||
        with self.settings(TEST_SUITE=False):
 | 
					 | 
				
			||||||
            with self.assertRaisesRegex(StripeError, "Missing Stripe config."):
 | 
					 | 
				
			||||||
                foo()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def test_no_plan_objects(self) -> None:
 | 
					 | 
				
			||||||
        Plan.objects.all().delete()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        @catch_stripe_errors
 | 
					 | 
				
			||||||
        def foo() -> None:
 | 
					 | 
				
			||||||
            pass  # nocoverage
 | 
					 | 
				
			||||||
        with self.assertRaisesRegex(StripeError, "Plan objects not created. Please run ./manage.py"):
 | 
					 | 
				
			||||||
            foo()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @mock.patch("stripe.Customer.create", side_effect=mock_create_customer)
 | 
					    @mock.patch("stripe.Customer.create", side_effect=mock_create_customer)
 | 
				
			||||||
    @mock.patch("stripe.Subscription.create", side_effect=mock_create_subscription)
 | 
					    @mock.patch("stripe.Subscription.create", side_effect=mock_create_subscription)
 | 
				
			||||||
    def test_initial_upgrade(self, mock_create_subscription: mock.Mock,
 | 
					    def test_initial_upgrade(self, mock_create_subscription: mock.Mock,
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user