11import math
22import os
33import time
4- from datetime import datetime , timedelta
4+ from datetime import UTC , datetime , timedelta
55from itertools import count
66from time import monotonic
77from unittest .mock import patch
@@ -199,7 +199,7 @@ def test_entry_and_model_last_run_at_with_utc_no_use_tz(self, monkeypatch):
199199 time .tzset ()
200200 assert self .app .timezone .key == 'Europe/Berlin'
201201 # simulate last_run_at from DB - not TZ aware but localtime
202- right_now = datetime .utcnow ( )
202+ right_now = datetime .now ( UTC )
203203 # make sure to use fixed date time
204204 monkeypatch .setattr (self .Entry , '_default_now' , lambda o : right_now )
205205 m = self .create_model_crontab (
@@ -233,7 +233,7 @@ def test_entry_and_model_last_run_at_when_model_changed(self, monkeypatch):
233233 time .tzset ()
234234 assert self .app .timezone .key == 'Europe/Berlin'
235235 # simulate last_run_at from DB - not TZ aware but localtime
236- right_now = datetime .utcnow ( )
236+ right_now = datetime .now ( UTC )
237237 # make sure to use fixed date time
238238 monkeypatch .setattr (self .Entry , '_default_now' , lambda o : right_now )
239239 m = self .create_model_crontab (
@@ -286,7 +286,7 @@ def test_entry_is_due__celery_timezone_doesnt_match_time_zone(self):
286286
287287 # simulate last_run_at all none, doing the same thing that
288288 # _default_now() would do
289- right_now = datetime .utcnow ( )
289+ right_now = datetime .now ( UTC )
290290
291291 m = self .create_model_crontab (
292292 crontab (minute = '*/10' ),
@@ -1478,28 +1478,6 @@ def setup_method(self):
14781478 def teardown_method (self ):
14791479 patch .stopall ()
14801480
1481- @patch ("django_celery_beat.schedulers.aware_now" )
1482- def test_server_timezone_handling_with_zoneinfo (self , mock_aware_now ):
1483- """Test handling when server timezone is already a ZoneInfo instance."""
1484-
1485- # Create a mock scheduler with only the methods we need to test
1486- class MockScheduler :
1487- _get_timezone_offset = schedulers .DatabaseScheduler ._get_timezone_offset
1488-
1489- s = MockScheduler ()
1490-
1491- tokyo_tz = ZoneInfo ("Asia/Tokyo" )
1492- mock_now = datetime (2023 , 1 , 1 , 12 , 0 , 0 , tzinfo = tokyo_tz )
1493- mock_aware_now .return_value = mock_now
1494-
1495- # Test with a different timezone
1496- new_york_tz = "America/New_York"
1497- offset = s ._get_timezone_offset (new_york_tz ) # Pass self explicitly
1498-
1499- # Tokyo is UTC+9, New York is UTC-5, so difference should be 14 hours
1500- assert offset == 14
1501- assert mock_aware_now .called
1502-
15031481 @patch ("django_celery_beat.schedulers.aware_now" )
15041482 def test_timezone_offset_with_zoneinfo_object_param (self , mock_aware_now ):
15051483 """Test handling when timezone_name parameter is a ZoneInfo object."""
@@ -1519,3 +1497,4 @@ class MockScheduler:
15191497
15201498 # Tokyo is UTC+9, New York is UTC-5, so difference should be 14 hours
15211499 assert offset == 14
1500+ assert mock_aware_now .called
0 commit comments