mirror of
https://github.com/django/django.git
synced 2024-12-23 01:25:58 +00:00
Fixed #22402 -- Consolidated model_inheritance tests.
The model_inheritance_same_model_name tests couldn't be run without the model_inheritance tests. Make the problem go away by merging them. Thanks timo for the report.
This commit is contained in:
parent
471fb04a30
commit
3f76339355
@ -1,9 +1,8 @@
|
||||
"""
|
||||
XX. Model inheritance
|
||||
|
||||
Model inheritance across apps can result in models with the same name resulting
|
||||
in the need for an %(app_label)s format string. This app specifically tests
|
||||
this feature by redefining the Copy model from model_inheritance/models.py
|
||||
Model inheritance across apps can result in models with the same name,
|
||||
requiring an %(app_label)s format string. This app tests this feature by
|
||||
redefining the Copy model from model_inheritance/models.py.
|
||||
"""
|
||||
|
||||
from django.db import models
|
||||
@ -12,9 +11,6 @@ from model_inheritance.models import NamedURL
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
|
||||
|
||||
#
|
||||
# Abstract base classes with related models
|
||||
#
|
||||
@python_2_unicode_compatible
|
||||
class Copy(NamedURL):
|
||||
content = models.TextField()
|
@ -3,15 +3,16 @@ from __future__ import unicode_literals
|
||||
from operator import attrgetter
|
||||
|
||||
from django.core.exceptions import FieldError
|
||||
from django.core.management import call_command
|
||||
from django.db import connection
|
||||
from django.test import TestCase
|
||||
from django.test.utils import CaptureQueriesContext
|
||||
from django.test.utils import CaptureQueriesContext, override_settings
|
||||
from django.utils import six
|
||||
|
||||
from .models import (
|
||||
Chef, CommonInfo, ItalianRestaurant, ParkingLot, Place, Post,
|
||||
Restaurant, Student, Supplier, Worker, MixinModel,
|
||||
Title, Base, SubBase)
|
||||
Title, Copy, Base, SubBase)
|
||||
|
||||
|
||||
class ModelInheritanceTests(TestCase):
|
||||
@ -339,3 +340,40 @@ class ModelInheritanceTests(TestCase):
|
||||
# accidentally found).
|
||||
self.assertQuerysetEqual(
|
||||
s.titles.all(), [])
|
||||
|
||||
|
||||
class InheritanceSameModelNameTests(TestCase):
|
||||
|
||||
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')
|
||||
|
||||
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)
|
||||
from .same_model_name.models import Copy
|
||||
self.assertEqual(
|
||||
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'
|
||||
), Copy.objects.get(
|
||||
content='The Web framework for perfectionists with deadlines.',
|
||||
))
|
||||
|
||||
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'))
|
||||
|
@ -1,36 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from model_inheritance.models import Title
|
||||
|
||||
|
||||
class InheritanceSameModelNameTests(TestCase):
|
||||
|
||||
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')
|
||||
|
||||
def test_inheritance_related_name(self):
|
||||
from model_inheritance.models import Copy
|
||||
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):
|
||||
from model_inheritance_same_model_name.models import Copy
|
||||
self.assertEqual(
|
||||
self.title.attached_model_inheritance_same_model_name_copy_set.create(
|
||||
content='The Web framework for perfectionists with deadlines.',
|
||||
url='http://www.djangoproject.com/',
|
||||
title='Django Rocks'
|
||||
), Copy.objects.get(content='The Web framework for perfectionists with deadlines.'))
|
||||
|
||||
def test_related_name_attribute_exists(self):
|
||||
# The Post model doesn't have an attribute called 'attached_%(app_label)s_%(class)s_set'.
|
||||
self.assertEqual(hasattr(self.title, 'attached_%(app_label)s_%(class)s_set'), False)
|
Loading…
Reference in New Issue
Block a user