Kaydet (Commit) d02e3314 authored tarafından Simon Charette's avatar Simon Charette

Avoided uncessary table creation in model_inheritance tests.

üst 53a5fb3c
...@@ -168,14 +168,6 @@ class NamedURL(models.Model): ...@@ -168,14 +168,6 @@ class NamedURL(models.Model):
abstract = True abstract = True
@python_2_unicode_compatible
class Copy(NamedURL):
content = models.TextField()
def __str__(self):
return self.content
class Mixin(object): class Mixin(object):
def __init__(self): def __init__(self):
self.other_attr = 1 self.other_attr = 1
......
"""
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 model_inheritance.models import NamedURL
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
@python_2_unicode_compatible
class Copy(NamedURL):
content = models.TextField()
def __str__(self):
return self.content
...@@ -3,14 +3,13 @@ from __future__ import unicode_literals ...@@ -3,14 +3,13 @@ from __future__ import unicode_literals
from operator import attrgetter from operator import attrgetter
from django.core.exceptions import FieldError, ValidationError from django.core.exceptions import FieldError, ValidationError
from django.core.management import call_command
from django.db import connection, models 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.test.utils import CaptureQueriesContext, isolate_apps
from django.utils import six from django.utils import six
from .models import ( from .models import (
Base, Chef, CommonInfo, Copy, GrandChild, GrandParent, ItalianRestaurant, Base, Chef, CommonInfo, GrandChild, GrandParent, ItalianRestaurant,
MixinModel, ParkingLot, Place, Post, Restaurant, Student, SubBase, MixinModel, ParkingLot, Place, Post, Restaurant, Student, SubBase,
Supplier, Title, Worker, Supplier, Title, Worker,
) )
...@@ -399,48 +398,37 @@ class ModelInheritanceDataTests(TestCase): ...@@ -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): class AbstractReferent(models.Model):
# The Title model has distinct accessors for both reference = models.ForeignKey(Referenced, models.CASCADE, related_name=related_name)
# 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): class Meta:
self.assertEqual( app_label = 'model_inheritance'
self.title.attached_model_inheritance_copy_set.create( abstract = True
content='Save $ on V1agr@',
url='http://v1agra.com/', class Referent(AbstractReferent):
title='V1agra is spam', class Meta:
), Copy.objects.get( app_label = 'model_inheritance'
content='Save $ on V1agr@',
)) LocalReferent = Referent
def test_inheritance_with_same_model_name(self): class Referent(AbstractReferent):
with self.modify_settings( class Meta:
INSTALLED_APPS={'append': ['model_inheritance.same_model_name']}): app_label = 'tests'
call_command('migrate', verbosity=0, run_syncdb=True)
from .same_model_name.models import Copy ForeignReferent = Referent
copy = self.title.attached_same_model_name_copy_set.create(
content='The Web framework for perfectionists with deadlines.', self.assertFalse(hasattr(Referenced, related_name))
url='http://www.djangoproject.com/', self.assertTrue(Referenced.model_inheritance_referent_references.rel.model, LocalReferent)
title='Django Rocks' self.assertTrue(Referenced.tests_referent_references.rel.model, ForeignReferent)
)
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 InheritanceUniqueTests(TestCase): class InheritanceUniqueTests(TestCase):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment