From 8687e135a3e211cd3dcdadbf14818062e430539c Mon Sep 17 00:00:00 2001 From: John Furr Date: Tue, 29 Apr 2014 07:25:17 -0400 Subject: [PATCH] Test that proxy models derived from PolyMorphicBase classes can call get_real_instance() and get_real_instance_class() Includes: def test_proxy_get_real_instance_class(self): --- polymorphic/tests.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/polymorphic/tests.py b/polymorphic/tests.py index 376f0f3..5032a85 100644 --- a/polymorphic/tests.py +++ b/polymorphic/tests.py @@ -223,6 +223,9 @@ class ProxyChild(ProxyBase): class Meta: proxy = True +class NonProxyChild(ProxyBase): + name=models.CharField(max_length=10) + # base -> proxy -> real models class ProxiedBase(ShowFieldTypeAndContent, PolymorphicModel): name = models.CharField(max_length=10) @@ -716,6 +719,24 @@ class PolymorphicTests(TestCase): self.assertIsInstance(items[0], ProxyChild) + def test_proxy_get_real_instance_class(self): + """ + Test that proxy models derived from PolyMorphicBase classes + can call get_real_instance() and get_real_instance_class() + """ + + name="Item1" + nonproxychild = NonProxyChild.objects.create(name=name) + + pb = ProxyBase.objects.get(id=1) + self.assertEqual(pb.get_real_instance_class(), NonProxyChild) + self.assertEqual(pb.get_real_instance(), nonproxychild) + self.assertEqual(pb.name, name) + + pbm = ProxyChild.objects.get(id=1) + self.assertEqual(pbm.get_real_instance_class(), NonProxyChild) + self.assertEqual(pbm.get_real_instance(), nonproxychild) + self.assertEqual(pbm.name, name) def test_content_types_for_proxy_models(self): """Checks if ContentType is capable of returning proxy models."""