Add testcase
This commit is contained in:
parent
c63f43854b
commit
017602056d
@ -37,7 +37,8 @@ class SignalTests(unittest.TestCase):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def post_init(cls, sender, document, **kwargs):
|
def post_init(cls, sender, document, **kwargs):
|
||||||
signal_output.append('post_init signal, %s' % document)
|
signal_output.append('post_init signal, %s, document._created = %s' % (document, document._created))
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def pre_save(cls, sender, document, **kwargs):
|
def pre_save(cls, sender, document, **kwargs):
|
||||||
@ -193,10 +194,16 @@ class SignalTests(unittest.TestCase):
|
|||||||
a1 = self.Author(name='Bill Shakespeare')
|
a1 = self.Author(name='Bill Shakespeare')
|
||||||
self.Author.objects.insert([a1], load_bulk=False)
|
self.Author.objects.insert([a1], load_bulk=False)
|
||||||
|
|
||||||
|
def load_existing_author():
|
||||||
|
a = self.Author(name='Bill Shakespeare')
|
||||||
|
a.save()
|
||||||
|
self.get_signal_output(lambda: None) # eliminate signal output
|
||||||
|
a1 = self.Author.objects(name='Bill Shakespeare')[0]
|
||||||
|
|
||||||
self.assertEqual(self.get_signal_output(create_author), [
|
self.assertEqual(self.get_signal_output(create_author), [
|
||||||
"pre_init signal, Author",
|
"pre_init signal, Author",
|
||||||
"{'name': 'Bill Shakespeare'}",
|
"{'name': 'Bill Shakespeare'}",
|
||||||
"post_init signal, Bill Shakespeare",
|
"post_init signal, Bill Shakespeare, document._created = True",
|
||||||
])
|
])
|
||||||
|
|
||||||
a1 = self.Author(name='Bill Shakespeare')
|
a1 = self.Author(name='Bill Shakespeare')
|
||||||
@ -225,12 +232,22 @@ class SignalTests(unittest.TestCase):
|
|||||||
'post_delete signal, William Shakespeare',
|
'post_delete signal, William Shakespeare',
|
||||||
])
|
])
|
||||||
|
|
||||||
|
signal_output = self.get_signal_output(load_existing_author)
|
||||||
|
# test signal_output lines separately, because of random ObjectID after object load
|
||||||
|
self.assertEqual(signal_output[0],
|
||||||
|
"pre_init signal, Author",
|
||||||
|
)
|
||||||
|
self.assertEqual(signal_output[2],
|
||||||
|
"post_init signal, Bill Shakespeare, document._created = False",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
signal_output = self.get_signal_output(bulk_create_author_with_load)
|
signal_output = self.get_signal_output(bulk_create_author_with_load)
|
||||||
|
|
||||||
# The output of this signal is not entirely deterministic. The reloaded
|
# The output of this signal is not entirely deterministic. The reloaded
|
||||||
# object will have an object ID. Hence, we only check part of the output
|
# object will have an object ID. Hence, we only check part of the output
|
||||||
self.assertEqual(signal_output[3],
|
self.assertEqual(signal_output[3], "pre_bulk_insert signal, [<Author: Bill Shakespeare>]"
|
||||||
"pre_bulk_insert signal, [<Author: Bill Shakespeare>]")
|
)
|
||||||
self.assertEqual(signal_output[-2:],
|
self.assertEqual(signal_output[-2:],
|
||||||
["post_bulk_insert signal, [<Author: Bill Shakespeare>]",
|
["post_bulk_insert signal, [<Author: Bill Shakespeare>]",
|
||||||
"Is loaded",])
|
"Is loaded",])
|
||||||
@ -238,7 +255,7 @@ class SignalTests(unittest.TestCase):
|
|||||||
self.assertEqual(self.get_signal_output(bulk_create_author_without_load), [
|
self.assertEqual(self.get_signal_output(bulk_create_author_without_load), [
|
||||||
"pre_init signal, Author",
|
"pre_init signal, Author",
|
||||||
"{'name': 'Bill Shakespeare'}",
|
"{'name': 'Bill Shakespeare'}",
|
||||||
"post_init signal, Bill Shakespeare",
|
"post_init signal, Bill Shakespeare, document._created = True",
|
||||||
"pre_bulk_insert signal, [<Author: Bill Shakespeare>]",
|
"pre_bulk_insert signal, [<Author: Bill Shakespeare>]",
|
||||||
"post_bulk_insert signal, [<Author: Bill Shakespeare>]",
|
"post_bulk_insert signal, [<Author: Bill Shakespeare>]",
|
||||||
"Not loaded",
|
"Not loaded",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user