App Engine Python SDK version 1.7.4 (2)
[gae.git] / python / lib / django_1_4 / tests / modeltests / reserved_names / tests.py
blob87f7a42ec465a60bacc155faedcbddee5062f899
1 from __future__ import absolute_import
3 import datetime
5 from django.test import TestCase
7 from .models import Thing
10 class ReservedNameTests(TestCase):
11 def generate(self):
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):
31 self.generate()
32 things = [t.when for t in Thing.objects.order_by('when')]
33 self.assertEqual(things, ['a', 'h'])
35 def test_fields(self):
36 self.generate()
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))
41 def test_dates(self):
42 self.generate()
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):
50 self.generate()
51 self.assertEqual(Thing.objects.filter(where__month=1)[0].when, 'a')