mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	populate_db: Import timedelta from its canonical module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit aa577a554b)
			
			
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							94a3f2cf1c
						
					
				
				
					commit
					51d2dc68c8
				
			@@ -1,4 +1,4 @@
 | 
				
			|||||||
from django.utils.timezone import timedelta as timezone_timedelta
 | 
					from datetime import timedelta
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from zerver.lib.test_classes import ZulipTestCase
 | 
					from zerver.lib.test_classes import ZulipTestCase
 | 
				
			||||||
from zilencer.management.commands.populate_db import choose_date_sent
 | 
					from zilencer.management.commands.populate_db import choose_date_sent
 | 
				
			||||||
@@ -19,9 +19,7 @@ class TestChoosePubDate(ZulipTestCase):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        # Verify there is a meaningful difference between elements.
 | 
					        # Verify there is a meaningful difference between elements.
 | 
				
			||||||
        for i in range(1, len(datetimes_list)):
 | 
					        for i in range(1, len(datetimes_list)):
 | 
				
			||||||
            self.assertTrue(
 | 
					            self.assertTrue(datetimes_list[i] - datetimes_list[i - 1] > timedelta(minutes=5))
 | 
				
			||||||
                datetimes_list[i] - datetimes_list[i - 1] > timezone_timedelta(minutes=5)
 | 
					 | 
				
			||||||
            )
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestUserTimeZones(ZulipTestCase):
 | 
					class TestUserTimeZones(ZulipTestCase):
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,7 +2,7 @@ import itertools
 | 
				
			|||||||
import os
 | 
					import os
 | 
				
			||||||
import random
 | 
					import random
 | 
				
			||||||
from collections import defaultdict
 | 
					from collections import defaultdict
 | 
				
			||||||
from datetime import datetime
 | 
					from datetime import datetime, timedelta
 | 
				
			||||||
from typing import Any, Dict, List, Mapping, Sequence, Tuple
 | 
					from typing import Any, Dict, List, Mapping, Sequence, Tuple
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import bmemcached
 | 
					import bmemcached
 | 
				
			||||||
@@ -15,7 +15,6 @@ from django.core.management.base import BaseCommand, CommandParser
 | 
				
			|||||||
from django.db import connection
 | 
					from django.db import connection
 | 
				
			||||||
from django.db.models import F
 | 
					from django.db.models import F
 | 
				
			||||||
from django.utils.timezone import now as timezone_now
 | 
					from django.utils.timezone import now as timezone_now
 | 
				
			||||||
from django.utils.timezone import timedelta as timezone_timedelta
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
from scripts.lib.zulip_tools import get_or_create_dev_uuid_var_path
 | 
					from scripts.lib.zulip_tools import get_or_create_dev_uuid_var_path
 | 
				
			||||||
from zerver.actions.create_realm import do_create_realm
 | 
					from zerver.actions.create_realm import do_create_realm
 | 
				
			||||||
@@ -1212,7 +1211,7 @@ def choose_date_sent(
 | 
				
			|||||||
    amount_in_second_chunk = tot_messages - amount_in_first_chunk
 | 
					    amount_in_second_chunk = tot_messages - amount_in_first_chunk
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if num_messages < amount_in_first_chunk:
 | 
					    if 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)
 | 
					        num_days_for_first_chunk = min(oldest_message_days - 2, 1)
 | 
				
			||||||
        interval_size = num_days_for_first_chunk * 24 * 60 * 60 / amount_in_first_chunk
 | 
					        interval_size = num_days_for_first_chunk * 24 * 60 * 60 / amount_in_first_chunk
 | 
				
			||||||
        lower_bound = interval_size * num_messages
 | 
					        lower_bound = interval_size * num_messages
 | 
				
			||||||
@@ -1220,13 +1219,13 @@ def choose_date_sent(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        # We're in the last 20% of messages, so distribute them over the last 24 hours:
 | 
					        # 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_chunk
 | 
					        interval_size = 24 * 60 * 60 / amount_in_second_chunk
 | 
				
			||||||
        lower_bound = interval_size * (num_messages - amount_in_first_chunk)
 | 
					        lower_bound = interval_size * (num_messages - amount_in_first_chunk)
 | 
				
			||||||
        upper_bound = interval_size * (num_messages - amount_in_first_chunk + 1)
 | 
					        upper_bound = interval_size * (num_messages - amount_in_first_chunk + 1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    offset_seconds = random.uniform(lower_bound, upper_bound)
 | 
					    offset_seconds = random.uniform(lower_bound, upper_bound)
 | 
				
			||||||
    spoofed_date += timezone_timedelta(seconds=offset_seconds)
 | 
					    spoofed_date += timedelta(seconds=offset_seconds)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return spoofed_date
 | 
					    return spoofed_date
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user