summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2014-04-21 11:50:53 +0200
committerAymeric Augustin <aymeric.augustin@m4x.org>2014-04-21 11:51:21 +0200
commit0dad0ca55ec6081d3e92ac8340ed9f8d5c65a606 (patch)
tree4c82cdf3369069d93d13d58d3faa90893950d247
parentab0afef9590730064d40ca074c3b2be3baebf9cb (diff)
[1.7.x] Further consolidated the model_inheritance tests.
Backport of 3f01e82 from master
-rw-r--r--tests/model_inheritance_regress/models.py5
-rw-r--r--tests/model_inheritance_regress/tests.py22
-rw-r--r--tests/model_inheritance_select_related/__init__.py0
-rw-r--r--tests/model_inheritance_select_related/models.py37
-rw-r--r--tests/model_inheritance_select_related/tests.py31
5 files changed, 27 insertions, 68 deletions
diff --git a/tests/model_inheritance_regress/models.py b/tests/model_inheritance_regress/models.py
index cb0b2fe72f..48adf94ddf 100644
--- a/tests/model_inheritance_regress/models.py
+++ b/tests/model_inheritance_regress/models.py
@@ -73,9 +73,14 @@ class ParkingLot4B(Place, ParkingLot4):
pass
+@python_2_unicode_compatible
class Supplier(models.Model):
+ name = models.CharField(max_length=50)
restaurant = models.ForeignKey(Restaurant)
+ def __str__(self):
+ return self.name
+
class Wholesaler(Supplier):
retailer = models.ForeignKey(Supplier, related_name='wholesale_supplier')
diff --git a/tests/model_inheritance_regress/tests.py b/tests/model_inheritance_regress/tests.py
index 211877d7c6..5297898e2f 100644
--- a/tests/model_inheritance_regress/tests.py
+++ b/tests/model_inheritance_regress/tests.py
@@ -466,3 +466,25 @@ class ModelInheritanceTest(TestCase):
serves_pizza=True, serves_hot_dogs=True)
p = Place.objects.all().select_related('restaurant')[0]
self.assertIsInstance(p.restaurant.serves_pizza, bool)
+
+ def test_inheritance_select_related(self):
+ # Regression test for #7246
+ r1 = Restaurant.objects.create(
+ name="Nobu", serves_hot_dogs=True, serves_pizza=False
+ )
+ r2 = Restaurant.objects.create(
+ name="Craft", serves_hot_dogs=False, serves_pizza=True
+ )
+ Supplier.objects.create(name="John", restaurant=r1)
+ Supplier.objects.create(name="Jane", restaurant=r2)
+
+ self.assertQuerysetEqual(
+ Supplier.objects.order_by("name").select_related(), [
+ "Jane",
+ "John",
+ ],
+ attrgetter("name")
+ )
+
+ jane = Supplier.objects.order_by("name").select_related("restaurant")[0]
+ self.assertEqual(jane.restaurant.name, "Craft")
diff --git a/tests/model_inheritance_select_related/__init__.py b/tests/model_inheritance_select_related/__init__.py
deleted file mode 100644
index e69de29bb2..0000000000
--- a/tests/model_inheritance_select_related/__init__.py
+++ /dev/null
diff --git a/tests/model_inheritance_select_related/models.py b/tests/model_inheritance_select_related/models.py
deleted file mode 100644
index 81f267589c..0000000000
--- a/tests/model_inheritance_select_related/models.py
+++ /dev/null
@@ -1,37 +0,0 @@
-"""
-Regression tests for the interaction between model inheritance and
-select_related().
-"""
-from __future__ import unicode_literals
-
-from django.db import models
-from django.utils.encoding import python_2_unicode_compatible
-
-
-@python_2_unicode_compatible
-class Place(models.Model):
- name = models.CharField(max_length=50)
-
- class Meta:
- ordering = ('name',)
-
- def __str__(self):
- return "%s the place" % self.name
-
-
-@python_2_unicode_compatible
-class Restaurant(Place):
- serves_sushi = models.BooleanField(default=False)
- serves_steak = models.BooleanField(default=False)
-
- def __str__(self):
- return "%s the restaurant" % self.name
-
-
-@python_2_unicode_compatible
-class Person(models.Model):
- name = models.CharField(max_length=50)
- favorite_restaurant = models.ForeignKey(Restaurant)
-
- def __str__(self):
- return self.name
diff --git a/tests/model_inheritance_select_related/tests.py b/tests/model_inheritance_select_related/tests.py
deleted file mode 100644
index 195ccc80ec..0000000000
--- a/tests/model_inheritance_select_related/tests.py
+++ /dev/null
@@ -1,31 +0,0 @@
-from __future__ import unicode_literals
-
-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
- )
- Person.objects.create(name="John", favorite_restaurant=r1)
- 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")