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
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())
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())
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
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
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