def test_destroy_callbacks_are_called(self): ODMModel.set_pm(MagicMock()) dic = {"_id" : "2323", "pippo" : "pluto"} odm = ODMModel(dic) pippo = MagicMock() pluto = MagicMock() sempronio = MagicMock() ODMModel.listen("before_destroy", pippo) ODMModel.listen("before_destroy", sempronio) ODMModel.listen("after_destroy", sempronio) ODMModel.listen("after_destroy", pluto) odm.destroy() MagicMock.assert_called_once_with(pippo, odm) MagicMock.assert_called_once_with(pluto, odm) MagicMock.assert_any_call(sempronio, odm)
def test_destroy_callbacks_are_called(self): ODMModel.set_pm(MagicMock()) dic = {"_id": "2323", "pippo": "pluto"} odm = ODMModel(dic) pippo = MagicMock() pluto = MagicMock() sempronio = MagicMock() ODMModel.listen("before_destroy", pippo) ODMModel.listen("before_destroy", sempronio) ODMModel.listen("after_destroy", sempronio) ODMModel.listen("after_destroy", pluto) odm.destroy() MagicMock.assert_called_once_with(pippo, odm) MagicMock.assert_called_once_with(pluto, odm) MagicMock.assert_any_call(sempronio, odm)
def test_class_callbacks_are_called(self): ODMModel.set_pm(MagicMock()) dic = {"_id" : "2323", "pippo" : "pluto"} odm = ODMModel(dic) odm.pippo = MagicMock() odm.pluto = MagicMock() odm.sempronio = MagicMock() ODMModel.listen("before_save", "sempronio") ODMModel.listen("before_save", "pippo") ODMModel.listen("after_save", "pluto") ODMModel.listen("after_save", "sempronio") odm.save() MagicMock.assert_called_once_with(odm.pippo, odm) MagicMock.assert_called_once_with(odm.pluto, odm) self.assertEqual(odm.sempronio.call_count, 2)
def test_class_callbacks_are_called(self): ODMModel.set_pm(MagicMock()) dic = {"_id": "2323", "pippo": "pluto"} odm = ODMModel(dic) odm.pippo = MagicMock() odm.pluto = MagicMock() odm.sempronio = MagicMock() ODMModel.listen("before_save", "sempronio") ODMModel.listen("before_save", "pippo") ODMModel.listen("after_save", "pluto") ODMModel.listen("after_save", "sempronio") odm.save() MagicMock.assert_called_once_with(odm.pippo, odm) MagicMock.assert_called_once_with(odm.pluto, odm) self.assertEqual(odm.sempronio.call_count, 2)
def test_class_callbacks_are_saved(self): ODMModel.listen("before_save", "pippo") ODMModel.listen("before_save", "pluto") ODMModel.listen("before_save", "sempronio") self.assertTrue("pippo" in ODMModel.before_callbacks["ODMModel"]["save"]) self.assertTrue("pluto" in ODMModel.before_callbacks["ODMModel"]["save"]) self.assertTrue("sempronio" in ODMModel.before_callbacks["ODMModel"]["save"]) self.assertEqual(["pippo", "pluto", "sempronio"], ODMModel.before_callbacks["ODMModel"]["save"] ) ODMModel.listen("after_save", "pippo") ODMModel.listen("after_save","pluto") ODMModel.listen("after_save", "sempronio") self.assertTrue("pippo" in ODMModel.after_callbacks["ODMModel"]["save"]) self.assertTrue("pluto" in ODMModel.after_callbacks["ODMModel"]["save"]) self.assertTrue("sempronio" in ODMModel.after_callbacks["ODMModel"]["save"]) self.assertEqual(["pippo", "pluto", "sempronio"], ODMModel.after_callbacks["ODMModel"]["save"] )
def test_class_callbacks_are_saved(self): ODMModel.listen("before_save", "pippo") ODMModel.listen("before_save", "pluto") ODMModel.listen("before_save", "sempronio") self.assertTrue( "pippo" in ODMModel.before_callbacks["ODMModel"]["save"]) self.assertTrue( "pluto" in ODMModel.before_callbacks["ODMModel"]["save"]) self.assertTrue( "sempronio" in ODMModel.before_callbacks["ODMModel"]["save"]) self.assertEqual(["pippo", "pluto", "sempronio"], ODMModel.before_callbacks["ODMModel"]["save"]) ODMModel.listen("after_save", "pippo") ODMModel.listen("after_save", "pluto") ODMModel.listen("after_save", "sempronio") self.assertTrue( "pippo" in ODMModel.after_callbacks["ODMModel"]["save"]) self.assertTrue( "pluto" in ODMModel.after_callbacks["ODMModel"]["save"]) self.assertTrue( "sempronio" in ODMModel.after_callbacks["ODMModel"]["save"]) self.assertEqual(["pippo", "pluto", "sempronio"], ODMModel.after_callbacks["ODMModel"]["save"])