Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A unit Test to make sure ClockedSchedule and PeriodicTasks are shown in TimeZone format #485

Merged
merged 7 commits into from
Apr 11, 2022
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 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)