コード例 #1
0
def test_get_role_details_request_without_id():
    role_id = None
    request = GetRoleDetailsRequest(role_id)

    assert not request.is_valid()
    assert request.role_id == role_id
    assert len(request.errors) == 1
    error = request.errors[0]
    assert error.parameter == 'role_id'
    assert error.message == 'is required'
コード例 #2
0
def test_get_role_details_bad_request():
    role_id = 'asd'
    request = GetRoleDetailsRequest(role_id)

    assert not request.is_valid()
    assert request.role_id == role_id
    assert len(request.errors) == 1
    error = request.errors[0]
    assert error.parameter == 'role_id'
    assert error.message == 'expected int, got str(asd)'
コード例 #3
0
def get_user_role_details(id):
    request = GetRoleDetailsRequest(id)
    action = GetRoleDetailsAction(user_roles_repository)
    action.add_before_execution_hook(authorization_manager.authorize)
    response = action.execute(request)
    status = get_status(response)

    return json_response(response.value, UserRoleEncoder, status)
コード例 #4
0
def test_get_role_details_action():
    role = mock.Mock()
    role = UserRole(name='admin', id=1)
    roles_repo = mock.Mock()
    roles_repo.one.return_value = role
    request = GetRoleDetailsRequest(role.id)

    action = GetRoleDetailsAction(roles_repo)
    response = action.execute(request)

    assert bool(response) is True
    roles_repo.one.assert_called_once_with(role.id)
    assert response.value == role
コード例 #5
0
def test_get_role_details_action_handles_generic_error():
    error_message = 'Error!!!'
    roles_repo = mock.Mock()
    roles_repo.one.side_effect = Exception(error_message)
    request = GetRoleDetailsRequest(role_id=1)

    action = GetRoleDetailsAction(roles_repo)
    response = action.execute(request)

    assert bool(response) is False
    roles_repo.one.assert_called_once_with(1)
    assert response.value == {
        'type': ResponseFailure.SYSTEM_ERROR,
        'message': 'Exception: {}'.format(error_message)
    }
コード例 #6
0
def test_get_role_details_action_handles_bad_request():
    role = mock.Mock()
    role = UserRole(name='admin', id=1)
    roles_repo = mock.Mock()
    roles_repo.one.return_value = role
    request = GetRoleDetailsRequest(role_id=None)

    action = GetRoleDetailsAction(roles_repo)
    response = action.execute(request)

    assert bool(response) is False
    assert not roles_repo.one.called
    assert response.value == {
        'type': ResponseFailure.PARAMETER_ERROR,
        'message': 'role_id: is required'
    }
コード例 #7
0
def test_get_role_details_action_with_hooks():
    role = mock.Mock()
    role = UserRole(name='admin', id=1)
    roles_repo = mock.Mock()
    roles_repo.one.return_value = role
    request = GetRoleDetailsRequest(role.id)

    action = GetRoleDetailsAction(roles_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
    roles_repo.one.assert_called_once_with(role.id)
    assert response.value == role
コード例 #8
0
def test_get_role_details_request():
    role_id = 1
    request = GetRoleDetailsRequest(role_id)

    assert request.is_valid()
    assert request.role_id == role_id