PageRenderTime 148ms CodeModel.GetById 139ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/modeltests/m2o_recursive/tests.py

https://code.google.com/p/mango-py/
Python | 38 lines | 32 code | 6 blank | 0 comment | 0 complexity | cc6a9cf527a61a9c5edc60efdb929c65 MD5 | raw file
 1from django.test import TestCase
 2from models import Category, Person
 3
 4class ManyToOneRecursiveTests(TestCase):
 5
 6    def setUp(self):
 7        self.r = Category(id=None, name='Root category', parent=None)
 8        self.r.save()
 9        self.c = Category(id=None, name='Child category', parent=self.r)
10        self.c.save()
11
12    def test_m2o_recursive(self):
13        self.assertQuerysetEqual(self.r.child_set.all(),
14                                 ['<Category: Child category>'])
15        self.assertEqual(self.r.child_set.get(name__startswith='Child').id, self.c.id)
16        self.assertEqual(self.r.parent, None)
17        self.assertQuerysetEqual(self.c.child_set.all(), [])
18        self.assertEqual(self.c.parent.id, self.r.id)
19
20class MultipleManyToOneRecursiveTests(TestCase):
21
22    def setUp(self):
23        self.dad = Person(full_name='John Smith Senior', mother=None, father=None)
24        self.dad.save()
25        self.mom = Person(full_name='Jane Smith', mother=None, father=None)
26        self.mom.save()
27        self.kid = Person(full_name='John Smith Junior', mother=self.mom, father=self.dad)
28        self.kid.save()
29
30    def test_m2o_recursive2(self):
31        self.assertEqual(self.kid.mother.id, self.mom.id)
32        self.assertEqual(self.kid.father.id, self.dad.id)
33        self.assertQuerysetEqual(self.dad.fathers_child_set.all(),
34                                 ['<Person: John Smith Junior>'])
35        self.assertQuerysetEqual(self.mom.mothers_child_set.all(),
36                                 ['<Person: John Smith Junior>'])
37        self.assertQuerysetEqual(self.kid.mothers_child_set.all(), [])
38        self.assertQuerysetEqual(self.kid.fathers_child_set.all(), [])