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 __future__ import absolute_import, unicode_literals
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.core import management
|
from django.core import management
|
||||||
from django.core.exceptions import FieldError
|
from django.core.exceptions import FieldError
|
||||||
|
@ -13,6 +14,7 @@ from .models import (MyPerson, Person, StatusPerson, LowerStatusPerson,
|
||||||
Country, State, StateProxy, TrackerUser, BaseUser, Bug, ProxyTrackerUser,
|
Country, State, StateProxy, TrackerUser, BaseUser, Bug, ProxyTrackerUser,
|
||||||
Improvement, ProxyProxyBug, ProxyBug, ProxyImprovement)
|
Improvement, ProxyProxyBug, ProxyBug, ProxyImprovement)
|
||||||
|
|
||||||
|
|
||||||
class ProxyModelTests(TestCase):
|
class ProxyModelTests(TestCase):
|
||||||
def test_same_manager_queries(self):
|
def test_same_manager_queries(self):
|
||||||
"""
|
"""
|
||||||
|
@ -91,7 +93,7 @@ class ProxyModelTests(TestCase):
|
||||||
)
|
)
|
||||||
self.assertRaises(Person.MultipleObjectsReturned,
|
self.assertRaises(Person.MultipleObjectsReturned,
|
||||||
MyPersonProxy.objects.get,
|
MyPersonProxy.objects.get,
|
||||||
id__lt=max_id+1
|
id__lt=max_id + 1
|
||||||
)
|
)
|
||||||
self.assertRaises(Person.DoesNotExist,
|
self.assertRaises(Person.DoesNotExist,
|
||||||
StatusPerson.objects.get,
|
StatusPerson.objects.get,
|
||||||
|
@ -104,7 +106,7 @@ class ProxyModelTests(TestCase):
|
||||||
|
|
||||||
self.assertRaises(Person.MultipleObjectsReturned,
|
self.assertRaises(Person.MultipleObjectsReturned,
|
||||||
StatusPerson.objects.get,
|
StatusPerson.objects.get,
|
||||||
id__lt=max_id+1
|
id__lt=max_id + 1
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_abc(self):
|
def test_abc(self):
|
||||||
|
@ -138,10 +140,32 @@ class ProxyModelTests(TestCase):
|
||||||
def build_new_fields():
|
def build_new_fields():
|
||||||
class NoNewFields(Person):
|
class NoNewFields(Person):
|
||||||
newfield = models.BooleanField()
|
newfield = models.BooleanField()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
proxy = True
|
proxy = True
|
||||||
self.assertRaises(FieldError, build_new_fields)
|
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):
|
def test_myperson_manager(self):
|
||||||
Person.objects.create(name="fred")
|
Person.objects.create(name="fred")
|
||||||
Person.objects.create(name="wilma")
|
Person.objects.create(name="wilma")
|
||||||
|
|
Loading…
Reference in New Issue