From 2990362d57166b36ea476e2b382b59b6b4a40374 Mon Sep 17 00:00:00 2001
From: Erik Reid <erik.reid@geant.org>
Date: Sun, 24 Jan 2021 13:35:52 +0100
Subject: [PATCH] moved response schema from test to source

---
 inventory_provider/routes/default.py | 43 ++++++++++++++++++++++++++++
 test/test_general_routes.py          | 37 ++----------------------
 2 files changed, 45 insertions(+), 35 deletions(-)

diff --git a/inventory_provider/routes/default.py b/inventory_provider/routes/default.py
index d7f1e897..f65d6124 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 116e89f4..228a5db4 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):
-- 
GitLab