Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
populate_db: Import timedelta from its canonical module.
Anders Kaseorgaa577a554b58
diff --git a/zerver/tests/test_populate_db.py b/zerver/tests/test_populate_db.pyindex 8d5fc84131e..605b8338e47 100644--- a/zerver/tests/test_populate_db.py+++ b/zerver/tests/test_populate_db.py@@ -1,4 +1,4 @@-from django.utils.timezone import timedelta as timezone_timedelta+from datetime import timedeltafrom zerver.lib.test_classes import ZulipTestCasefrom zilencer.management.commands.populate_db import choose_date_sent@@ -19,9 +19,7 @@ class TestChoosePubDate(ZulipTestCase):# 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)- )+ self.assertTrue(datetimes_list[i] - datetimes_list[i - 1] > timedelta(minutes=5))class TestUserTimeZones(ZulipTestCase):diff --git a/zilencer/management/commands/populate_db.py b/zilencer/management/commands/populate_db.pyindex b4b4bf2c6c9..6b8c1d9269e 100644--- a/zilencer/management/commands/populate_db.py+++ b/zilencer/management/commands/populate_db.py@@ -2,7 +2,7 @@ import itertoolsimport osimport randomfrom collections import defaultdict-from datetime import datetime+from datetime import datetime, timedeltafrom typing import Any, Dict, List, Mapping, Sequence, Tupleimport bmemcached@@ -16,7 +16,6 @@ from django.db import connectionfrom django.db.models import Ffrom django.db.models.signals import post_deletefrom django.utils.timezone import now as timezone_now-from django.utils.timezone import timedelta as timezone_timedeltafrom scripts.lib.zulip_tools import get_or_create_dev_uuid_var_pathfrom zerver.actions.create_realm import do_create_realm@@ -1223,7 +1222,7 @@ def choose_date_sent(amount_in_second_chunk = tot_messages - amount_in_first_chunkif num_messages < amount_in_first_chunk:- spoofed_date = timezone_now() - timezone_timedelta(days=oldest_message_days)+ spoofed_date = timezone_now() - timedelta(days=oldest_message_days)num_days_for_first_chunk = min(oldest_message_days - 2, 1)interval_size = num_days_for_first_chunk * 24 * 60 * 60 / amount_in_first_chunklower_bound = interval_size * num_messages@@ -1231,13 +1230,13 @@ def choose_date_sent(else:# We're in the last 20% of messages, so distribute them over the last 24 hours:- spoofed_date = timezone_now() - timezone_timedelta(days=1)+ spoofed_date = timezone_now() - timedelta(days=1)interval_size = 24 * 60 * 60 / amount_in_second_chunklower_bound = interval_size * (num_messages - amount_in_first_chunk)upper_bound = interval_size * (num_messages - amount_in_first_chunk + 1)offset_seconds = random.uniform(lower_bound, upper_bound)- spoofed_date += timezone_timedelta(seconds=offset_seconds)+ spoofed_date += timedelta(seconds=offset_seconds)return spoofed_date