Esempio n. 1
0
 def publish(self):
     try:
         self.publish_impl()
     except Exception as e:
         call_back.notify_callbacks(self.call_backs, is_success=False)
         raise e
     call_back.notify_callbacks(self.call_backs, is_success=True)
Esempio n. 2
0
    def test_failure_notify(self) -> None:
        callback1 = MagicMock()
        callback2 = MagicMock()
        callbacks: List[Callback] = [callback1, callback2]

        notify_callbacks(callbacks, is_success=False)

        self.assertTrue(not callback1.on_success.called)
        self.assertTrue(callback1.on_failure.called)
        self.assertTrue(not callback2.on_success.called)
        self.assertTrue(callback2.on_failure.called)
Esempio n. 3
0
    def test_success_notify(self):
        # type: () -> None
        callback1 = MagicMock()
        callback2 = MagicMock()
        callbacks = [callback1, callback2]

        call_back.notify_callbacks(callbacks, is_success=True)

        self.assertTrue(callback1.on_success.called)
        self.assertTrue(not callback1.on_failure.called)
        self.assertTrue(callback2.on_success.called)
        self.assertTrue(not callback2.on_failure.called)
Esempio n. 4
0
    def test_notify_failure(self) -> None:
        callback1 = MagicMock()
        callback2 = MagicMock()
        callback2.on_success.side_effect = Exception('Boom')
        callback3 = MagicMock()
        callbacks: List[Callback] = [callback1, callback2, callback3]

        try:
            notify_callbacks(callbacks, is_success=True)
            self.assertTrue(False)
        except Exception:
            self.assertTrue(True)

        self.assertTrue(callback1.on_success.called)
        self.assertTrue(callback2.on_success.called)
        self.assertTrue(callback3.on_success.called)