Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Ticket #4102 - Add tests for proxied models.

  • Loading branch information...
commit b748b33ecb99bcc0a627f3af525b943e0ef97dab 1 parent 5671df4
@niwinz authored
View
3  tests/modeltests/update_only_fields/__init__.py
@@ -1,3 +0,0 @@
-# -*- coding: utf-8 -*-
-
-
View
5 tests/modeltests/update_only_fields/models.py
@@ -24,3 +24,8 @@ class Profile(models.Model):
def __unicode__(self):
return self.name
+
+
+class ProxyEmployee(Employee):
+ class Meta:
+ proxy = True
View
26 tests/modeltests/update_only_fields/tests.py
@@ -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 = []
Please sign in to comment.
Something went wrong with that request. Please try again.