def test_search_steps_with_states(self): step_running = Step(lambda x: x) step_running.state = Step.RUN step_paused = Step(lambda x: x) step_paused.state = Step.PAUSED steps = [step_running, step_paused] filtered_steps = search_steps_with_states(steps, [Step.PAUSED]) self.assertEqual(list(filtered_steps), [step_paused])
def test_normal_run(self): trail_manager(self.mock_root_step, self.mock_api_socket, self.mock_backup, delay=12, context=self.mock_context, state_transitions=self.mock_state_transitions) self.mock_topological_traverse.assert_called_once_with( self.mock_root_step) self.mock_state_transition.assert_called_once_with( self.mock_step, self.mock_context) root_step, done_check, ignore_check = self.mock_topological_while.call_args[ 0] self.assertEqual(root_step, self.mock_root_step) # This table is used to check the possible results of done_check and ignore_check functions check_table = [ # State, Expected result of done_check, Expected result of ignore_check (Step.SUCCESS, True, False), (Step.SKIPPED, True, False), (Step.READY, False, False), (Step.RUN, False, False), (Step.FAILURE, False, True), (Step.BLOCKED, False, True), (Step.PAUSED, False, False), (Step.INTERRUPTED, False, False), (Step.PAUSED_ON_FAIL, False, False), (Step.WAIT, False, False), (Step.TOSKIP, False, False), (Step.TOBLOCK, False, False), (Step.TOPAUSE, False, False), ] for state, done_check_result, ignore_check_result in check_table: step = Step(lambda: True) step.state = state self.assertEqual(done_check(step), done_check_result) self.assertEqual(ignore_check(step), ignore_check_result) self.assertEqual(len(self.mock_serve_socket.mock_calls), 2) for mock_call in self.mock_serve_socket.mock_calls: socket, handler = mock_call[1] self.assertEqual(socket, self.mock_api_socket) mock_request = MagicMock() handler(mock_request) self.mock_handle_api_call.assert_called_with( mock_request, steps=[self.mock_step]) self.assertEqual(list(self.step_iterator), []) # Make sure the iterator is drained. self.mock_backup.assert_called_once_with(self.mock_root_step) self.mock_sleep.assert_called_once_with(12) self.mock_api_socket.shutdown.assert_called_once_with(SHUT_RDWR)