2015-05-23 03:16:26 +08:00
|
|
|
from django.test import TestCase
|
|
|
|
|
|
|
|
from .models import Alarm
|
|
|
|
|
|
|
|
|
|
|
|
class TimeFieldLookupTests(TestCase):
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setUpTestData(self):
|
|
|
|
# Create a few Alarms
|
|
|
|
self.al1 = Alarm.objects.create(desc='Early', time='05:30')
|
|
|
|
self.al2 = Alarm.objects.create(desc='Late', time='10:00')
|
|
|
|
self.al3 = Alarm.objects.create(desc='Precise', time='12:34:56')
|
|
|
|
|
|
|
|
def test_hour_lookups(self):
|
2020-10-19 00:29:52 +08:00
|
|
|
self.assertSequenceEqual(
|
2015-05-23 03:16:26 +08:00
|
|
|
Alarm.objects.filter(time__hour=5),
|
2020-10-19 00:29:52 +08:00
|
|
|
[self.al1],
|
2015-05-23 03:16:26 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_minute_lookups(self):
|
2020-10-19 00:29:52 +08:00
|
|
|
self.assertSequenceEqual(
|
2015-05-23 03:16:26 +08:00
|
|
|
Alarm.objects.filter(time__minute=30),
|
2020-10-19 00:29:52 +08:00
|
|
|
[self.al1],
|
2015-05-23 03:16:26 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_second_lookups(self):
|
2020-10-19 00:29:52 +08:00
|
|
|
self.assertSequenceEqual(
|
2015-05-23 03:16:26 +08:00
|
|
|
Alarm.objects.filter(time__second=56),
|
2020-10-19 00:29:52 +08:00
|
|
|
[self.al3],
|
2015-05-23 03:16:26 +08:00
|
|
|
)
|