2020-06-11 00:54:34 +02:00
|
|
|
from django.utils.timezone import timedelta as timezone_timedelta
|
|
|
|
|
2019-07-11 02:14:40 +02:00
|
|
|
from zerver.lib.test_classes import ZulipTestCase
|
2020-06-11 00:54:34 +02:00
|
|
|
from zilencer.management.commands.populate_db import choose_date_sent
|
2019-07-11 02:14:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TestChoosePubDate(ZulipTestCase):
|
2019-08-28 02:43:19 +02:00
|
|
|
def test_choose_date_sent_large_tot_messages(self) -> None:
|
2019-07-11 02:14:40 +02:00
|
|
|
"""
|
|
|
|
Test for a bug that was present, where specifying a large amount of messages to generate
|
2019-08-28 02:43:19 +02:00
|
|
|
would cause each message to have date_sent set to timezone_now(), instead of the date_sents
|
2019-07-11 02:14:40 +02:00
|
|
|
being distributed across the span of several days.
|
|
|
|
"""
|
|
|
|
tot_messages = 1000000
|
|
|
|
datetimes_list = [
|
2021-02-12 08:19:30 +01:00
|
|
|
choose_date_sent(i, tot_messages, 1)
|
|
|
|
for i in range(1, tot_messages, tot_messages // 100)
|
2019-07-11 02:14:40 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
# Verify there is a meaningful difference between elements.
|
|
|
|
for i in range(1, len(datetimes_list)):
|
2021-02-12 08:19:30 +01:00
|
|
|
self.assertTrue(
|
|
|
|
datetimes_list[i] - datetimes_list[i - 1] > timezone_timedelta(minutes=5)
|
|
|
|
)
|
2022-02-19 00:45:14 +01:00
|
|
|
|
|
|
|
|
2022-02-24 21:15:43 +01:00
|
|
|
class TestUserTimeZones(ZulipTestCase):
|
2022-02-19 00:45:14 +01:00
|
|
|
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")
|