Esempio n. 1
0
    def test_when_post_processor_fails(self):
        mock_exception = MockException()
        mock_post_processor = MagicMock(side_effect=mock_exception)
        mock_failure_handler_return_value = MagicMock()
        mock_failure_handler = MagicMock(
            return_value=mock_failure_handler_return_value)
        self.mock_step.failure_handler = mock_failure_handler
        self.mock_step.post_processor = mock_post_processor

        check_running_step(self.mock_step)

        mock_post_processor.assert_called_once_with(
            self.mock_step.environment, self.mock_step.context,
            self.mock_result.return_value)
        self.assertEqual(self.mock_step.state, Step.PAUSED_ON_FAIL)
        mock_failure_handler.assert_called_once_with(
            self.mock_step.environment, self.mock_step.context, mock_exception)
        self.assertEqual(self.mock_step.return_value,
                         mock_failure_handler_return_value)
        self.mock_log_step.assert_called_once_with(
            logging.debug, self.mock_step,
            ('Step has failed. Changed state to: {}. Setting return value to: {}'
             ).format(Step.PAUSED_ON_FAIL, mock_failure_handler_return_value))
        self.assertEqual(self.mock_skip_progeny.call_count, 0)
        self.mock_collect_output_messages_from_step.assert_called_once_with(
            self.mock_step)
        self.mock_collect_prompt_messages_from_step.assert_called_once_with(
            self.mock_step)
Esempio n. 2
0
    def test_when_step_fails_and_progeny_need_to_be_skipped(self):
        self.mock_result.result = Step.FAILURE
        self.mock_result.return_value = 'mock_return_value'
        self.mock_step.skip_progeny_on_failure = True
        self.mock_step.state = Step.RUN
        self.mock_step.return_value = None
        self.mock_step.result_queue.get_nowait = MagicMock(
            return_value=self.mock_result)

        check_running_step(self.mock_step)

        self.mock_failure_handler.assert_called_once_with(
            self.mock_step.environment, self.mock_step.context,
            self.mock_result.return_value)
        self.assertEqual(self.mock_step.state, Step.PAUSED_ON_FAIL)
        self.assertEqual(self.mock_step.return_value,
                         self.mock_failed_return_value)
        self.mock_log_step.assert_called_once_with(
            logging.debug, self.mock_step,
            ('Step has failed. Changed state to: {}. Setting return value to: {}'
             ).format(Step.PAUSED_ON_FAIL, self.mock_failed_return_value))
        self.mock_skip_progeny.assert_called_once_with(self.mock_step)
        self.mock_collect_output_messages_from_step.assert_called_once_with(
            self.mock_step)
        self.mock_collect_prompt_messages_from_step.assert_called_once_with(
            self.mock_step)
        self.assertEqual(self.mock_post_processor.call_count, 0)
Esempio n. 3
0
    def test_when_step_does_not_return_a_result(self):
        self.mock_step.result_queue.get_nowait = MagicMock(
            side_effect=QueueEmpty)

        check_running_step(self.mock_step)

        self.assertNotEqual(self.mock_step.state, 'mock_result')
        self.assertNotEqual(self.mock_step.return_value, 'mock_return_value')
        self.assertEqual(self.mock_log_step.call_count, 0)
        self.assertEqual(self.mock_skip_progeny.call_count, 0)
        self.mock_collect_output_messages_from_step.assert_called_once_with(
            self.mock_step)
        self.mock_collect_prompt_messages_from_step.assert_called_once_with(
            self.mock_step)
Esempio n. 4
0
    def test_when_step_returns_result(self):
        check_running_step(self.mock_step)

        self.assertEqual(self.mock_step.state, 'mock_result')
        self.assertEqual(self.mock_step.return_value, 'mock_return_value')
        self.mock_log_step.assert_called_once_with(
            logging.debug, self.mock_step,
            ('Step has completed. Changed state to: mock_result. Setting return value to: mock_return_value'
             ))
        self.assertEqual(self.mock_skip_progeny.call_count, 0)
        self.mock_collect_output_messages_from_step.assert_called_once_with(
            self.mock_step)
        self.mock_collect_prompt_messages_from_step.assert_called_once_with(
            self.mock_step)
Esempio n. 5
0
    def test_when_step_returns_result(self):
        check_running_step(self.mock_step)

        self.mock_post_processor.assert_called_once_with(
            self.mock_step.environment, self.mock_step.context,
            self.mock_result.return_value)
        self.assertEqual(self.mock_step.state, Step.SUCCESS)
        self.assertEqual(self.mock_step.return_value, self.mock_return_value)
        self.mock_log_step.assert_called_once_with(
            logging.debug, self.mock_step,
            ('Step has succeeded. Changed state to: {}. Setting return value to: {}'
             .format(Step.SUCCESS, self.mock_return_value)))
        self.assertEqual(self.mock_skip_progeny.call_count, 0)
        self.assertEqual(self.mock_failure_handler.call_count, 0)
        self.mock_collect_output_messages_from_step.assert_called_once_with(
            self.mock_step)
        self.mock_collect_prompt_messages_from_step.assert_called_once_with(
            self.mock_step)
Esempio n. 6
0
    def test_when_step_fails_and_progeny_need_to_be_skipped(self):
        self.mock_result.result = Step.FAILURE
        self.mock_result.return_value = 'mock_return_value'
        self.mock_step.skip_progeny_on_failure = True
        self.mock_step.state = Step.RUN
        self.mock_step.return_value = None
        self.mock_step.result_queue.get_nowait = MagicMock(
            return_value=self.mock_result)

        check_running_step(self.mock_step)

        self.assertEqual(self.mock_step.state, Step.FAILURE)
        self.assertEqual(self.mock_step.return_value, 'mock_return_value')
        self.mock_log_step.assert_called_once_with(
            logging.debug, self.mock_step,
            ('Step has completed. Changed state to: {}. Setting return value to: mock_return_value'
             ).format(Step.FAILURE))
        self.mock_skip_progeny.assert_called_once_with(self.mock_step)
        self.mock_collect_output_messages_from_step.assert_called_once_with(
            self.mock_step)
        self.mock_collect_prompt_messages_from_step.assert_called_once_with(
            self.mock_step)