Browse Source

Refactor: Added endpoint to expose roles

merge-requests/1/head
Drew Short 5 years ago
parent
commit
4da0fae30f
  1. 17
      server/corvus/api/user_api.py
  2. 16
      server/tests/api/test_user_api.py

17
server/corvus/api/user_api.py

@ -15,6 +15,7 @@ from corvus.service import (
from corvus.service.patch_service import get_patch_fields from corvus.service.patch_service import get_patch_fields
from corvus.service.role_service import Role from corvus.service.role_service import Role
from corvus.utility.pagination_utility import get_pagination_params from corvus.utility.pagination_utility import get_pagination_params
from corvus.service.role_service import ROLE_LIST
USER_BLUEPRINT = Blueprint( USER_BLUEPRINT = Blueprint(
name='user', import_name=__name__, url_prefix='/user') name='user', import_name=__name__, url_prefix='/user')
@ -114,3 +115,19 @@ def delete_user(name: str) -> APIResponse:
return APIResponse( return APIResponse(
APIMessage(True, 'Successfully Deleted'), status=200) APIMessage(True, 'Successfully Deleted'), status=200)
return abort(404) return abort(404)
@USER_BLUEPRINT.route('/roles', methods=['GET'])
@return_json
@authentication_middleware.require(
required_auth=Auth.TOKEN, required_role=Role.USER)
def get_roles() -> APIResponse:
"""
List the roles available on the service
:return: The list of roles
"""
return APIResponse(
sorted({str(role.data) for role in ROLE_LIST}),
status=200
)

16
server/tests/api/test_user_api.py

@ -6,6 +6,8 @@ from flask.testing import FlaskClient
from tests.conftest import AuthActions from tests.conftest import AuthActions
from corvus.service.role_service import ROLE_LIST
def test_get_users_happy_path(auth: AuthActions, client: FlaskClient): def test_get_users_happy_path(auth: AuthActions, client: FlaskClient):
with auth: with auth:
@ -177,3 +179,17 @@ def test_delete_user_happy_path(auth: AuthActions, client: FlaskClient):
assert 200 == result2.status_code assert 200 == result2.status_code
assert result2.json is not None assert result2.json is not None
assert 'message' in result2.json assert 'message' in result2.json
def test_get_roles(auth: AuthActions, client: FlaskClient):
with auth:
auth_header = auth.get_authorization_header_token()
result = client.get(
'/user/roles',
headers={
auth_header[0]: auth_header[1]
})
assert 200 == result.status_code
assert result.json is not None
for role in ROLE_LIST:
assert str(role.data) in result.json
Loading…
Cancel
Save