Skip to content
Snippets Groups Projects
Commit 2f2a8a3a authored by Erik Reid's avatar Erik Reid
Browse files

added /classifier/infinera-dna-addresses route

parent 71d1556f
No related branches found
No related tags found
No related merge requests found
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])
......@@ -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(
......
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)
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