コード例 #1
0
def test_assign_user_to_task_request():
    user_id = 1
    task_id = 2
    request = AssignUserToTaskRequest(task_id, user_id)

    assert request.is_valid()
    assert request.task_id == task_id
    assert request.user_id == user_id
コード例 #2
0
def test_assign_user_to_task_request_without_id():
    user_id = None
    task_id = None

    request = AssignUserToTaskRequest(task_id, user_id)

    assert not request.is_valid()
    assert request.task_id == task_id
    assert request.user_id == user_id
    assert len(request.errors) == 2
    assert any([e.parameter == 'task_id' and e.message == 'is required'
                for e in request.errors])
    assert any([e.parameter == 'user_id' and e.message == 'is required'
                for e in request.errors])
コード例 #3
0
def assing_user_to_task(task_id):
    request = AssignUserToTaskRequest(task_id=task_id, user_id=current_user.id)
    action = AssignUserToTaskAction(tasks_repository, users_repository)
    action.add_before_execution_hook(authorization_manager.authorize)
    response = action.execute(request)
    status = get_status(response)

    return json_response(response.value, TaskEncoder, status)
コード例 #4
0
def test_assign_user_to_task_bad_request():
    user_id = 'ab'
    task_id = 'ad'

    request = AssignUserToTaskRequest(task_id, user_id)

    assert not request.is_valid()
    assert request.task_id == task_id
    assert request.user_id == user_id
    assert len(request.errors) == 2
    assert any(
        [e.parameter == 'task_id' and e.message == 'expected int, got str(ad)'
            for e in request.errors]
    )
    assert any(
        [e.parameter == 'user_id' and e.message == 'expected int, got str(ab)'
            for e in request.errors]
    )
コード例 #5
0
def test_assign_user_to_task_action():
    tasks_repo = mock.Mock()
    users_repo = mock.Mock()

    request = AssignUserToTaskRequest(task_id=1, user_id=2)

    action = AssignUserToTaskAction(tasks_repo, users_repo)
    response = action.execute(request)

    assert bool(response) is True
    assert tasks_repo.update.called
コード例 #6
0
def test_assing_user_to_task_action_handles_bad_request():
    tasks_repo = mock.Mock()
    users_repo = mock.Mock()

    request = AssignUserToTaskRequest(task_id=None, user_id=None)

    action = AssignUserToTaskAction(tasks_repo, users_repo)
    response = action.execute(request)

    assert bool(response) is False
    assert not tasks_repo.update.called
    assert response.value == {
        'type': ResponseFailure.PARAMETER_ERROR,
        'message': 'task_id: is required\nuser_id: is required'
    }
コード例 #7
0
def test_assign_user_to_task_action_handles_generic_error():
    error_message = 'Error!!!'
    tasks_repo = mock.Mock()
    tasks_repo.update.side_effect = Exception(error_message)
    users_repo = mock.Mock()

    request = AssignUserToTaskRequest(task_id=1, user_id=2)

    action = AssignUserToTaskAction(tasks_repo, users_repo)
    response = action.execute(request)

    assert bool(response) is False
    assert tasks_repo.update.called
    assert response.value == {
        'type': ResponseFailure.SYSTEM_ERROR,
        'message': 'Exception: {}'.format(error_message)
    }
コード例 #8
0
def test_assign_user_to_task_action_with_hooks():
    tasks_repo = mock.Mock()
    users_repo = mock.Mock()

    request = AssignUserToTaskRequest(task_id=1, user_id=2)

    action = AssignUserToTaskAction(tasks_repo, users_repo)

    before = mock.MagicMock()
    after = mock.MagicMock()

    action.add_before_execution_hook(before)
    action.add_after_execution_hook(after)

    response = action.execute(request)

    assert before.called
    assert after.called
    assert bool(response) is True
    assert tasks_repo.update.called