Added test for proxy model safeguards on swappable models.

This commit is contained in:
Russell Keith-Magee 2012-09-16 20:12:34 +08:00
parent 280bf19e94
commit 913e1ac84c
1 changed files with 26 additions and 2 deletions

View File

@ -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):
"""
@ -91,7 +93,7 @@ class ProxyModelTests(TestCase):
)
self.assertRaises(Person.MultipleObjectsReturned,
MyPersonProxy.objects.get,
id__lt=max_id+1
id__lt=max_id + 1
)
self.assertRaises(Person.DoesNotExist,
StatusPerson.objects.get,
@ -104,7 +106,7 @@ class ProxyModelTests(TestCase):
self.assertRaises(Person.MultipleObjectsReturned,
StatusPerson.objects.get,
id__lt=max_id+1
id__lt=max_id + 1
)
def test_abc(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")