Skip to content

Commit

Permalink
A unit test to make sure ClockedSchedule and PeriodicTasks are not sh…
Browse files Browse the repository at this point in the history
…owing UTC time when Time Zone is used
  • Loading branch information
Mohamed Hamdy committed Dec 19, 2021
1 parent be7901b commit d094414
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion t/unit/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from django.db.migrations.loader import MigrationLoader
from django.db.migrations.questioner import NonInteractiveMigrationQuestioner
from django.utils import timezone

from django.conf import settings
import pytz, datetime
import timezone_field

from django_celery_beat import migrations as beat_migrations
Expand Down Expand Up @@ -146,3 +147,12 @@ class ClockedScheduleTestCase(TestCase, TestDuplicatesMixin):
def test_duplicate_schedules(self):
kwargs = {'clocked_time': timezone.now()}
self._test_duplicate_schedules(ClockedSchedule, kwargs)

# IMPORTANT: we must have a valid the time-zone (not UTC) to do an accurate testing
@override_settings(TIME_ZONE='Africa/Cairo')
def test_timezone_format(self):
"""Make sure the scheduled time is not shown in UTC when time zone is used"""
tz_info = pytz.timezone(settings.TIME_ZONE).localize(datetime.datetime.utcnow())
schedule, created = ClockedSchedule.objects.get_or_create(clocked_time=tz_info)
# testnig str(schedule) calls make_aware() internally
assert str(schedule.clocked_time) == str(schedule)

0 comments on commit d094414

Please sign in to comment.