Skip to content

Commit

Permalink
Fix timezone issues
Browse files Browse the repository at this point in the history
  • Loading branch information
j4mie committed Apr 9, 2024
1 parent 705dc4b commit 8d88eb2
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions django_dbq/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
from io import StringIO


try:
utc = timezone.utc
except AttributeError:
from datetime import timezone as datetime_timezone
utc = datetime_timezone.utc


def test_task(job=None):
pass # pragma: no cover

Expand Down Expand Up @@ -189,7 +196,7 @@ def test_get_next_ready_job(self):
Job.objects.create(name="testjob", state=Job.STATES.READY)
Job.objects.create(name="testjob", state=Job.STATES.PROCESSING)
expected = Job.objects.create(name="testjob", state=Job.STATES.READY)
expected.created = datetime.now() - timedelta(minutes=1)
expected.created = timezone.now() - timedelta(minutes=1)
expected.save()

self.assertEqual(Job.objects.get_ready_or_none("default"), expected)
Expand Down Expand Up @@ -231,7 +238,7 @@ def test_gets_jobs_in_priority_and_date_order(self):

def test_ignores_jobs_until_run_after_is_in_the_past(self):
job_1 = Job.objects.create(name="testjob")
job_2 = Job.objects.create(name="testjob", run_after=datetime(2021, 11, 4, 8))
job_2 = Job.objects.create(name="testjob", run_after=datetime(2021, 11, 4, 8, tzinfo=utc))

with freezegun.freeze_time(datetime(2021, 11, 4, 7)):
self.assertEqual(
Expand All @@ -256,7 +263,7 @@ def test_get_next_ready_job_created(self):
Job.objects.create(name="testjob", state=Job.STATES.NEW)
Job.objects.create(name="testjob", state=Job.STATES.PROCESSING)
expected = Job.objects.create(name="testjob", state=Job.STATES.NEW)
expected.created = datetime.now() - timedelta(minutes=1)
expected.created = timezone.now() - timedelta(minutes=1)
expected.save()

self.assertEqual(Job.objects.get_ready_or_none("default"), expected)
Expand Down Expand Up @@ -336,7 +343,7 @@ def test_failure_hook(self):
@override_settings(JOBS={"testjob": {"tasks": ["a"]}})
class DeleteOldJobsTestCase(TestCase):
def test_delete_old_jobs(self):
two_days_ago = datetime.utcnow() - timedelta(days=2)
two_days_ago = timezone.now() - timedelta(days=2)

j1 = Job.objects.create(name="testjob", state=Job.STATES.COMPLETE)
j1.created = two_days_ago
Expand Down

0 comments on commit 8d88eb2

Please sign in to comment.