diff options
Diffstat (limited to 'tests/model_inheritance/tests.py')
-rw-r--r-- | tests/model_inheritance/tests.py | 72 |
1 files changed, 30 insertions, 42 deletions
diff --git a/tests/model_inheritance/tests.py b/tests/model_inheritance/tests.py index d47ad08680..7362c446ba 100644 --- a/tests/model_inheritance/tests.py +++ b/tests/model_inheritance/tests.py @@ -3,14 +3,13 @@ from __future__ import unicode_literals from operator import attrgetter from django.core.exceptions import FieldError, ValidationError -from django.core.management import call_command from django.db import connection, models -from django.test import TestCase, TransactionTestCase +from django.test import SimpleTestCase, TestCase from django.test.utils import CaptureQueriesContext, isolate_apps from django.utils import six from .models import ( - Base, Chef, CommonInfo, Copy, GrandChild, GrandParent, ItalianRestaurant, + Base, Chef, CommonInfo, GrandChild, GrandParent, ItalianRestaurant, MixinModel, ParkingLot, Place, Post, Restaurant, Student, SubBase, Supplier, Title, Worker, ) @@ -399,48 +398,37 @@ class ModelInheritanceDataTests(TestCase): ) -class InheritanceSameModelNameTests(TransactionTestCase): +@isolate_apps('model_inheritance', 'model_inheritance.tests') +class InheritanceSameModelNameTests(SimpleTestCase): + def test_abstract_fk_related_name(self): + related_name = '%(app_label)s_%(class)s_references' - available_apps = ['model_inheritance'] + class Referenced(models.Model): + class Meta: + app_label = 'model_inheritance' - def setUp(self): - # The Title model has distinct accessors for both - # model_inheritance.Copy and model_inheritance_same_model_name.Copy - # models. - self.title = Title.objects.create(title='Lorem Ipsum') + class AbstractReferent(models.Model): + reference = models.ForeignKey(Referenced, models.CASCADE, related_name=related_name) - def test_inheritance_related_name(self): - self.assertEqual( - self.title.attached_model_inheritance_copy_set.create( - content='Save $ on V1agr@', - url='http://v1agra.com/', - title='V1agra is spam', - ), Copy.objects.get( - content='Save $ on V1agr@', - )) - - def test_inheritance_with_same_model_name(self): - with self.modify_settings( - INSTALLED_APPS={'append': ['model_inheritance.same_model_name']}): - call_command('migrate', verbosity=0, run_syncdb=True) - from .same_model_name.models import Copy - copy = self.title.attached_same_model_name_copy_set.create( - content='The Web framework for perfectionists with deadlines.', - url='http://www.djangoproject.com/', - title='Django Rocks' - ) - self.assertEqual( - copy, - Copy.objects.get( - content='The Web framework for perfectionists with deadlines.', - )) - # We delete the copy manually so that it doesn't block the flush - # command under Oracle (which does not cascade deletions). - copy.delete() - - def test_related_name_attribute_exists(self): - # The Post model doesn't have an attribute called 'attached_%(app_label)s_%(class)s_set'. - self.assertFalse(hasattr(self.title, 'attached_%(app_label)s_%(class)s_set')) + class Meta: + app_label = 'model_inheritance' + abstract = True + + class Referent(AbstractReferent): + class Meta: + app_label = 'model_inheritance' + + LocalReferent = Referent + + class Referent(AbstractReferent): + class Meta: + app_label = 'tests' + + ForeignReferent = Referent + + self.assertFalse(hasattr(Referenced, related_name)) + self.assertTrue(Referenced.model_inheritance_referent_references.rel.model, LocalReferent) + self.assertTrue(Referenced.tests_referent_references.rel.model, ForeignReferent) class InheritanceUniqueTests(TestCase): |