Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inventory-provider
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
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
geant-swd
dashboardv3
inventory-provider
Commits
2f2a8a3a
Commit
2f2a8a3a
authored
6 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
added /classifier/infinera-dna-addresses route
parent
71d1556f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
inventory_provider/routes/classifier.py
+33
-0
33 additions, 0 deletions
inventory_provider/routes/classifier.py
test/conftest.py
+6
-1
6 additions, 1 deletion
test/conftest.py
test/test_classifier_routes.py
+24
-0
24 additions, 0 deletions
test/test_classifier_routes.py
with
63 additions
and
1 deletion
inventory_provider/routes/classifier.py
0 → 100644
+
33
−
0
View file @
2f2a8a3a
import
functools
from
flask
import
Blueprint
,
request
,
Response
,
current_app
,
jsonify
routes
=
Blueprint
(
"
inventory-data-classifier-support-routes
"
,
__name__
)
def
require_accepts_json
(
f
):
"""
used as a route handler decorator to return an error
unless the request allows responses with type
"
application/json
"
:param f: the function to be decorated
:return: the decorated function
"""
@functools.wraps
(
f
)
def
decorated_function
(
*
args
,
**
kwargs
):
# TODO: use best_match to disallow */* ...?
if
not
request
.
accept_mimetypes
.
accept_json
:
return
Response
(
response
=
"
response will be json
"
,
status
=
406
,
mimetype
=
"
text/html
"
)
return
f
(
*
args
,
**
kwargs
)
return
decorated_function
@routes.route
(
"
/infinera-dna-addresses
"
,
methods
=
[
'
GET
'
,
'
POST
'
])
@require_accepts_json
def
infinera_addresses
():
infinera_config
=
current_app
.
config
[
"
INVENTORY_PROVIDER_CONFIG
"
][
"
infinera-dna
"
]
return
jsonify
([
dna
[
'
address
'
]
for
dna
in
infinera_config
])
This diff is collapsed.
Click to expand it.
test/conftest.py
+
6
−
1
View file @
2f2a8a3a
...
...
@@ -42,7 +42,12 @@ def data_config_filename(tmp_dir_name):
"
redis
"
:
{
"
hostname
"
:
"
xxxxxx
"
,
"
port
"
:
6379
}
},
"
infinera-dna
"
:
[
{
"
name
"
:
"
name1
"
,
"
address
"
:
"
123.456.789.0
"
},
{
"
name
"
:
"
name2
"
,
"
address
"
:
"
012.345.678.9
"
},
{
"
name
"
:
"
name3
"
,
"
address
"
:
"
111.222.333.000
"
}
]
}
shutil
.
copyfile
(
...
...
This diff is collapsed.
Click to expand it.
test/test_classifier_routes.py
0 → 100644
+
24
−
0
View file @
2f2a8a3a
import
json
import
jsonschema
DEFAULT_REQUEST_HEADERS
=
{
"
Content-type
"
:
"
application/json
"
,
"
Accept
"
:
[
"
application/json
"
]
}
def
test_version_request
(
client
):
response_schema
=
{
"
$schema
"
:
"
http://json-schema.org/draft-07/schema#
"
,
"
type
"
:
"
array
"
,
"
items
"
:
{
"
type
"
:
"
string
"
}
}
rv
=
client
.
post
(
"
/classifier/infinera-dna-addresses
"
,
headers
=
DEFAULT_REQUEST_HEADERS
)
assert
rv
.
status_code
==
200
jsonschema
.
validate
(
json
.
loads
(
rv
.
data
.
decode
(
"
utf-8
"
)),
response_schema
)
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