mirror of https://github.com/zulip/zulip.git
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:
parent
ecb3879d0c
commit
b7d3a1a0f3
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue