

def test_model_signals(self):
    ' Model saves should throw some signals. '

    def create_author():
        self.Author(name='Bill Shakespeare')

    def bulk_create_author_with_load():
        a1 = self.Author(name='Bill Shakespeare')
        self.Author.objects.insert([a1], load_bulk=True)

    def bulk_create_author_without_load():
        a1 = self.Author(name='Bill Shakespeare')
        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))
        a1 = self.Author.objects(name='Bill Shakespeare')[0]
    self.assertEqual(self.get_signal_output(create_author), ['pre_init signal, Author', {
        'name': 'Bill Shakespeare',
    }, 'post_init signal, Bill Shakespeare, document._created = True'])
    a1 = self.Author(name='Bill Shakespeare')
    self.assertEqual(self.get_signal_output(a1.save), ['pre_save signal, Bill Shakespeare', {
        
    }, 'pre_save_post_validation signal, Bill Shakespeare', 'Is created', {
        
    }, 'post_save signal, Bill Shakespeare', "post_save dirty keys, ['name']", 'Is created', {
        
    }])
    a1.reload()
    a1.name = 'William Shakespeare'
    self.assertEqual(self.get_signal_output(a1.save), ['pre_save signal, William Shakespeare', {
        
    }, 'pre_save_post_validation signal, William Shakespeare', 'Is updated', {
        
    }, 'post_save signal, William Shakespeare', "post_save dirty keys, ['name']", 'Is updated', {
        
    }])
    self.assertEqual(self.get_signal_output(a1.delete), ['pre_delete signal, William Shakespeare', {
        
    }, 'post_delete signal, William Shakespeare', {
        
    }])
    self.assertEqual(self.get_signal_output(load_existing_author), ['pre_init signal, Author', {
        'id': 2,
        'name': 'Bill Shakespeare',
    }, 'post_init signal, Bill Shakespeare, document._created = False'])
    self.assertEqual(self.get_signal_output(bulk_create_author_with_load), ['pre_init signal, Author', {
        'name': 'Bill Shakespeare',
    }, 'post_init signal, Bill Shakespeare, document._created = True', 'pre_bulk_insert signal, [<Author: Bill Shakespeare>]', {
        
    }, 'pre_init signal, Author', {
        'id': 3,
        'name': 'Bill Shakespeare',
    }, 'post_init signal, Bill Shakespeare, document._created = False', 'post_bulk_insert signal, [<Author: Bill Shakespeare>]', 'Is loaded', {
        
    }])
    self.assertEqual(self.get_signal_output(bulk_create_author_without_load), ['pre_init signal, Author', {
        'name': 'Bill Shakespeare',
    }, 'post_init signal, Bill Shakespeare, document._created = True', 'pre_bulk_insert signal, [<Author: Bill Shakespeare>]', {
        
    }, 'post_bulk_insert signal, [<Author: Bill Shakespeare>]', 'Not loaded', {
        
    }])

dataset/ETHPy150Open MongoEngine/mongoengine/tests/test_signals.py SignalTests.test_model_signals/original