mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 23:13:25 +00:00
remote_billing: Fix two tests that shouldn't be asserting in a loop.
It doesn't make sense to run a loop over "all" query results, when those results are just two, and each of them has its own distinct asserts. That for loop is there probably due to copying the structure of the earlier test_transfer_legacy_plan_from_server_to_all_realms test, for which the loop does make sense.
This commit is contained in:
committed by
Tim Abbott
parent
68f02da82e
commit
1c61bb2fad
@@ -839,26 +839,37 @@ class RemoteBillingAuthenticationTest(RemoteRealmBillingTestCase):
|
|||||||
["zephyr.testserver", "lear.testserver"],
|
["zephyr.testserver", "lear.testserver"],
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check legacy CustomerPlan exists for all realms except bot realm.
|
# Check legacy CustomerPlan exists for the one non-deactivated "real" realm
|
||||||
for remote_realm in RemoteRealm.objects.filter(realm_deactivated=False):
|
# and does not for the bot realm.
|
||||||
if remote_realm.is_system_bot_realm:
|
|
||||||
self.assertIsNone(get_customer_by_remote_realm(remote_realm))
|
|
||||||
continue
|
|
||||||
|
|
||||||
self.assertEqual(remote_realm.host, "zulip.testserver")
|
# Sanity check that the setup for this test is the way we think it is.
|
||||||
customer = get_customer_by_remote_realm(remote_realm)
|
self.assertEqual(RemoteRealm.objects.filter(realm_deactivated=False).count(), 2)
|
||||||
|
# These queries have a unique result, so we can use .get().
|
||||||
|
remote_realm_with_plan = RemoteRealm.objects.get(
|
||||||
|
realm_deactivated=False, is_system_bot_realm=False
|
||||||
|
)
|
||||||
|
system_bot_remote_realm = RemoteRealm.objects.get(
|
||||||
|
realm_deactivated=False, is_system_bot_realm=True
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertIsNone(get_customer_by_remote_realm(system_bot_remote_realm))
|
||||||
|
|
||||||
|
self.assertEqual(remote_realm_with_plan.host, "zulip.testserver")
|
||||||
|
customer = get_customer_by_remote_realm(remote_realm_with_plan)
|
||||||
assert customer is not None
|
assert customer is not None
|
||||||
# Customer got transferred from server to realm.
|
# Customer got transferred from server to realm.
|
||||||
self.assertEqual(customer, server_customer)
|
self.assertEqual(customer, server_customer)
|
||||||
plan = get_current_plan_by_customer(customer)
|
plan = get_current_plan_by_customer(customer)
|
||||||
assert plan is not None
|
assert plan is not None
|
||||||
self.assertEqual(remote_realm.plan_type, RemoteRealm.PLAN_TYPE_SELF_MANAGED_LEGACY)
|
self.assertEqual(
|
||||||
|
remote_realm_with_plan.plan_type, RemoteRealm.PLAN_TYPE_SELF_MANAGED_LEGACY
|
||||||
|
)
|
||||||
self.assertEqual(plan.tier, CustomerPlan.TIER_SELF_HOSTED_LEGACY)
|
self.assertEqual(plan.tier, CustomerPlan.TIER_SELF_HOSTED_LEGACY)
|
||||||
self.assertEqual(plan.status, CustomerPlan.SWITCH_PLAN_TIER_AT_PLAN_END)
|
self.assertEqual(plan.status, CustomerPlan.SWITCH_PLAN_TIER_AT_PLAN_END)
|
||||||
self.assertEqual(plan.billing_cycle_anchor, start_date)
|
self.assertEqual(plan.billing_cycle_anchor, start_date)
|
||||||
self.assertEqual(plan.end_date, end_date)
|
self.assertEqual(plan.end_date, end_date)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
RemoteRealmBillingSession(remote_realm).get_next_plan(plan), server_next_plan
|
RemoteRealmBillingSession(remote_realm_with_plan).get_next_plan(plan), server_next_plan
|
||||||
)
|
)
|
||||||
|
|
||||||
@responses.activate
|
@responses.activate
|
||||||
@@ -936,19 +947,27 @@ class RemoteBillingAuthenticationTest(RemoteRealmBillingTestCase):
|
|||||||
self.assertEqual(self.server.plan_type, RemoteZulipServer.PLAN_TYPE_SELF_MANAGED)
|
self.assertEqual(self.server.plan_type, RemoteZulipServer.PLAN_TYPE_SELF_MANAGED)
|
||||||
|
|
||||||
# Check business CustomerPlan exists for all realms except bot realm.
|
# Check business CustomerPlan exists for all realms except bot realm.
|
||||||
for remote_realm in RemoteRealm.objects.filter(realm_deactivated=False):
|
|
||||||
if remote_realm.is_system_bot_realm:
|
|
||||||
self.assertIsNone(get_customer_by_remote_realm(remote_realm))
|
|
||||||
continue
|
|
||||||
|
|
||||||
self.assertEqual(remote_realm.host, "zulip.testserver")
|
# Sanity check that the setup for this test is the way we think it is.
|
||||||
customer = get_customer_by_remote_realm(remote_realm)
|
self.assertEqual(RemoteRealm.objects.filter(realm_deactivated=False).count(), 2)
|
||||||
|
# These queries have a unique result, so we can use .get().
|
||||||
|
remote_realm_with_plan = RemoteRealm.objects.get(
|
||||||
|
realm_deactivated=False, is_system_bot_realm=False
|
||||||
|
)
|
||||||
|
system_bot_remote_realm = RemoteRealm.objects.get(
|
||||||
|
realm_deactivated=False, is_system_bot_realm=True
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertIsNone(get_customer_by_remote_realm(system_bot_remote_realm))
|
||||||
|
|
||||||
|
self.assertEqual(remote_realm_with_plan.host, "zulip.testserver")
|
||||||
|
customer = get_customer_by_remote_realm(remote_realm_with_plan)
|
||||||
assert customer is not None
|
assert customer is not None
|
||||||
# Customer got transferred from server to realm.
|
# Customer got transferred from server to realm.
|
||||||
self.assertEqual(customer, server_customer)
|
self.assertEqual(customer, server_customer)
|
||||||
plan = get_current_plan_by_customer(customer)
|
plan = get_current_plan_by_customer(customer)
|
||||||
assert plan is not None
|
assert plan is not None
|
||||||
self.assertEqual(remote_realm.plan_type, RemoteRealm.PLAN_TYPE_BUSINESS)
|
self.assertEqual(remote_realm_with_plan.plan_type, RemoteRealm.PLAN_TYPE_BUSINESS)
|
||||||
self.assertEqual(plan.tier, CustomerPlan.TIER_SELF_HOSTED_BUSINESS)
|
self.assertEqual(plan.tier, CustomerPlan.TIER_SELF_HOSTED_BUSINESS)
|
||||||
self.assertEqual(plan.status, CustomerPlan.ACTIVE)
|
self.assertEqual(plan.status, CustomerPlan.ACTIVE)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user