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.

test_remote_counts: Insert in date order.

Alex Vandiverf4cbb494ac8a
diff --git a/corporate/tests/test_remote_counts.py b/corporate/tests/test_remote_counts.py
index e817050a063..346a0025a48 100644
--- a/corporate/tests/test_remote_counts.py
+++ b/corporate/tests/test_remote_counts.py
@@ -51,51 +51,54 @@ class RemoteCountTest(ZulipTestCase):
# we actually don't record 0s), then the function should just very reasonably return 0.
self.assertEqual(compute_max_monthly_messages(self.server), 0)
- # Last 30 days of data:
+ # We insert these oldest-first so that the ids are in a
+ # realistic order. This is >90 days ago and should be ignored
+ # for the calculation. We simulate the highest amounts of
+ # messages here, to test that this is indeed ignored.
RemoteInstallationCount.objects.bulk_create(
RemoteInstallationCount(
server=self.server,
- remote_id=1,
+ remote_id=1 + t,
property="messages_sent:message_type:day",
- value=10,
- end_time=now_offset - datetime.timedelta(days=t),
+ value=100,
+ end_time=now_offset - datetime.timedelta(days=90 + (31 - t)),
)
for t in range(1, 31)
)
- # 30 days before that:
- # This will be the peak of the last 3 months - with 900 messages total
+
+ # Days 60 - 89 ago; this is the last month we're considering for
+ # the calculation
RemoteInstallationCount.objects.bulk_create(
RemoteInstallationCount(
server=self.server,
- remote_id=1,
+ remote_id=31 + t,
property="messages_sent:message_type:day",
- value=30,
- end_time=now_offset - datetime.timedelta(days=30 + t),
+ value=20,
+ end_time=now_offset - datetime.timedelta(days=60 + (31 - t)),
)
for t in range(1, 31)
)
- # Additional 30 days before that:
- # This is the last month we're considering for the calculation
+ # Days 30 - 59 ago: this will be the peak of the last 3 months -
+ # with 900 messages total
RemoteInstallationCount.objects.bulk_create(
RemoteInstallationCount(
server=self.server,
- remote_id=1,
+ remote_id=61 + t,
property="messages_sent:message_type:day",
- value=20,
- end_time=now_offset - datetime.timedelta(days=60 + t),
+ value=30,
+ end_time=now_offset - datetime.timedelta(days=30 + (31 - t)),
)
for t in range(1, 31)
)
- # Additional 30 days before that:
- # This is >90 days ago and should be ignored for the calculation. We simulate the highest
- # amounts of messages here, to test that this is indeed ignored.
+
+ # Days 0 - 29 ago:
RemoteInstallationCount.objects.bulk_create(
RemoteInstallationCount(
server=self.server,
- remote_id=1,
+ remote_id=91 + t,
property="messages_sent:message_type:day",
- value=100,
- end_time=now_offset - datetime.timedelta(days=90 + t),
+ value=10,
+ end_time=now_offset - datetime.timedelta(days=(31 - t)),
)
for t in range(1, 31)
)