~ubuntuone-pqm-team/django/stable

« back to all changes in this revision

Viewing changes to tests/modeltests/m2o_recursive/tests.py

  • Committer: Natalia
  • Date: 2014-12-05 15:21:13 UTC
  • Revision ID: natalia.bidart@ubuntu.com-20141205152113-cchtmygjia45gb87
Tags: 1.6.8
- Imported Django 1.6.8 from released tarball.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from __future__ import absolute_import
2
 
 
3
 
from django.test import TestCase
4
 
 
5
 
from .models import Category, Person
6
 
 
7
 
 
8
 
class ManyToOneRecursiveTests(TestCase):
9
 
 
10
 
    def setUp(self):
11
 
        self.r = Category(id=None, name='Root category', parent=None)
12
 
        self.r.save()
13
 
        self.c = Category(id=None, name='Child category', parent=self.r)
14
 
        self.c.save()
15
 
 
16
 
    def test_m2o_recursive(self):
17
 
        self.assertQuerysetEqual(self.r.child_set.all(),
18
 
                                 ['<Category: Child category>'])
19
 
        self.assertEqual(self.r.child_set.get(name__startswith='Child').id, self.c.id)
20
 
        self.assertEqual(self.r.parent, None)
21
 
        self.assertQuerysetEqual(self.c.child_set.all(), [])
22
 
        self.assertEqual(self.c.parent.id, self.r.id)
23
 
 
24
 
class MultipleManyToOneRecursiveTests(TestCase):
25
 
 
26
 
    def setUp(self):
27
 
        self.dad = Person(full_name='John Smith Senior', mother=None, father=None)
28
 
        self.dad.save()
29
 
        self.mom = Person(full_name='Jane Smith', mother=None, father=None)
30
 
        self.mom.save()
31
 
        self.kid = Person(full_name='John Smith Junior', mother=self.mom, father=self.dad)
32
 
        self.kid.save()
33
 
 
34
 
    def test_m2o_recursive2(self):
35
 
        self.assertEqual(self.kid.mother.id, self.mom.id)
36
 
        self.assertEqual(self.kid.father.id, self.dad.id)
37
 
        self.assertQuerysetEqual(self.dad.fathers_child_set.all(),
38
 
                                 ['<Person: John Smith Junior>'])
39
 
        self.assertQuerysetEqual(self.mom.mothers_child_set.all(),
40
 
                                 ['<Person: John Smith Junior>'])
41
 
        self.assertQuerysetEqual(self.kid.mothers_child_set.all(), [])
42
 
        self.assertQuerysetEqual(self.kid.fathers_child_set.all(), [])