예제 #1
0
 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")
예제 #2
0
   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"], [])
예제 #3
0
 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")
예제 #4
0
    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"], [])
예제 #5
0
   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)
예제 #6
0
    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)