1
1
import math
2
2
import os
3
3
import time
4
- from datetime import datetime , timedelta
4
+ from datetime import UTC , datetime , timedelta
5
5
from itertools import count
6
6
from time import monotonic
7
7
from unittest .mock import patch
@@ -199,7 +199,7 @@ def test_entry_and_model_last_run_at_with_utc_no_use_tz(self, monkeypatch):
199
199
time .tzset ()
200
200
assert self .app .timezone .key == 'Europe/Berlin'
201
201
# simulate last_run_at from DB - not TZ aware but localtime
202
- right_now = datetime .utcnow ( )
202
+ right_now = datetime .now ( UTC )
203
203
# make sure to use fixed date time
204
204
monkeypatch .setattr (self .Entry , '_default_now' , lambda o : right_now )
205
205
m = self .create_model_crontab (
@@ -233,7 +233,7 @@ def test_entry_and_model_last_run_at_when_model_changed(self, monkeypatch):
233
233
time .tzset ()
234
234
assert self .app .timezone .key == 'Europe/Berlin'
235
235
# simulate last_run_at from DB - not TZ aware but localtime
236
- right_now = datetime .utcnow ( )
236
+ right_now = datetime .now ( UTC )
237
237
# make sure to use fixed date time
238
238
monkeypatch .setattr (self .Entry , '_default_now' , lambda o : right_now )
239
239
m = self .create_model_crontab (
@@ -286,7 +286,7 @@ def test_entry_is_due__celery_timezone_doesnt_match_time_zone(self):
286
286
287
287
# simulate last_run_at all none, doing the same thing that
288
288
# _default_now() would do
289
- right_now = datetime .utcnow ( )
289
+ right_now = datetime .now ( UTC )
290
290
291
291
m = self .create_model_crontab (
292
292
crontab (minute = '*/10' ),
@@ -1478,28 +1478,6 @@ def setup_method(self):
1478
1478
def teardown_method (self ):
1479
1479
patch .stopall ()
1480
1480
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
-
1503
1481
@patch ("django_celery_beat.schedulers.aware_now" )
1504
1482
def test_timezone_offset_with_zoneinfo_object_param (self , mock_aware_now ):
1505
1483
"""Test handling when timezone_name parameter is a ZoneInfo object."""
@@ -1519,3 +1497,4 @@ class MockScheduler:
1519
1497
1520
1498
# Tokyo is UTC+9, New York is UTC-5, so difference should be 14 hours
1521
1499
assert offset == 14
1500
+ assert mock_aware_now .called
0 commit comments