From d86b8fe4f42935d3a6c5ac87679368854f7bc1a0 Mon Sep 17 00:00:00 2001
From: Erik Reid <erik.reid@geant.org>
Date: Thu, 30 Jan 2020 17:02:43 +0100
Subject: [PATCH] added unit test of opsdb.lookup_lg_routers

---
 inventory_provider/db/opsdb.py |  2 +-
 test/test_opsdb_queries.py     | 51 ++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/inventory_provider/db/opsdb.py b/inventory_provider/db/opsdb.py
index 41536113..3074c856 100644
--- a/inventory_provider/db/opsdb.py
+++ b/inventory_provider/db/opsdb.py
@@ -336,7 +336,7 @@ WHERE
     def _row2rsp(row):
         print(row)
         return {
-            'equipment-name': row['router_name'],
+            'equipment name': row['router_name'],
             'type': 'INTERNAL' if row['pop_name'] in INTERNAL_POP_NAMES else 'CORE',
             'pop': {
                 'name': row['pop_name'],
diff --git a/test/test_opsdb_queries.py b/test/test_opsdb_queries.py
index a268ccb7..dd45730e 100644
--- a/test/test_opsdb_queries.py
+++ b/test/test_opsdb_queries.py
@@ -144,6 +144,51 @@ CORIANT_PATH_METADATA = {
     "additionalProperties": False
 }
 
+LG_ROUTERS_SCHEMA = {
+    "$schema": "http://json-schema.org/draft-07/schema#",
+
+    "definitions": {
+        "pop-info": {
+            "type": "object",
+            "properties": {
+                "name": {"type": "string"},
+                "abbreviation": {"type": "string"},
+                "country": {"type": "string"},
+                "country code": {"type": "string"},
+                "city": {"type": "string"},
+                "longitude": {"type": "number"},
+                "latitude": {"type": "number"}
+            },
+            "required": [
+                "name",
+                "abbreviation",
+                "country",
+                "country code",
+                "city",
+                "longitude",
+                "latitude"
+            ],
+            "additionalProperties": False
+        },
+        "router": {
+            "type": "object",
+            "properties": {
+                "equipment name": {"type": "string"},
+                "type": {
+                    "type": "string",
+                    "enum": ["INTERNAL", "CORE"]
+                },
+                "pop": {"$ref": "#/definitions/pop-info"}
+            },
+            "required": ["equipment name", "type", "pop"],
+            "additionalProperties": False
+        }
+    },
+
+    "type": "array",
+    "items": {"$ref": "#/definitions/router"}
+}
+
 
 @pytest.mark.parametrize('equipment', [
     'mx1.cbg.uk.geant.net',
@@ -227,3 +272,9 @@ def test_get_all_service_users(connection, cached_test_data):
     #     services.setdefault(user['service_id'], []).append(user['user'])
     #
     # print([f'{k}: {v}' for k, v in services.items() if len(v) > 1])
+
+
+def test_lookup_lg_routers(connection, cached_test_data):
+    routers = list(opsdb.lookup_lg_routers(connection))
+    jsonschema.validate(routers, LG_ROUTERS_SCHEMA)
+    assert routers  # shouldn't be empty
-- 
GitLab