streams: Don't compute traffic data for sub objects in zephyr realm.

We set stream_weekly_traffic field to "null" for Subscription
objects in zephyr mirror realm as we do not need stream traffic
data in zephyr mirror realm. This makes the subscription data
consistent with steams data.

This commit also udpates test to check never_subscribed data for
zephyr mirror realm.
This commit is contained in:
Sahil Batra
2023-08-16 17:25:10 +05:30
committed by Tim Abbott
parent 6776e380b2
commit 7137eba222
3 changed files with 32 additions and 13 deletions

View File

@@ -4967,7 +4967,7 @@ class SubscriptionAPITest(ZulipTestCase):
# realm. This does generate stream creation events from
# send_stream_creation_events_for_previously_inaccessible_streams.
with self.capture_send_event_calls(expected_num_events=num_streams + 1) as events:
with self.assert_database_query_count(num_streams + 12):
with self.assert_database_query_count(num_streams + 11):
self.common_subscribe_to_streams(
mit_user,
stream_names,
@@ -6249,7 +6249,7 @@ class GetSubscribersTest(ZulipTestCase):
subdomain="zephyr",
)
with self.assert_database_query_count(4):
with self.assert_database_query_count(3):
subscribed_streams, _ = gather_subscriptions(mit_user_profile, include_subscribers=True)
self.assertGreaterEqual(len(subscribed_streams), 2)
@@ -6260,6 +6260,19 @@ class GetSubscribersTest(ZulipTestCase):
self.assert_length(sub["subscribers"], len(users_to_subscribe))
else:
self.assert_length(sub["subscribers"], 0)
self.assertIsNone(sub["stream_weekly_traffic"])
# Create a web-public stream to test never_subscried data.
self.make_stream("mit_stream_2", realm=mit_user_profile.realm, is_web_public=True)
self.make_stream("mit_stream_3", realm=mit_user_profile.realm)
sub_info = gather_subscriptions_helper(mit_user_profile, include_subscribers=True)
never_subscribed_streams = sub_info.never_subscribed
# Users in zephyr mirror realm can only access web-public never subscribed streams.
self.assert_length(never_subscribed_streams, 1)
self.assertEqual(never_subscribed_streams[0]["name"], "mit_stream_2")
self.assertTrue(never_subscribed_streams[0]["is_web_public"])
self.assertIsNone(never_subscribed_streams[0]["stream_weekly_traffic"])
def test_nonsubscriber(self) -> None:
"""