def test_onObservationAborted_uses_correct_triggerid_and_sets_correct_cancellation_reason(
            self):
        handler = TriggerCancellationHandler(self.momqueryrpc_mock)

        handler.onObservationAborted(self.obs_sas_id, None)

        # correct otdb id is used to obtain trigger
        call_otdb_id = self.momqueryrpc_mock.getMoMIdsForOTDBIds.call_args[0][
            0]
        self.assertEqual(self.obs_sas_id, call_otdb_id)

        # correct trigger id and reason are used to abort
        call_id, call_reason = self.momqueryrpc_mock.cancel_trigger.call_args[
            0]
        self.assertEqual(self.trigger_id, call_id)
        self.assertIn('aborted', call_reason)
    def test_start_listening_opens_momquery_rpc(self):
        handler = TriggerCancellationHandler(self.momqueryrpc_mock)

        handler.start_handling()

        self.momqueryrpc_mock.open.assert_called()
    def test_stop_listening_closes_momquery_rpc(self):
        handler = TriggerCancellationHandler(self.momqueryrpc_mock)

        handler.stop_handling()

        self.momqueryrpc_mock.close.assert_called()
    def test_onObservationError_calls_cancel_trigger_when_its_a_trigger(self):
        handler = TriggerCancellationHandler(self.momqueryrpc_mock)

        handler.onObservationError(self.obs_sas_id, None)

        self.momqueryrpc_mock.cancel_trigger.assert_called()