コード例 #1
0
ファイル: test_client.py プロジェクト: yutiansut/clearly
def test_client_task(bool1, mocked_client_display):
    task = clearly_pb2.TaskMessage(name='name',
                                   routing_key='routing_key',
                                   uuid='uuid',
                                   retries=2,
                                   args='args',
                                   kwargs='kwargs',
                                   result='result',
                                   traceback='traceback',
                                   timestamp=123.1,
                                   state='state',
                                   created=False)
    mocked_client_display._stub.find_task.return_value = task if bool1 else clearly_pb2.TaskMessage(
    )
    mocked_client_display.task('uuid')
    if bool1:
        mocked_client_display._display_task.assert_called_once_with(
            task, True, True, True)
    else:
        mocked_client_display._display_task.assert_not_called()
コード例 #2
0
ファイル: test_client.py プロジェクト: yutiansut/clearly
def test_client_tasks(tristate, bool1, bool2, mocked_client_display):
    task = clearly_pb2.TaskMessage(name='name',
                                   routing_key='routing_key',
                                   uuid='uuid',
                                   retries=2,
                                   args='args',
                                   kwargs='kwargs',
                                   result='result',
                                   traceback='traceback',
                                   timestamp=123.1,
                                   state='ANY',
                                   created=False)
    mocked_client_display._stub.filter_tasks.return_value = (task, )
    mocked_client_display.tasks(params=tristate, success=bool1, error=bool2)
    mocked_client_display._display_task.assert_called_once_with(
        task, tristate, bool1, bool2)
コード例 #3
0
ファイル: test_client.py プロジェクト: yutiansut/clearly
def test_client_display_task(task_result, tristate, bool1, bool2, bool3,
                             task_state_type, task_tb, mocked_client, capsys):
    task = clearly_pb2.TaskMessage(name='name',
                                   routing_key='routing_key',
                                   uuid='uuid',
                                   retries=2,
                                   args='args123',
                                   kwargs='kwargs',
                                   result=task_result,
                                   traceback=task_tb,
                                   timestamp=123.1,
                                   state=task_state_type,
                                   created=bool3)

    with mock.patch(
            'clearly.client.ClearlyClient._task_state') as m_task_state:
        mocked_client._display_task(task,
                                    params=tristate,
                                    success=bool1,
                                    error=bool2)
    generated = strip_colors(capsys.readouterr().out)

    assert task.name in generated
    assert task.uuid in generated

    if bool3:
        assert task.routing_key in generated
        m_task_state.assert_not_called()
    else:
        m_task_state.assert_called_once_with(task.state)

    show_result = (task.state in states.EXCEPTION_STATES and bool2) \
                  or (task.state == states.SUCCESS and bool1)

    # params
    first_seen = bool(tristate) and task.created
    result = tristate is not False and (task.state
                                        in states.READY_STATES) and show_result
    tristate = first_seen or result
    assert tristate == (task.args in generated)
    assert tristate == (task.kwargs in generated)

    # result
    if show_result:
        assert '==> ' + (task_result or task_tb or ':)') in generated