diff --git a/inventory_provider/routes/default.py b/inventory_provider/routes/default.py index d7f1e897ed91f982a69b6a1d56f29f5fac471cad..f65d6124835c09f70459f9d2defe01a36e23dbd6 100644 --- a/inventory_provider/routes/default.py +++ b/inventory_provider/routes/default.py @@ -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, diff --git a/test/test_general_routes.py b/test/test_general_routes.py index 116e89f412329b2d053bcafe6531f55e12398e40..228a5db470bc2d3a5607d8410b4e706bed31d1be 100644 --- a/test/test_general_routes.py +++ b/test/test_general_routes.py @@ -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):