From b7d3a1a0f38d79898b85c815a2bec7e85be8f3d6 Mon Sep 17 00:00:00 2001 From: Vishnu Ks Date: Thu, 26 Jul 2018 13:46:20 +0530 Subject: [PATCH] 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". --- zilencer/lib/stripe.py | 17 ++++++++--------- zilencer/tests/test_stripe.py | 18 ------------------ 2 files changed, 8 insertions(+), 27 deletions(-) diff --git a/zilencer/lib/stripe.py b/zilencer/lib/stripe.py index ca09c840e0..718b08aa30 100644 --- a/zilencer/lib/stripe.py +++ b/zilencer/lib/stripe.py @@ -69,15 +69,14 @@ class StripeError(JsonableError): def catch_stripe_errors(func: CallableT) -> CallableT: @wraps(func) def wrapped(*args: Any, **kwargs: Any) -> Any: - if not settings.TEST_SUITE and STRIPE_PUBLISHABLE_KEY is None: - # Dev-only message; no translation needed. - raise StripeError( - "Missing Stripe config. See https://zulip.readthedocs.io/en/latest/subsystems/billing.html.") - - if not Plan.objects.exists(): - # Dev-only message; no translation needed. - raise StripeError( - "Plan objects not created. Please run ./manage.py setup_stripe") + if settings.DEVELOPMENT and not settings.TEST_SUITE: # nocoverage + if STRIPE_PUBLISHABLE_KEY is None: + raise AssertionError( + "Missing Stripe config. " + "See https://zulip.readthedocs.io/en/latest/subsystems/billing.html.") + if not Plan.objects.exists(): + raise AssertionError( + "Plan objects not created. Please run ./manage.py setup_stripe") try: return func(*args, **kwargs) diff --git a/zilencer/tests/test_stripe.py b/zilencer/tests/test_stripe.py index 665ded38c9..03dad96dea 100644 --- a/zilencer/tests/test_stripe.py +++ b/zilencer/tests/test_stripe.py @@ -74,24 +74,6 @@ class StripeTest(ZulipTestCase): raise_exception() 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.Subscription.create", side_effect=mock_create_subscription) def test_initial_upgrade(self, mock_create_subscription: mock.Mock,