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

moved response schema from test to source

parent ac955ba3
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,40 @@ routes = Blueprint("inventory-data-default-routes", __name__)
API_VERSION = '0.1'
VERSION_SCHEMA = {
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"latch": {
"type": "object",
"properties": {
"current": {"type": "integer"},
"next": {"type": "integer"},
"this": {"type": "integer"},
"failure": {"type": "boolean"},
"pending": {"type": "boolean"},
},
"required": ["current", "next", "this", "pending", "failure"],
"additionalProperties": False
}
},
"type": "object",
"properties": {
"api": {
"type": "string",
"pattern": r'\d+\.\d+'
},
"module": {
"type": "string",
"pattern": r'\d+\.\d+'
},
"latch": {"$ref": "#/definitions/latch"}
},
"required": ["api", "module"],
"additionalProperties": False
}
@routes.after_request
def after_request(resp):
......@@ -17,6 +51,15 @@ def after_request(resp):
@routes.route("/version", methods=['GET', 'POST'])
@common.require_accepts_json
def version():
"""
Returns a json object with information about the module version.
The response will be formatted according to the following schema:
.. asjson:: inventory_provider.routes.default.VERSION_SCHEMA
:return:
"""
config = current_app.config["INVENTORY_PROVIDER_CONFIG"]
version_params = {
'api': API_VERSION,
......
......@@ -2,6 +2,7 @@ import json
import jsonschema
from inventory_provider.routes import common
from inventory_provider.routes.default import VERSION_SCHEMA
DEFAULT_REQUEST_HEADERS = {
"Content-type": "application/json",
......@@ -11,47 +12,13 @@ DEFAULT_REQUEST_HEADERS = {
def test_version_request(client, mocked_redis):
version_schema = {
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"latch": {
"type": "object",
"properties": {
"current": {"type": "integer"},
"next": {"type": "integer"},
"this": {"type": "integer"},
"failure": {"type": "boolean"},
"pending": {"type": "boolean"},
},
"required": ["current", "next", "this", "pending", "failure"],
"additionalProperties": False
}
},
"type": "object",
"properties": {
"api": {
"type": "string",
"pattern": r'\d+\.\d+'
},
"module": {
"type": "string",
"pattern": r'\d+\.\d+'
},
"latch": {"$ref": "#/definitions/latch"}
},
"required": ["api", "module"],
"additionalProperties": False
}
rv = client.post(
"version",
headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 200
jsonschema.validate(
json.loads(rv.data.decode("utf-8")),
version_schema)
VERSION_SCHEMA)
def test_load_json_docs(data_config, mocked_redis):
......
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