Updated proxy model tests

Extracted classes from original proxy test.
Added another simple proxy model test.
Moved the test case to a seemingly better spot.
fix_request_path_info
floppya 2013-03-23 02:47:23 -06:00 committed by Diederik van der Boor
parent 20ac209dbb
commit 54cf2f37d8
1 changed files with 31 additions and 17 deletions

View File

@ -196,7 +196,6 @@ class Middle(Top):
class Bottom(Middle):
author = models.CharField(max_length=50)
class UUIDProject(ShowFieldTypeAndContent, PolymorphicModel):
uuid_primary_key = UUIDField(primary_key = True)
topic = models.CharField(max_length = 30)
@ -213,6 +212,13 @@ class UUIDPlainB(UUIDPlainA):
class UUIDPlainC(UUIDPlainB):
field3 = models.CharField(max_length=10)
# base -> proxy
class ProxyBase(PolymorphicModel):
some_data = models.CharField(max_length=128)
class ProxyChild(ProxyBase):
class Meta:
proxy = True
# base -> proxy -> real models
class ProxiedBase(ShowFieldTypeAndContent, PolymorphicModel):
name = models.CharField(max_length=10)
@ -686,6 +692,30 @@ class PolymorphicTests(TestCase):
self.assertIs(type(parent.childmodel_set.my_queryset_foo()), MyManagerQuerySet)
def test_proxy_models(self):
# prepare some data
for data in ('bleep bloop', 'I am a', 'computer'):
ProxyChild.objects.create(some_data=data)
# this caches ContentType queries so they don't interfere with our query counts later
list(ProxyBase.objects.all())
# one query per concrete class
with self.assertNumQueries(1):
items = list(ProxyBase.objects.all())
self.assertIsInstance(items[0], ProxyChild)
def test_content_types_for_proxy_models(self):
"""Checks if ContentType is capable of returning proxy models."""
from django.db.models import Model
from django.contrib.contenttypes.models import ContentType
ct = ContentType.objects.get_for_model(ProxyChild, for_concrete_model=False)
self.assertEqual(ProxyChild, ct.model_class())
def test_proxy_model_inheritance(self):
"""
Polymorphic abilities should also work when the base model is a proxy object.
@ -749,19 +779,3 @@ class RegressionTests(TestCase):
expected_queryset = [bottom]
self.assertQuerysetEqual(Bottom.objects.all(), [repr(r) for r in expected_queryset])
class ProxiedModelTests(TestCase):
def test_content_types_for_proxy_models(self):
from django.db.models import Model
from django.contrib.contenttypes.models import ContentType
class Base(Model):
pass
class Proxy(Base):
class Meta:
proxy = True
ct = ContentType.objects.get_for_model(Proxy, for_concrete_model=False)
self.assertEqual(Proxy, ct.model_class())