def test_destroy(self): pm = MagicMock() ODMModel.set_pm(pm) dic = {"_id" : "2323", "pippo" : "pluto"} odm = ODMModel(dic) odm.destroy() pm.destroy_by_id.assert_called_once_with(odm.collection_name(), "2323")
def test_instance_callbacks_are_executed_once(self): ODMModel.set_pm(MagicMock()) dic = {"_id" : "2323", "pippo" : "pluto"} odm = ODMModel(dic) odm.pippo = MagicMock() odm.pluto = MagicMock() sempronio = MagicMock() odm.listen_once("before_save", "pippo") odm.listen_once("before_save", "pluto") odm.listen_once("before_save", sempronio) odm.save() MagicMock.assert_called_once_with(odm.pippo, odm) MagicMock.assert_called_once_with(odm.pluto, odm) MagicMock.assert_called_once_with(sempronio, odm) self.assertEqual(odm.before_callbacks_single["save"], []) odm.pippo.reset_mock() odm.pluto.reset_mock() sempronio.reset_mock() odm.listen_once("after_destroy", "pippo") odm.listen_once("after_destroy", sempronio) odm.destroy() MagicMock.assert_called_once_with(odm.pippo, odm) MagicMock.assert_called_once_with(sempronio, odm) self.assertEqual(odm.pluto.call_count, 0) self.assertEqual(odm.after_callbacks_single["destroy"], [])
def test_destroy(self): pm = MagicMock() ODMModel.set_pm(pm) dic = {"_id": "2323", "pippo": "pluto"} odm = ODMModel(dic) odm.destroy() pm.destroy_by_id.assert_called_once_with(odm.collection_name(), "2323")
def test_instance_callbacks_are_executed_once(self): ODMModel.set_pm(MagicMock()) dic = {"_id": "2323", "pippo": "pluto"} odm = ODMModel(dic) odm.pippo = MagicMock() odm.pluto = MagicMock() sempronio = MagicMock() odm.listen_once("before_save", "pippo") odm.listen_once("before_save", "pluto") odm.listen_once("before_save", sempronio) odm.save() MagicMock.assert_called_once_with(odm.pippo, odm) MagicMock.assert_called_once_with(odm.pluto, odm) MagicMock.assert_called_once_with(sempronio, odm) self.assertEqual(odm.before_callbacks_single["save"], []) odm.pippo.reset_mock() odm.pluto.reset_mock() sempronio.reset_mock() odm.listen_once("after_destroy", "pippo") odm.listen_once("after_destroy", sempronio) odm.destroy() MagicMock.assert_called_once_with(odm.pippo, odm) MagicMock.assert_called_once_with(sempronio, odm) self.assertEqual(odm.pluto.call_count, 0) self.assertEqual(odm.after_callbacks_single["destroy"], [])
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)