PageRenderTime 28ms CodeModel.GetById 22ms RepoModel.GetById 2ms app.codeStats 0ms

/tests/regressiontests/model_inheritance_select_related/tests.py

https://code.google.com/p/mango-py/
Python | 29 lines | 22 code | 6 blank | 1 comment | 0 complexity | 6e27bbfeb75997fa043cecf907795803 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. from operator import attrgetter
  2. from django.test import TestCase
  3. from models import Restaurant, Person
  4. class ModelInheritanceSelectRelatedTests(TestCase):
  5. def test_inherited_select_related(self):
  6. # Regression test for #7246
  7. r1 = Restaurant.objects.create(
  8. name="Nobu", serves_sushi=True, serves_steak=False
  9. )
  10. r2 = Restaurant.objects.create(
  11. name="Craft", serves_sushi=False, serves_steak=True
  12. )
  13. p1 = Person.objects.create(name="John", favorite_restaurant=r1)
  14. p2 = Person.objects.create(name="Jane", favorite_restaurant=r2)
  15. self.assertQuerysetEqual(
  16. Person.objects.order_by("name").select_related(), [
  17. "Jane",
  18. "John",
  19. ],
  20. attrgetter("name")
  21. )
  22. jane = Person.objects.order_by("name").select_related("favorite_restaurant")[0]
  23. self.assertEqual(jane.favorite_restaurant.name, "Craft")