Added test for errors when saving timezone-aware times if not supported.

This commit is contained in:
abhiabhi94 2021-07-01 18:49:09 +05:30 committed by Mariusz Felisiak
parent f35ab74752
commit 6a5ef557f8
2 changed files with 13 additions and 1 deletions

View File

@ -25,3 +25,7 @@ class Timestamp(models.Model):
class AllDayEvent(models.Model):
day = models.DateField()
class DailyEvent(models.Model):
time = models.TimeField()

View File

@ -37,7 +37,8 @@ from .forms import (
EventSplitForm,
)
from .models import (
AllDayEvent, Event, MaybeEvent, Session, SessionEvent, Timestamp,
AllDayEvent, DailyEvent, Event, MaybeEvent, Session, SessionEvent,
Timestamp,
)
try:
@ -270,6 +271,13 @@ class LegacyDatabaseTests(TestCase):
class NewDatabaseTests(TestCase):
naive_warning = 'DateTimeField Event.dt received a naive datetime'
@skipIfDBFeature('supports_timezones')
def test_aware_time_unsupported(self):
t = datetime.time(13, 20, 30, tzinfo=EAT)
msg = 'backend does not support timezone-aware times.'
with self.assertRaisesMessage(ValueError, msg):
DailyEvent.objects.create(time=t)
@requires_tz_support
def test_naive_datetime(self):
dt = datetime.datetime(2011, 9, 1, 13, 20, 30)