PageRenderTime 142ms CodeModel.GetById 70ms app.highlight 9ms RepoModel.GetById 62ms app.codeStats 0ms

/tests/regressiontests/managers_regress/tests.py

https://code.google.com/p/mango-py/
Python | 54 lines | 45 code | 7 blank | 2 comment | 0 complexity | a93978cb9962a2f84838d3b8a51bcd40 MD5 | raw file
 1from django.test import TestCase
 2
 3from models import Child1, Child2, Child3, Child4, Child5, Child6, Child7
 4
 5
 6class ManagersRegressionTests(TestCase):
 7    def test_managers(self):
 8        a1 = Child1.objects.create(name='fred', data='a1')
 9        a2 = Child1.objects.create(name='barney', data='a2')
10        b1 = Child2.objects.create(name='fred', data='b1', value=1)
11        b2 = Child2.objects.create(name='barney', data='b2', value=42)
12        c1 = Child3.objects.create(name='fred', data='c1', comment='yes')
13        c2 = Child3.objects.create(name='barney', data='c2', comment='no')
14        d1 = Child4.objects.create(name='fred', data='d1')
15        d2 = Child4.objects.create(name='barney', data='d2')
16        e1 = Child5.objects.create(name='fred', comment='yes')
17        e2 = Child5.objects.create(name='barney', comment='no')
18        f1 = Child6.objects.create(name='fred', data='f1', value=42)
19        f2 = Child6.objects.create(name='barney', data='f2', value=42)
20        g1 = Child7.objects.create(name='fred')
21        g2 = Child7.objects.create(name='barney')
22
23        self.assertQuerysetEqual(Child1.manager1.all(), ["<Child1: a1>"])
24        self.assertQuerysetEqual(Child1.manager2.all(), ["<Child1: a2>"])
25        self.assertQuerysetEqual(Child1._default_manager.all(), ["<Child1: a1>"])
26
27        self.assertQuerysetEqual(Child2._default_manager.all(), ["<Child2: b1>"])
28        self.assertQuerysetEqual(Child2.restricted.all(), ["<Child2: b2>"])
29
30        self.assertQuerysetEqual(Child3._default_manager.all(), ["<Child3: c1>"])
31        self.assertQuerysetEqual(Child3.manager1.all(), ["<Child3: c1>"])
32        self.assertQuerysetEqual(Child3.manager2.all(), ["<Child3: c2>"])
33
34        # Since Child6 inherits from Child4, the corresponding rows from f1 and
35        # f2 also appear here. This is the expected result.
36        self.assertQuerysetEqual(Child4._default_manager.order_by('data'), [
37                "<Child4: d1>",
38                "<Child4: d2>",
39                "<Child4: f1>",
40                "<Child4: f2>"
41            ]
42        )
43        self.assertQuerysetEqual(Child4.manager1.all(), [
44                "<Child4: d1>",
45                "<Child4: f1>"
46            ]
47        )
48        self.assertQuerysetEqual(Child5._default_manager.all(), ["<Child5: fred>"])
49        self.assertQuerysetEqual(Child6._default_manager.all(), ["<Child6: f1>"])
50        self.assertQuerysetEqual(Child7._default_manager.order_by('name'), [
51                "<Child7: barney>",
52                "<Child7: fred>"
53            ]
54        )