Tested model signals "sender" parameter when defer() is used.

This was fixed when dynamic classes for deferred instance loading
was removed in 7f51876f99.
This commit is contained in:
Mathieu Pillard 2016-09-21 12:32:24 +02:00 committed by Tim Graham
parent d895fc9ac0
commit 2b8ccff3b6
1 changed files with 28 additions and 18 deletions

View File

@ -53,12 +53,12 @@ class SignalTests(BaseSignalTest):
def pre_save_handler(signal, sender, instance, **kwargs): def pre_save_handler(signal, sender, instance, **kwargs):
data.append( data.append(
(instance, kwargs.get("raw", False)) (instance, sender, kwargs.get("raw", False))
) )
def post_save_handler(signal, sender, instance, **kwargs): def post_save_handler(signal, sender, instance, **kwargs):
data.append( data.append(
(instance, kwargs.get("created"), kwargs.get("raw", False)) (instance, sender, kwargs.get("created"), kwargs.get("raw", False))
) )
signals.pre_save.connect(pre_save_handler, weak=False) signals.pre_save.connect(pre_save_handler, weak=False)
@ -67,24 +67,24 @@ class SignalTests(BaseSignalTest):
p1 = Person.objects.create(first_name="John", last_name="Smith") p1 = Person.objects.create(first_name="John", last_name="Smith")
self.assertEqual(data, [ self.assertEqual(data, [
(p1, False), (p1, Person, False),
(p1, True, False), (p1, Person, True, False),
]) ])
data[:] = [] data[:] = []
p1.first_name = "Tom" p1.first_name = "Tom"
p1.save() p1.save()
self.assertEqual(data, [ self.assertEqual(data, [
(p1, False), (p1, Person, False),
(p1, False, False), (p1, Person, False, False),
]) ])
data[:] = [] data[:] = []
# Calling an internal method purely so that we can trigger a "raw" save. # Calling an internal method purely so that we can trigger a "raw" save.
p1.save_base(raw=True) p1.save_base(raw=True)
self.assertEqual(data, [ self.assertEqual(data, [
(p1, True), (p1, Person, True),
(p1, False, True), (p1, Person, False, True),
]) ])
data[:] = [] data[:] = []
@ -92,15 +92,25 @@ class SignalTests(BaseSignalTest):
p2.id = 99999 p2.id = 99999
p2.save() p2.save()
self.assertEqual(data, [ self.assertEqual(data, [
(p2, False), (p2, Person, False),
(p2, True, False), (p2, Person, True, False),
]) ])
data[:] = [] data[:] = []
p2.id = 99998 p2.id = 99998
p2.save() p2.save()
self.assertEqual(data, [ self.assertEqual(data, [
(p2, False), (p2, Person, False),
(p2, True, False), (p2, Person, True, False),
])
# The sender should stay the same when using defer().
data[:] = []
p3 = Person.objects.defer('first_name').get(pk=p1.pk)
p3.last_name = 'Reese'
p3.save()
self.assertEqual(data, [
(p3, Person, False),
(p3, Person, False, False),
]) ])
finally: finally:
signals.pre_save.disconnect(pre_save_handler) signals.pre_save.disconnect(pre_save_handler)
@ -111,7 +121,7 @@ class SignalTests(BaseSignalTest):
def pre_delete_handler(signal, sender, instance, **kwargs): def pre_delete_handler(signal, sender, instance, **kwargs):
data.append( data.append(
(instance, instance.id is None) (instance, sender, instance.id is None)
) )
# #8285: signals can be any callable # #8285: signals can be any callable
@ -121,7 +131,7 @@ class SignalTests(BaseSignalTest):
def __call__(self, signal, sender, instance, **kwargs): def __call__(self, signal, sender, instance, **kwargs):
self.data.append( self.data.append(
(instance, instance.id is None) (instance, sender, instance.id is None)
) )
post_delete_handler = PostDeleteHandler(data) post_delete_handler = PostDeleteHandler(data)
@ -131,8 +141,8 @@ class SignalTests(BaseSignalTest):
p1 = Person.objects.create(first_name="John", last_name="Smith") p1 = Person.objects.create(first_name="John", last_name="Smith")
p1.delete() p1.delete()
self.assertEqual(data, [ self.assertEqual(data, [
(p1, False), (p1, Person, False),
(p1, False), (p1, Person, False),
]) ])
data[:] = [] data[:] = []
@ -143,8 +153,8 @@ class SignalTests(BaseSignalTest):
p2.save() p2.save()
p2.delete() p2.delete()
self.assertEqual(data, [ self.assertEqual(data, [
(p2, False), (p2, Person, False),
(p2, False) (p2, Person, False),
]) ])
data[:] = [] data[:] = []