1 from __future__
import absolute_import
5 from django
.test
import TestCase
7 from .models
import Thing
10 class ReservedNameTests(TestCase
):
12 day1
= datetime
.date(2005, 1, 1)
13 t
= Thing
.objects
.create(when
='a', join
='b', like
='c', drop
='d',
14 alter
='e', having
='f', where
=day1
, has_hyphen
='h')
15 day2
= datetime
.date(2006, 2, 2)
16 u
= Thing
.objects
.create(when
='h', join
='i', like
='j', drop
='k',
17 alter
='l', having
='m', where
=day2
)
19 def test_simple(self
):
20 day1
= datetime
.date(2005, 1, 1)
21 t
= Thing
.objects
.create(when
='a', join
='b', like
='c', drop
='d',
22 alter
='e', having
='f', where
=day1
, has_hyphen
='h')
23 self
.assertEqual(t
.when
, 'a')
25 day2
= datetime
.date(2006, 2, 2)
26 u
= Thing
.objects
.create(when
='h', join
='i', like
='j', drop
='k',
27 alter
='l', having
='m', where
=day2
)
28 self
.assertEqual(u
.when
, 'h')
30 def test_order_by(self
):
32 things
= [t
.when
for t
in Thing
.objects
.order_by('when')]
33 self
.assertEqual(things
, ['a', 'h'])
35 def test_fields(self
):
37 v
= Thing
.objects
.get(pk
='a')
38 self
.assertEqual(v
.join
, 'b')
39 self
.assertEqual(v
.where
, datetime
.date(year
=2005, month
=1, day
=1))
43 resp
= Thing
.objects
.dates('where', 'year')
44 self
.assertEqual(list(resp
), [
45 datetime
.datetime(2005, 1, 1, 0, 0),
46 datetime
.datetime(2006, 1, 1, 0, 0),
49 def test_month_filter(self
):
51 self
.assertEqual(Thing
.objects
.filter(where__month
=1)[0].when
, 'a')