Skip to content

Commit 01078eb

Browse files
committed
Add tests
1 parent e003166 commit 01078eb

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

t/unit/backends/test_database.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,26 @@ def test_custom_state(self):
968968
assert self.b.get_status(tid) == states.SUCCESS
969969
assert self.b.get_result(tid) == 42
970970

971+
def test_date_started_is_timezone_aware(self):
972+
"""Test that date_started is timezone-aware when task is started"""
973+
tid = uuid()
974+
975+
# Create a task in PENDING state
976+
self.b.store_result(tid, None, states.PENDING)
977+
tr = TaskResult.objects.get(task_id=tid)
978+
assert tr.date_started is None
979+
980+
# Mark as started
981+
self.b.mark_as_started(tid)
982+
983+
# Verify date_started is set and timezone-aware
984+
tr = TaskResult.objects.get(task_id=tid)
985+
assert tr.date_started is not None
986+
assert isinstance(tr.date_started, datetime.datetime)
987+
# Check if datetime is timezone-aware (has tzinfo set)
988+
assert tr.date_started.tzinfo is not None
989+
assert tr.date_started.tzinfo.utcoffset(tr.date_started) is not None
990+
971991

972992
class DjangoCeleryResultRouter:
973993
route_app_labels = {"django_celery_results"}

0 commit comments

Comments
 (0)