Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

stripe: Save a query to get CustomerPlan for sponsored customers.

Aman Agrawald4a852e97c96
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py
index 613b6cd623a..ddab91a38ad 100644
--- a/corporate/lib/stripe.py
+++ b/corporate/lib/stripe.py
@@ -4098,11 +4098,6 @@ def get_push_status_for_remote_request(
billing_session = RemoteServerBillingSession(remote_server)
customer = billing_session.get_customer()
- if customer is not None:
- current_plan = get_current_plan_by_customer(customer)
- else:
- current_plan = None
-
if billing_session.is_sponsored():
return PushNotificationsEnabledStatus(
can_push=True,
@@ -4110,6 +4105,11 @@ def get_push_status_for_remote_request(
message="Community plan",
)
+ if customer is not None:
+ current_plan = get_current_plan_by_customer(customer)
+ else:
+ current_plan = None
+
if current_plan is not None:
if current_plan.status in [
CustomerPlan.DOWNGRADE_AT_END_OF_CYCLE,
diff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.py
index 397fd7cb004..ec74e192f09 100644
--- a/zerver/tests/test_push_notifications.py
+++ b/zerver/tests/test_push_notifications.py
@@ -2191,7 +2191,7 @@ class AnalyticsBouncerTest(BouncerTestCase):
with mock.patch(
"zilencer.views.RemoteRealmBillingSession.get_customer", return_value=dummy_customer
- ) as m:
+ ):
with mock.patch(
"corporate.lib.stripe.get_current_plan_by_customer", return_value=None
) as m:
@@ -2200,7 +2200,7 @@ class AnalyticsBouncerTest(BouncerTestCase):
return_value=11,
):
send_server_data_to_push_bouncer(consider_usage_statistics=False)
- m.assert_called()
+ m.assert_not_called()
realms = Realm.objects.all()
for realm in realms:
self.assertEqual(realm.push_notifications_enabled, True)