Beispiel #1
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"], [])
Beispiel #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"], [])
Beispiel #3
0
    def test_instance_callbacks_are_saved(self):

        ODMModel.set_pm(MagicMock())

        dic = {"_id": "2323", "pippo": "pluto"}
        odm = ODMModel(dic)
        pippo = MagicMock()
        pluto = MagicMock()
        sempronio = MagicMock()

        odm.listen_once("before_save", "pippo")
        odm.listen_once("before_save", "pluto")
        odm.listen_once("before_save", "sempronio")
        self.assertEqual(odm.before_callbacks_single["save"],
                         ["pippo", "pluto", "sempronio"])

        odm.listen_once("after_save", "pippo")
        odm.listen_once("after_save", "sempronio")
        self.assertEqual(odm.after_callbacks_single["save"],
                         ["pippo", "sempronio"])
Beispiel #4
0
   def test_instance_callbacks_are_saved(self):

      ODMModel.set_pm(MagicMock())

      dic            = {"_id" : "2323", "pippo" : "pluto"}
      odm            = ODMModel(dic)
      pippo          = MagicMock()
      pluto          = MagicMock()
      sempronio      = MagicMock()

      odm.listen_once("before_save", "pippo")
      odm.listen_once("before_save", "pluto")
      odm.listen_once("before_save", "sempronio")
      self.assertEqual(
                        odm.before_callbacks_single["save"],
                        ["pippo", "pluto", "sempronio"]
                        )

      odm.listen_once("after_save", "pippo")
      odm.listen_once("after_save", "sempronio")
      self.assertEqual(
                        odm.after_callbacks_single["save"],
                        ["pippo", "sempronio"]
                        )