Exemple #1
0
    def test_heartbeat_no_token(self, mCreateSession):
        iSession = MockSession()
        mCreateSession.return_value = (iSession, '123456')

        task = TaskMixin()

        with self.assertRaises(Exception):
            task.heartbeat()
Exemple #2
0
    def test_failure_no_token(self, mCreateSession):
        iSession = MockSession()
        mCreateSession.return_value = (iSession, '123456')

        task = TaskMixin()

        with self.assertRaises(Exception):
            task.failure(None, None)

        self.assertEqual(task.token, None)
Exemple #3
0
    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])
Exemple #4
0
    def test_heartbeat(self, mCreateSession):
        iSession = MockSession()
        client = iSession.client('stepfunctions')
        mCreateSession.return_value = (iSession, '123456')

        task = TaskMixin()
        task.token = 'token'
        task.heartbeat()

        call = mock.call.send_task_heartbeat(taskToken='token')
        self.assertEqual(client.mock_calls, [call])
Exemple #5
0
    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, [])
Exemple #6
0
    def test_failure_timeout(self, mCreateSession):
        iSession = MockSession()
        mCreateSession.return_value = (iSession, '123456')

        client = iSession.client('stepfunctions')
        client.send_task_failure.side_effect = TimeoutError()

        task = TaskMixin()
        task.token = 'token'

        task.failure(None, None)

        self.assertEqual(task.token, None)
Exemple #7
0
    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])
Exemple #8
0
    def test_failure(self, mCreateSession):
        iSession = MockSession()
        client = iSession.client('stepfunctions')
        mCreateSession.return_value = (iSession, '123456')

        task = TaskMixin()
        task.token = 'token'

        self.assertEqual(task.token, 'token')

        task.failure(None, None)

        self.assertEqual(task.token, None)
        call = mock.call.send_task_failure(taskToken='token',
                                           error=None,
                                           cause=None)
        self.assertEqual(client.mock_calls, [call])
Exemple #9
0
    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)