Skip to content

Commit 83996ed

Browse files
committed
Remove test
this tested for string timezones, which were not possible
1 parent d88ba8b commit 83996ed

File tree

1 file changed

+6
-30
lines changed

1 file changed

+6
-30
lines changed

t/unit/test_schedulers.py

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import math
22
import os
33
import time
4-
from datetime import datetime, timedelta
4+
from datetime import UTC, datetime, timedelta
55
from datetime import timezone as dt_timezone
66
from itertools import count
77
from time import monotonic
@@ -333,7 +333,7 @@ def test_entry_is_due__no_use_tz(self):
333333
assert self.app.timezone.key == 'Europe/Berlin'
334334

335335
# simulate last_run_at from DB - not TZ aware but localtime
336-
right_now = datetime.utcnow()
336+
right_now = datetime.now(UTC)
337337

338338
m = self.create_model_crontab(
339339
crontab(minute='*/10'),
@@ -364,7 +364,7 @@ def test_entry_and_model_last_run_at_with_utc_no_use_tz(self, monkeypatch):
364364
time.tzset()
365365
assert self.app.timezone.key == 'Europe/Berlin'
366366
# simulate last_run_at from DB - not TZ aware but localtime
367-
right_now = datetime.utcnow()
367+
right_now = datetime.now(UTC)
368368
# make sure to use fixed date time
369369
monkeypatch.setattr(self.Entry, '_default_now', lambda o: right_now)
370370
m = self.create_model_crontab(
@@ -398,7 +398,7 @@ def test_entry_and_model_last_run_at_when_model_changed(self, monkeypatch):
398398
time.tzset()
399399
assert self.app.timezone.key == 'Europe/Berlin'
400400
# simulate last_run_at from DB - not TZ aware but localtime
401-
right_now = datetime.utcnow()
401+
right_now = datetime.now(UTC)
402402
# make sure to use fixed date time
403403
monkeypatch.setattr(self.Entry, '_default_now', lambda o: right_now)
404404
m = self.create_model_crontab(
@@ -451,7 +451,7 @@ def test_entry_is_due__celery_timezone_doesnt_match_time_zone(self):
451451

452452
# simulate last_run_at all none, doing the same thing that
453453
# _default_now() would do
454-
right_now = datetime.utcnow()
454+
right_now = datetime.now(UTC)
455455

456456
m = self.create_model_crontab(
457457
crontab(minute='*/10'),
@@ -1678,31 +1678,6 @@ def setup_method(self):
16781678
def teardown_method(self):
16791679
patch.stopall()
16801680

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-
17061681
@patch("django_celery_beat.schedulers.aware_now")
17071682
def test_timezone_offset_with_zoneinfo_object_param(self, mock_aware_now):
17081683
"""Test handling when timezone_name parameter is a ZoneInfo object."""
@@ -1724,3 +1699,4 @@ class MockScheduler:
17241699

17251700
# Tokyo is UTC+9, New York is UTC-5, so difference should be 14 hours
17261701
assert offset == 14
1702+
assert mock_aware_now.called

0 commit comments

Comments
 (0)