mirror of
https://github.com/zulip/zulip.git
synced 2025-10-23 04:52:12 +00:00
corporate: Use check_int_in in change_plan_status.
This commit is contained in:
@@ -2299,6 +2299,17 @@ class StripeTest(StripeTestCase):
|
|||||||
self.assertEqual(old_plan.next_invoice_date, None)
|
self.assertEqual(old_plan.next_invoice_date, None)
|
||||||
self.assertEqual(old_plan.status, CustomerPlan.ENDED)
|
self.assertEqual(old_plan.status, CustomerPlan.ENDED)
|
||||||
|
|
||||||
|
def test_update_plan_with_invalid_status(self, *mocks: Mock) -> None:
|
||||||
|
with patch("corporate.lib.stripe.timezone_now", return_value=self.now):
|
||||||
|
self.local_upgrade(self.seat_count, True, CustomerPlan.ANNUAL, "token")
|
||||||
|
self.login_user(self.example_user("hamlet"))
|
||||||
|
|
||||||
|
response = self.client_post(
|
||||||
|
"/json/billing/plan/change",
|
||||||
|
{"status": CustomerPlan.NEVER_STARTED},
|
||||||
|
)
|
||||||
|
self.assert_json_error_contains(response, "Invalid status")
|
||||||
|
|
||||||
def test_deactivate_realm(self) -> None:
|
def test_deactivate_realm(self) -> None:
|
||||||
user = self.example_user("hamlet")
|
user = self.example_user("hamlet")
|
||||||
with patch("corporate.lib.stripe.timezone_now", return_value=self.now):
|
with patch("corporate.lib.stripe.timezone_now", return_value=self.now):
|
||||||
|
@@ -46,7 +46,7 @@ from zerver.decorator import (
|
|||||||
from zerver.lib.request import REQ, has_request_variables
|
from zerver.lib.request import REQ, has_request_variables
|
||||||
from zerver.lib.response import json_error, json_success
|
from zerver.lib.response import json_error, json_success
|
||||||
from zerver.lib.send_email import FromAddress, send_email
|
from zerver.lib.send_email import FromAddress, send_email
|
||||||
from zerver.lib.validator import check_int, check_string_in
|
from zerver.lib.validator import check_int, check_int_in, check_string_in
|
||||||
from zerver.models import UserProfile, get_realm
|
from zerver.models import UserProfile, get_realm
|
||||||
|
|
||||||
billing_logger = logging.getLogger("corporate.stripe")
|
billing_logger = logging.getLogger("corporate.stripe")
|
||||||
@@ -357,14 +357,20 @@ def billing_home(request: HttpRequest) -> HttpResponse:
|
|||||||
@require_billing_access
|
@require_billing_access
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def change_plan_status(
|
def change_plan_status(
|
||||||
request: HttpRequest, user: UserProfile, status: int = REQ("status", json_validator=check_int)
|
request: HttpRequest,
|
||||||
|
user: UserProfile,
|
||||||
|
status: int = REQ(
|
||||||
|
"status",
|
||||||
|
json_validator=check_int_in(
|
||||||
|
[
|
||||||
|
CustomerPlan.ACTIVE,
|
||||||
|
CustomerPlan.DOWNGRADE_AT_END_OF_CYCLE,
|
||||||
|
CustomerPlan.SWITCH_TO_ANNUAL_AT_END_OF_CYCLE,
|
||||||
|
CustomerPlan.ENDED,
|
||||||
|
]
|
||||||
|
),
|
||||||
|
),
|
||||||
) -> HttpResponse:
|
) -> HttpResponse:
|
||||||
assert status in [
|
|
||||||
CustomerPlan.ACTIVE,
|
|
||||||
CustomerPlan.DOWNGRADE_AT_END_OF_CYCLE,
|
|
||||||
CustomerPlan.SWITCH_TO_ANNUAL_AT_END_OF_CYCLE,
|
|
||||||
CustomerPlan.ENDED,
|
|
||||||
]
|
|
||||||
|
|
||||||
plan = get_current_plan_by_realm(user.realm)
|
plan = get_current_plan_by_realm(user.realm)
|
||||||
assert plan is not None # for mypy
|
assert plan is not None # for mypy
|
||||||
|
Reference in New Issue
Block a user