From 19a31026cf4d95791ee34f8a62409c337958e80c Mon Sep 17 00:00:00 2001
From: Erik Reid <erik.reid@geant.org>
Date: Thu, 4 Mar 2021 14:38:49 +0100
Subject: [PATCH] use updated schema for tests

---
 inventory_provider/routes/data.py   | 12 ++++++---
 test/per_router/test_data_routes.py | 31 ++-------------------
 test/test_general_data_routes.py    | 42 +++++------------------------
 test/test_general_routes.py         |  1 +
 4 files changed, 18 insertions(+), 68 deletions(-)

diff --git a/inventory_provider/routes/data.py b/inventory_provider/routes/data.py
index 9c9842d9..f63197b3 100644
--- a/inventory_provider/routes/data.py
+++ b/inventory_provider/routes/data.py
@@ -22,8 +22,12 @@ ROUTER_INTERFACES_SCHEMA = {
         "type": "object",
         "properties": {
             "name": {"type": "string"},
-            "router": {"type": "string"},
             "description": {"type": "string"},
+            "router": {"type": "string"},
+            "bundle": {
+                "type": "array",
+                "items": {"type": "string"}
+            },
             "ipv4": {
                 "type": "array",
                 "items": {"type": "string"}
@@ -31,9 +35,11 @@ ROUTER_INTERFACES_SCHEMA = {
             "ipv6": {
                 "type": "array",
                 "items": {"type": "string"}
-            }
+            },
+            # only if not the default
+            "logical-system": {"type": "string"},
         },
-        "required": ["name", "description", "router", "ipv4", "ipv6"],
+        "required": ["name", "description", "ipv4", "router", "ipv6"],
         "additionalProperties": False
     }
 }
diff --git a/test/per_router/test_data_routes.py b/test/per_router/test_data_routes.py
index b795eb6e..4bc828ac 100644
--- a/test/per_router/test_data_routes.py
+++ b/test/per_router/test_data_routes.py
@@ -3,6 +3,7 @@ import json
 import pytest
 import jsonschema
 from inventory_provider.routes import msr
+from inventory_provider.routes.data import ROUTER_INTERFACES_SCHEMA
 
 DEFAULT_REQUEST_HEADERS = {
     "Content-type": "application/json",
@@ -11,41 +12,13 @@ DEFAULT_REQUEST_HEADERS = {
 
 
 def test_router_interfaces(router, client):
-
-    interfaces_list_schema = {
-        "$schema": "http://json-schema.org/draft-07/schema#",
-        "type": "array",
-        "items": {
-            "type": "object",
-            "properties": {
-                "name": {"type": "string"},
-                "description": {"type": "string"},
-                "router": {"type": "string"},
-                "bundle": {
-                    "type": "array",
-                    "items": {"type": "string"}
-                },
-                "ipv4": {
-                    "type": "array",
-                    "items": {"type": "string"}
-                },
-                "ipv6": {
-                    "type": "array",
-                    "items": {"type": "string"}
-                }
-            },
-            "required": ["name", "description", "ipv4", "router", "ipv6"],
-            "additionalProperties": False
-        }
-    }
-
     rv = client.post(
         "/data/interfaces/" + router,
         headers=DEFAULT_REQUEST_HEADERS)
 
     assert rv.status_code == 200
     response = json.loads(rv.data.decode("utf-8"))
-    jsonschema.validate(response, interfaces_list_schema)
+    jsonschema.validate(response, ROUTER_INTERFACES_SCHEMA)
     assert response  # at least shouldn't be empty
 
 
diff --git a/test/test_general_data_routes.py b/test/test_general_data_routes.py
index a618f8fb..ce98d99c 100644
--- a/test/test_general_data_routes.py
+++ b/test/test_general_data_routes.py
@@ -2,6 +2,9 @@ import contextlib
 import json
 import jsonschema
 
+from inventory_provider.routes.data \
+    import ROUTER_INTERFACES_SCHEMA, ROUTERS_RESPONSE_SCHEMA
+
 DEFAULT_REQUEST_HEADERS = {
     "Content-type": "application/json",
     "Accept": ["application/json"]
@@ -9,18 +12,12 @@ DEFAULT_REQUEST_HEADERS = {
 
 
 def test_get_routers(client):
-    version_schema = {
-        "$schema": "http://json-schema.org/draft-07/schema#",
-        "type": "array",
-        "items": {"type": "string"}
-    }
-
     rv = client.post(
-        "data/routers",
+        "/data/routers",
         headers=DEFAULT_REQUEST_HEADERS)
     assert rv.status_code == 200
     response = json.loads(rv.data.decode("utf-8"))
-    jsonschema.validate(response, version_schema)
+    jsonschema.validate(response, ROUTERS_RESPONSE_SCHEMA)
     assert response
 
 
@@ -79,38 +76,11 @@ def test_pop_not_found(client, mocker):
 
 def test_router_interfaces_all(client):
 
-    interfaces_list_schema = {
-        "$schema": "http://json-schema.org/draft-07/schema#",
-        "type": "array",
-        "items": {
-            "type": "object",
-            "properties": {
-                "name": {"type": "string"},
-                "description": {"type": "string"},
-                "router": {"type": "string"},
-                "bundle": {
-                    "type": "array",
-                    "items": {"type": "string"}
-                },
-                "ipv4": {
-                    "type": "array",
-                    "items": {"type": "string"}
-                },
-                "ipv6": {
-                    "type": "array",
-                    "items": {"type": "string"}
-                }
-            },
-            "required": ["name", "description", "ipv4", "router", "ipv6"],
-            "additionalProperties": False
-        }
-    }
-
     rv = client.post(
         '/data/interfaces',
         headers=DEFAULT_REQUEST_HEADERS)
 
     assert rv.status_code == 200
     response = json.loads(rv.data.decode("utf-8"))
-    jsonschema.validate(response, interfaces_list_schema)
+    jsonschema.validate(response, ROUTER_INTERFACES_SCHEMA)
     assert response  # at least shouldn't be empty
diff --git a/test/test_general_routes.py b/test/test_general_routes.py
index 228a5db4..254d9db1 100644
--- a/test/test_general_routes.py
+++ b/test/test_general_routes.py
@@ -30,6 +30,7 @@ def test_load_json_docs(data_config, mocked_redis):
             "interface": {
                 "type": "object",
                 "properties": {
+                    "logical-system": {"type": "string"},
                     "name": {"type": "string"},
                     "description": {"type": "string"},
                     "bundle": {
-- 
GitLab