1
1
import math
2
2
import os
3
3
import time
4
+ < << << << HEAD
4
5
from datetime import datetime , timedelta
5
6
from datetime import timezone as dt_timezone
7
+ == == == =
8
+ from datetime import UTC , datetime , timedelta
9
+ > >> >> >> 1152091 (Remove test )
6
10
from itertools import count
7
11
from time import monotonic
8
12
from unittest .mock import patch
@@ -333,7 +337,7 @@ def test_entry_is_due__no_use_tz(self):
333
337
assert self .app .timezone .key == 'Europe/Berlin'
334
338
335
339
# simulate last_run_at from DB - not TZ aware but localtime
336
- right_now = datetime .utcnow ( )
340
+ right_now = datetime .now ( UTC )
337
341
338
342
m = self .create_model_crontab (
339
343
crontab (minute = '*/10' ),
@@ -364,7 +368,7 @@ def test_entry_and_model_last_run_at_with_utc_no_use_tz(self, monkeypatch):
364
368
time .tzset ()
365
369
assert self .app .timezone .key == 'Europe/Berlin'
366
370
# simulate last_run_at from DB - not TZ aware but localtime
367
- right_now = datetime .utcnow ( )
371
+ right_now = datetime .now ( UTC )
368
372
# make sure to use fixed date time
369
373
monkeypatch .setattr (self .Entry , '_default_now' , lambda o : right_now )
370
374
m = self .create_model_crontab (
@@ -398,7 +402,7 @@ def test_entry_and_model_last_run_at_when_model_changed(self, monkeypatch):
398
402
time .tzset ()
399
403
assert self .app .timezone .key == 'Europe/Berlin'
400
404
# simulate last_run_at from DB - not TZ aware but localtime
401
- right_now = datetime .utcnow ( )
405
+ right_now = datetime .now ( UTC )
402
406
# make sure to use fixed date time
403
407
monkeypatch .setattr (self .Entry , '_default_now' , lambda o : right_now )
404
408
m = self .create_model_crontab (
@@ -451,7 +455,7 @@ def test_entry_is_due__celery_timezone_doesnt_match_time_zone(self):
451
455
452
456
# simulate last_run_at all none, doing the same thing that
453
457
# _default_now() would do
454
- right_now = datetime .utcnow ( )
458
+ right_now = datetime .now ( UTC )
455
459
456
460
m = self .create_model_crontab (
457
461
crontab (minute = '*/10' ),
@@ -1678,31 +1682,6 @@ def setup_method(self):
1678
1682
def teardown_method (self ):
1679
1683
patch .stopall ()
1680
1684
1681
- @patch ("django_celery_beat.schedulers.aware_now" )
1682
- def test_server_timezone_handling_with_zoneinfo (self , mock_aware_now ):
1683
- """Test handling when server timezone
1684
- is already a ZoneInfo instance."""
1685
-
1686
- # Create a mock scheduler with only the methods we need to test
1687
- class MockScheduler :
1688
- _get_timezone_offset = (
1689
- schedulers .DatabaseScheduler ._get_timezone_offset
1690
- )
1691
-
1692
- s = MockScheduler ()
1693
-
1694
- tokyo_tz = ZoneInfo ("Asia/Tokyo" )
1695
- mock_now = datetime (2023 , 1 , 1 , 12 , 0 , 0 , tzinfo = tokyo_tz )
1696
- mock_aware_now .return_value = mock_now
1697
-
1698
- # Test with a different timezone
1699
- new_york_tz = "America/New_York"
1700
- offset = s ._get_timezone_offset (new_york_tz ) # Pass self explicitly
1701
-
1702
- # Tokyo is UTC+9, New York is UTC-5, so difference should be 14 hours
1703
- assert offset == 14
1704
- assert mock_aware_now .called
1705
-
1706
1685
@patch ("django_celery_beat.schedulers.aware_now" )
1707
1686
def test_timezone_offset_with_zoneinfo_object_param (self , mock_aware_now ):
1708
1687
"""Test handling when timezone_name parameter is a ZoneInfo object."""
@@ -1724,3 +1703,4 @@ class MockScheduler:
1724
1703
1725
1704
# Tokyo is UTC+9, New York is UTC-5, so difference should be 14 hours
1726
1705
assert offset == 14
1706
+ assert mock_aware_now .called
0 commit comments