Added test for proxy model safeguards on swappable models.
This commit is contained in:
parent
280bf19e94
commit
913e1ac84c
|
@ -1,5 +1,6 @@
|
|||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core import management
|
||||
from django.core.exceptions import FieldError
|
||||
|
@ -13,6 +14,7 @@ from .models import (MyPerson, Person, StatusPerson, LowerStatusPerson,
|
|||
Country, State, StateProxy, TrackerUser, BaseUser, Bug, ProxyTrackerUser,
|
||||
Improvement, ProxyProxyBug, ProxyBug, ProxyImprovement)
|
||||
|
||||
|
||||
class ProxyModelTests(TestCase):
|
||||
def test_same_manager_queries(self):
|
||||
"""
|
||||
|
@ -138,10 +140,32 @@ class ProxyModelTests(TestCase):
|
|||
def build_new_fields():
|
||||
class NoNewFields(Person):
|
||||
newfield = models.BooleanField()
|
||||
|
||||
class Meta:
|
||||
proxy = True
|
||||
self.assertRaises(FieldError, build_new_fields)
|
||||
|
||||
def test_swappable(self):
|
||||
try:
|
||||
settings.TEST_SWAPPABLE_MODEL = 'proxy_models.AlternateModel'
|
||||
|
||||
class SwappableModel(models.Model):
|
||||
|
||||
class Meta:
|
||||
swappable = 'TEST_SWAPPABLE_MODEL'
|
||||
|
||||
class AlternateModel(models.Model):
|
||||
pass
|
||||
|
||||
# You can't proxy a swapped model
|
||||
with self.assertRaises(TypeError):
|
||||
class ProxyModel(SwappableModel):
|
||||
|
||||
class Meta:
|
||||
proxy = True
|
||||
finally:
|
||||
del settings.TEST_SWAPPABLE_MODEL
|
||||
|
||||
def test_myperson_manager(self):
|
||||
Person.objects.create(name="fred")
|
||||
Person.objects.create(name="wilma")
|
||||
|
|
Loading…
Reference in New Issue