From ceef628c192127d5e231613bc280d68dc0927fa3 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Tue, 12 Oct 2010 02:09:13 +0000 Subject: [PATCH] Converted model_inheritance_select_related tests from doctests to unittests. We have always been at war with doctests. git-svn-id: http://code.djangoproject.com/svn/django/trunk@14181 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- .../models.py | 18 ------------ .../model_inheritance_select_related/tests.py | 29 +++++++++++++++++++ 2 files changed, 29 insertions(+), 18 deletions(-) create mode 100644 tests/regressiontests/model_inheritance_select_related/tests.py diff --git a/tests/regressiontests/model_inheritance_select_related/models.py b/tests/regressiontests/model_inheritance_select_related/models.py index a97ecaadea..5851e467ce 100644 --- a/tests/regressiontests/model_inheritance_select_related/models.py +++ b/tests/regressiontests/model_inheritance_select_related/models.py @@ -27,21 +27,3 @@ class Person(models.Model): def __unicode__(self): return self.name - -__test__ = {'API_TESTS':""" -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) - ->>> Person.objects.order_by('name').select_related() -[, ] - ->>> jane = Person.objects.order_by('name').select_related('favorite_restaurant')[0] ->>> jane.favorite_restaurant.name -u'Craft' - -"""} - diff --git a/tests/regressiontests/model_inheritance_select_related/tests.py b/tests/regressiontests/model_inheritance_select_related/tests.py new file mode 100644 index 0000000000..e1ed609396 --- /dev/null +++ b/tests/regressiontests/model_inheritance_select_related/tests.py @@ -0,0 +1,29 @@ +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")