Permalink
Browse files

Ticket #4102 - Add tests for proxied models.

  • Loading branch information...
1 parent 5671df4 commit b748b33ecb99bcc0a627f3af525b943e0ef97dab @niwinz committed May 1, 2012
@@ -1,3 +0,0 @@
-# -*- coding: utf-8 -*-
-
-
@@ -24,3 +24,8 @@ class Profile(models.Model):
def __unicode__(self):
return self.name
+
+
+class ProxyEmployee(Employee):
+ class Meta:
+ proxy = True
@@ -2,7 +2,7 @@
from django.test import TestCase
from django.db.models.signals import pre_save, post_save
-from .models import Person, Employee, Profile
+from .models import Person, Employee, ProxyEmployee, Profile
class UpdateOnlyFieldsTests(TestCase):
def test_update_fields_basic(self):
@@ -41,6 +41,30 @@ def test_update_fields_inheritance(self):
self.assertEqual(e3.name, 'Ian')
self.assertEqual(e3.profile, profile_receptionist)
+ def test_update_fields_inheritance_with_proxy_model(self):
+ profile_boss = Profile.objects.create(name='Boss', salary=3000)
+ profile_receptionist = Profile.objects.create(name='Receptionist', salary=1000)
+
+ e1 = ProxyEmployee.objects.create(name='Sara', gender='F',
+ employee_num=1, profile=profile_boss)
+
+ e1.name = 'Ian'
+ e1.gender = 'M'
+ e1.save(update_fields=['name'])
+
+ e2 = ProxyEmployee.objects.get(pk=e1.pk)
+ self.assertEqual(e2.name, 'Ian')
+ self.assertEqual(e2.gender, 'F')
+ self.assertEqual(e2.profile, profile_boss)
+
+ e2.profile = profile_receptionist
+ e2.name = 'Sara'
+ e2.save(update_fields=['profile'])
+
+ e3 = ProxyEmployee.objects.get(pk=e1.pk)
+ self.assertEqual(e3.name, 'Ian')
+ self.assertEqual(e3.profile, profile_receptionist)
+
def test_update_fields_signals(self):
p = Person.objects.create(name='Sara', gender='F')
pre_save_data = []

0 comments on commit b748b33

Please sign in to comment.