PageRenderTime 37ms CodeModel.GetById 22ms RepoModel.GetById 0ms 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
Possible License(s): BSD-3-Clause
  1. from django.test import TestCase
  2. from models import Category, Person
  3. class ManyToOneRecursiveTests(TestCase):
  4. def setUp(self):
  5. self.r = Category(id=None, name='Root category', parent=None)
  6. self.r.save()
  7. self.c = Category(id=None, name='Child category', parent=self.r)
  8. self.c.save()
  9. def test_m2o_recursive(self):
  10. self.assertQuerysetEqual(self.r.child_set.all(),
  11. ['<Category: Child category>'])
  12. self.assertEqual(self.r.child_set.get(name__startswith='Child').id, self.c.id)
  13. self.assertEqual(self.r.parent, None)
  14. self.assertQuerysetEqual(self.c.child_set.all(), [])
  15. self.assertEqual(self.c.parent.id, self.r.id)
  16. class MultipleManyToOneRecursiveTests(TestCase):
  17. def setUp(self):
  18. self.dad = Person(full_name='John Smith Senior', mother=None, father=None)
  19. self.dad.save()
  20. self.mom = Person(full_name='Jane Smith', mother=None, father=None)
  21. self.mom.save()
  22. self.kid = Person(full_name='John Smith Junior', mother=self.mom, father=self.dad)
  23. self.kid.save()
  24. def test_m2o_recursive2(self):
  25. self.assertEqual(self.kid.mother.id, self.mom.id)
  26. self.assertEqual(self.kid.father.id, self.dad.id)
  27. self.assertQuerysetEqual(self.dad.fathers_child_set.all(),
  28. ['<Person: John Smith Junior>'])
  29. self.assertQuerysetEqual(self.mom.mothers_child_set.all(),
  30. ['<Person: John Smith Junior>'])
  31. self.assertQuerysetEqual(self.kid.mothers_child_set.all(), [])
  32. self.assertQuerysetEqual(self.kid.fathers_child_set.all(), [])