Files
zulip/zerver/tests/test_populate_db.py
evykassirer 8c3ff92964 populate_db: Add timezones for some test users.
After failing to notice a place where we wanted to hide timezone
information, we decided to add timezones to some of the test
users, so that we can better consider the effects of timezones
when manually testing.

Testing:

* ran populate_db and confirmed users had timezones in the UI
* updated test_populate_db.py
2022-02-22 11:14:58 -08:00

35 lines
1.4 KiB
Python

from django.utils.timezone import timedelta as timezone_timedelta
from zerver.lib.test_classes import ZulipTestCase
from zilencer.management.commands.populate_db import choose_date_sent
class TestChoosePubDate(ZulipTestCase):
def test_choose_date_sent_large_tot_messages(self) -> None:
"""
Test for a bug that was present, where specifying a large amount of messages to generate
would cause each message to have date_sent set to timezone_now(), instead of the date_sents
being distributed across the span of several days.
"""
tot_messages = 1000000
datetimes_list = [
choose_date_sent(i, tot_messages, 1)
for i in range(1, tot_messages, tot_messages // 100)
]
# Verify there is a meaningful difference between elements.
for i in range(1, len(datetimes_list)):
self.assertTrue(
datetimes_list[i] - datetimes_list[i - 1] > timezone_timedelta(minutes=5)
)
class TestUserTimezones(ZulipTestCase):
def test_timezones_assigned_to_users(self) -> None:
othello = self.example_user("othello")
self.assertEqual(othello.timezone, "US/Pacific")
shiva = self.example_user("shiva")
self.assertEqual(shiva.timezone, "Asia/Kolkata")
cordelia = self.example_user("cordelia")
self.assertEqual(cordelia.timezone, "UTC")