示例#1
0
def test_read_self_should_return_404_if_user_does_not_exist(client, jwt_service):
    jwt_payload = AccessTokenPayload(
        user_id=1, roles=[], exp=AccessTokenPayload.calc_exp(1), sid="123456"
    )
    jwt = jwt_service.generate_token(jwt_payload.dict())
    response = read_self_request(client, jwt)
    assert response.status_code == HTTP_404_NOT_FOUND
示例#2
0
def user_jwt(jwt_service, user):
    jwt_payload = AccessTokenPayload(
        user_id=user.id,
        roles=user.roles,
        exp=AccessTokenPayload.calc_exp(1),
        sid="123456",
    )
    return jwt_service.generate_token(jwt_payload.dict())
示例#3
0
def user_2_jwt(jwt_service, users_repository):
    user = users_repository.create(user_dict_2)
    jwt_payload = AccessTokenPayload(
        user_id=user.id,
        roles=user.roles,
        exp=AccessTokenPayload.calc_exp(1),
        sid="123456",
    )
    return jwt_service.generate_token(jwt_payload.dict())
示例#4
0
def test_update_user_should_return_403_for_non_admin(client, jwt_service):
    jwt_payload = AccessTokenPayload(
        user_id=1,
        roles=[],
        exp=AccessTokenPayload.calc_exp(1),
        sid="123456",
    )
    jwt = jwt_service.generate_token(jwt_payload.dict())
    response = update_user_roles_request(client, 1, jwt, [])
    assert response.status_code == HTTP_403_FORBIDDEN
示例#5
0
def test_update_user_roles_should_return_404_if_user_does_not_exist(
        client, jwt_service):
    jwt_payload = AccessTokenPayload(
        user_id=1,
        roles=[UserRoles.ADMIN],
        exp=AccessTokenPayload.calc_exp(1),
        sid="123456",
    )
    jwt = jwt_service.generate_token(jwt_payload.dict())
    response = update_user_roles_request(client, 1, jwt, [])
    assert response.status_code == HTTP_404_NOT_FOUND
示例#6
0
def test_update_self_should_return_409_if_data_conflicts(
    client, jwt_service, user, users_repository
):
    users_repository.create(update_payload)
    jwt_payload = AccessTokenPayload(
        user_id=user.id,
        roles=user.roles,
        exp=AccessTokenPayload.calc_exp(1),
        sid="123456",
    )
    jwt = jwt_service.generate_token(jwt_payload.dict())
    response = update_self_request(client, jwt)
    assert response.status_code == HTTP_409_CONFLICT