def test_run_function(self, mCreateSession): iSession = MockSession() mCreateSession.return_value = (iSession, '123456') client = iSession.client('stepfunctions') task = TaskMixin() task.handle_task('token', None) self.assertEqual(task.token, None) call = mock.call.send_task_success(taskToken='token', output='null') self.assertEqual(client.mock_calls, [call])
def test_run_timeout(self, mCreateSession): iSession = MockSession() mCreateSession.return_value = (iSession, '123456') client = iSession.client('stepfunctions') target = mock.MagicMock() target.side_effect = TimeoutError() task = TaskMixin(process=target) task.handle_task('token', None) self.assertEqual(task.token, None) self.assertEqual(client.mock_calls, [])
def test_run_exception(self, mCreateSession): iSession = MockSession() mCreateSession.return_value = (iSession, '123456') client = iSession.client('stepfunctions') target = mock.MagicMock() target.side_effect = BossError('cause') task = TaskMixin(process=target) task.handle_task('token', None) self.assertEqual(task.token, None) call = mock.call.send_task_failure(taskToken='token', error='BossError', cause='cause') self.assertEqual(client.mock_calls, [call])
def test_run_generator(self, mCreateSession): iSession = MockSession() mCreateSession.return_value = (iSession, '123456') client = iSession.client('stepfunctions') def target(input_): yield yield return # Just make sure the target is actually a generator self.assertEqual(type(target(None)), types.GeneratorType) task = TaskMixin(process=target) task.handle_task('token', None) self.assertEqual(task.token, None) call = mock.call.send_task_success(taskToken='token', output='null') call_ = mock.call.send_task_heartbeat(taskToken='token') calls = [call_, call_, call] self.assertEqual(client.mock_calls, calls)