mirror of
https://github.com/django/django.git
synced 2025-09-26 20:19:16 +00:00
Merged regressiontests and modeltests into the test root.
This commit is contained in:
parent
b3d2ccb5bf
commit
89f40e3624
1050 changed files with 0 additions and 0 deletions
31
tests/model_inheritance_select_related/tests.py
Normal file
31
tests/model_inheritance_select_related/tests.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
from operator import attrgetter
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from .models import Restaurant, Person
|
||||
|
||||
|
||||
class ModelInheritanceSelectRelatedTests(TestCase):
|
||||
def test_inherited_select_related(self):
|
||||
# Regression test for #7246
|
||||
r1 = Restaurant.objects.create(
|
||||
name="Nobu", serves_sushi=True, serves_steak=False
|
||||
)
|
||||
r2 = Restaurant.objects.create(
|
||||
name="Craft", serves_sushi=False, serves_steak=True
|
||||
)
|
||||
p1 = Person.objects.create(name="John", favorite_restaurant=r1)
|
||||
p2 = Person.objects.create(name="Jane", favorite_restaurant=r2)
|
||||
|
||||
self.assertQuerysetEqual(
|
||||
Person.objects.order_by("name").select_related(), [
|
||||
"Jane",
|
||||
"John",
|
||||
],
|
||||
attrgetter("name")
|
||||
)
|
||||
|
||||
jane = Person.objects.order_by("name").select_related("favorite_restaurant")[0]
|
||||
self.assertEqual(jane.favorite_restaurant.name, "Craft")
|
Loading…
Add table
Add a link
Reference in a new issue