diff --git a/app/api/main.py b/app/api/main.py index 42b2fb1bc53f47d188660faa52eadbe4916e5a03..de7c369738abd0494231d650e35f4c2dd40962b2 100644 --- a/app/api/main.py +++ b/app/api/main.py @@ -14,7 +14,7 @@ from flask import (current_app, Blueprint, jsonify, request) from flask_jwt_extended import create_access_token, jwt_required from flask_ldap3_login import AuthenticationResponseStatus from ..extensions import ldap_manager, db -from ..models import Item, Manufacturer, Model, Location, Status +from ..models import Item, Manufacturer, Model, Location, Status, Action from .. import utils from ..decorators import jwt_groups_accepted @@ -174,6 +174,12 @@ def patch_item(id_): return jsonify(item.to_dict()) +@bp.route('/actions') +@jwt_required +def get_actions(): + return get_generic_model(Action, request.args) + + @bp.route('/manufacturers') @jwt_required def get_manufacturers(): diff --git a/tests/functional/test_api.py b/tests/functional/test_api.py index c1e828b32a3df8baa438625cd5b3f583615dbbe9..0f99c3a248caca4a11060302b8a940cb64e9766f 100644 --- a/tests/functional/test_api.py +++ b/tests/functional/test_api.py @@ -15,14 +15,16 @@ from app import models ENDPOINT_MODEL = { + 'actions': models.Action, 'manufacturers': models.Manufacturer, 'models': models.Model, 'locations': models.Location, 'status': models.Status, 'items': models.Item, } -GENERIC_ENDPOINTS = [key for key in ENDPOINT_MODEL.keys() if key != 'items'] -ENDPOINTS = list(ENDPOINT_MODEL.keys()) +GENERIC_GET_ENDPOINTS = [key for key in ENDPOINT_MODEL.keys() if key != 'items'] +GENERIC_CREATE_ENDPOINTS = [key for key in ENDPOINT_MODEL.keys() if key not in ('items', 'actions')] +CREATE_AUTH_ENDPOINTS = [key for key in ENDPOINT_MODEL.keys() if key != 'actions'] def get(client, url, token=None): @@ -123,7 +125,7 @@ def test_login(client): assert 'access_token' in response.json -@pytest.mark.parametrize('endpoint', GENERIC_ENDPOINTS) +@pytest.mark.parametrize('endpoint', GENERIC_GET_ENDPOINTS) def test_get_generic_model(endpoint, session, client, readonly_token): model = ENDPOINT_MODEL[endpoint] names = ('Foo', 'Bar', 'Alice') @@ -146,7 +148,7 @@ def test_get_generic_model(endpoint, session, client, readonly_token): assert 'qrcode' not in item -@pytest.mark.parametrize('endpoint', ENDPOINTS) +@pytest.mark.parametrize('endpoint', CREATE_AUTH_ENDPOINTS) def test_create_model_auth_fail(endpoint, client, readonly_token): response = client.post(f'/api/{endpoint}') check_response_message(response, 'Missing Authorization Header', 401) @@ -158,7 +160,7 @@ def test_create_model_auth_fail(endpoint, client, readonly_token): assert model.query.count() == 0 -@pytest.mark.parametrize('endpoint', GENERIC_ENDPOINTS) +@pytest.mark.parametrize('endpoint', GENERIC_CREATE_ENDPOINTS) def test_create_generic_model(endpoint, client, user_token): response = post(client, f'/api/{endpoint}', data={}, token=user_token) check_response_message(response, "Missing mandatory field 'name'", 422)