Skip to content
Snippets Groups Projects
Commit ef4fb50f authored by Benjamin Bertrand's avatar Benjamin Bertrand
Browse files

Add actions endpoint to API

parent a47c2c0b
No related branches found
No related tags found
No related merge requests found
...@@ -14,7 +14,7 @@ from flask import (current_app, Blueprint, jsonify, request) ...@@ -14,7 +14,7 @@ from flask import (current_app, Blueprint, jsonify, request)
from flask_jwt_extended import create_access_token, jwt_required from flask_jwt_extended import create_access_token, jwt_required
from flask_ldap3_login import AuthenticationResponseStatus from flask_ldap3_login import AuthenticationResponseStatus
from ..extensions import ldap_manager, db 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 .. import utils
from ..decorators import jwt_groups_accepted from ..decorators import jwt_groups_accepted
...@@ -174,6 +174,12 @@ def patch_item(id_): ...@@ -174,6 +174,12 @@ def patch_item(id_):
return jsonify(item.to_dict()) return jsonify(item.to_dict())
@bp.route('/actions')
@jwt_required
def get_actions():
return get_generic_model(Action, request.args)
@bp.route('/manufacturers') @bp.route('/manufacturers')
@jwt_required @jwt_required
def get_manufacturers(): def get_manufacturers():
......
...@@ -15,14 +15,16 @@ from app import models ...@@ -15,14 +15,16 @@ from app import models
ENDPOINT_MODEL = { ENDPOINT_MODEL = {
'actions': models.Action,
'manufacturers': models.Manufacturer, 'manufacturers': models.Manufacturer,
'models': models.Model, 'models': models.Model,
'locations': models.Location, 'locations': models.Location,
'status': models.Status, 'status': models.Status,
'items': models.Item, 'items': models.Item,
} }
GENERIC_ENDPOINTS = [key for key in ENDPOINT_MODEL.keys() if key != 'items'] GENERIC_GET_ENDPOINTS = [key for key in ENDPOINT_MODEL.keys() if key != 'items']
ENDPOINTS = list(ENDPOINT_MODEL.keys()) 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): def get(client, url, token=None):
...@@ -123,7 +125,7 @@ def test_login(client): ...@@ -123,7 +125,7 @@ def test_login(client):
assert 'access_token' in response.json 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): def test_get_generic_model(endpoint, session, client, readonly_token):
model = ENDPOINT_MODEL[endpoint] model = ENDPOINT_MODEL[endpoint]
names = ('Foo', 'Bar', 'Alice') names = ('Foo', 'Bar', 'Alice')
...@@ -146,7 +148,7 @@ def test_get_generic_model(endpoint, session, client, readonly_token): ...@@ -146,7 +148,7 @@ def test_get_generic_model(endpoint, session, client, readonly_token):
assert 'qrcode' not in item 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): def test_create_model_auth_fail(endpoint, client, readonly_token):
response = client.post(f'/api/{endpoint}') response = client.post(f'/api/{endpoint}')
check_response_message(response, 'Missing Authorization Header', 401) check_response_message(response, 'Missing Authorization Header', 401)
...@@ -158,7 +160,7 @@ def test_create_model_auth_fail(endpoint, client, readonly_token): ...@@ -158,7 +160,7 @@ def test_create_model_auth_fail(endpoint, client, readonly_token):
assert model.query.count() == 0 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): def test_create_generic_model(endpoint, client, user_token):
response = post(client, f'/api/{endpoint}', data={}, token=user_token) response = post(client, f'/api/{endpoint}', data={}, token=user_token)
check_response_message(response, "Missing mandatory field 'name'", 422) check_response_message(response, "Missing mandatory field 'name'", 422)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment