test_classes: Create helper function for subscribing realm to manual plan.

This commit is contained in:
Vishnu KS
2021-06-03 15:50:31 +05:30
committed by Tim Abbott
parent 9e5f382241
commit 7197c8ae89
2 changed files with 74 additions and 0 deletions

View File

@@ -43,6 +43,7 @@ from django.utils.timezone import now as timezone_now
from fakeldap import MockLDAP
from two_factor.models import PhoneDevice
from corporate.models import Customer, CustomerPlan, LicenseLedger
from zerver.decorator import do_two_factor_login
from zerver.lib.actions import (
bulk_add_subscriptions,
@@ -1266,6 +1267,35 @@ Output:
self.assertTrue(validation_func(new_member_user))
self.assertFalse(validation_func(guest_user))
def subscribe_realm_to_manual_license_management_plan(
self, realm: Realm, licenses: int, licenses_at_next_renewal: int, billing_schedule: int
) -> Tuple[CustomerPlan, LicenseLedger]:
customer, _ = Customer.objects.get_or_create(realm=realm)
plan = CustomerPlan.objects.create(
customer=customer,
automanage_licenses=False,
billing_cycle_anchor=timezone_now(),
billing_schedule=billing_schedule,
tier=CustomerPlan.STANDARD,
)
ledger = LicenseLedger.objects.create(
plan=plan,
is_renewal=True,
event_time=timezone_now(),
licenses=licenses,
licenses_at_next_renewal=licenses_at_next_renewal,
)
realm.plan_type = Realm.STANDARD
realm.save(update_fields=["plan_type"])
return plan, ledger
def subscribe_realm_to_monthly_plan_on_manual_license_management(
self, realm: Realm, licenses: int, licenses_at_next_renewal: int
) -> Tuple[CustomerPlan, LicenseLedger]:
return self.subscribe_realm_to_manual_license_management_plan(
realm, licenses, licenses_at_next_renewal, CustomerPlan.MONTHLY
)
@contextmanager
def tornado_redirected_to_list(
self, lst: List[Mapping[str, Any]], expected_num_events: int