Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
csentry
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Anders Harrisson
csentry
Commits
ef4fb50f
"examples/tty/serial.c" did not exist on "a9fbf2c2c3569292b28d54c4ef957ea2c7829fd3"
Commit
ef4fb50f
authored
7 years ago
by
Benjamin Bertrand
Browse files
Options
Downloads
Patches
Plain Diff
Add actions endpoint to API
parent
a47c2c0b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/api/main.py
+7
-1
7 additions, 1 deletion
app/api/main.py
tests/functional/test_api.py
+7
-5
7 additions, 5 deletions
tests/functional/test_api.py
with
14 additions
and
6 deletions
app/api/main.py
+
7
−
1
View file @
ef4fb50f
...
@@ -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
():
...
...
This diff is collapsed.
Click to expand it.
tests/functional/test_api.py
+
7
−
5
View file @
ef4fb50f
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment