PageRenderTime 273ms CodeModel.GetById 100ms app.highlight 81ms RepoModel.GetById 90ms app.codeStats 0ms

/tests/modeltests/reserved_names/tests.py

https://code.google.com/p/mango-py/
Python | 48 lines | 39 code | 9 blank | 0 comment | 2 complexity | 38964158de9486f3ecbbd9721d68e63c MD5 | raw file
 1import datetime
 2
 3from django.test import TestCase
 4
 5from models import Thing
 6
 7class ReservedNameTests(TestCase):
 8    def generate(self):
 9        day1 = datetime.date(2005, 1, 1)
10        t = Thing.objects.create(when='a', join='b', like='c', drop='d',
11            alter='e', having='f', where=day1, has_hyphen='h')
12        day2 = datetime.date(2006, 2, 2)
13        u = Thing.objects.create(when='h', join='i', like='j', drop='k',
14            alter='l', having='m', where=day2)
15
16    def test_simple(self):
17        day1 = datetime.date(2005, 1, 1)
18        t = Thing.objects.create(when='a', join='b', like='c', drop='d',
19            alter='e', having='f', where=day1, has_hyphen='h')
20        self.assertEqual(t.when, 'a')
21
22        day2 = datetime.date(2006, 2, 2)
23        u = Thing.objects.create(when='h', join='i', like='j', drop='k',
24            alter='l', having='m', where=day2)
25        self.assertEqual(u.when, 'h')
26
27    def test_order_by(self):
28        self.generate()
29        things = [t.when for t in Thing.objects.order_by('when')]
30        self.assertEqual(things, ['a', 'h'])
31
32    def test_fields(self):
33        self.generate()
34        v = Thing.objects.get(pk='a')
35        self.assertEqual(v.join, 'b')
36        self.assertEqual(v.where, datetime.date(year=2005, month=1, day=1))
37
38    def test_dates(self):
39        self.generate()
40        resp = Thing.objects.dates('where', 'year')
41        self.assertEqual(list(resp), [
42            datetime.datetime(2005, 1, 1, 0, 0),
43            datetime.datetime(2006, 1, 1, 0, 0),
44        ])
45
46    def test_month_filter(self):
47        self.generate()
48        self.assertEqual(Thing.objects.filter(where__month=1)[0].when, 'a')