From 457459fb7e9f1ec84dbf308bd15a20497f3ab46b Mon Sep 17 00:00:00 2001
From: Erik Reid <erik.reid@geant.org>
Date: Mon, 4 Feb 2019 13:37:46 +0100
Subject: [PATCH] add test for junosspace loading utility

---
 requirements.txt           |  1 +
 test/conftest.py           | 13 +++++--------
 test/test_junosspace_io.py | 26 ++++++++++++++++++++++++++
 3 files changed, 32 insertions(+), 8 deletions(-)
 create mode 100644 test/test_junosspace_io.py

diff --git a/requirements.txt b/requirements.txt
index 91780209..ff5a3796 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -12,3 +12,4 @@ requests
 
 pytest
 pytest-mock
+responses
diff --git a/test/conftest.py b/test/conftest.py
index 52fa1af3..748d607f 100644
--- a/test/conftest.py
+++ b/test/conftest.py
@@ -32,9 +32,6 @@ def data_config_filename(tmp_dir_name):
         "oid_list.conf": os.path.join(
             tmp_dir_name,
             "oid_list.conf"),
-        "routers_community.conf": os.path.join(
-            tmp_dir_name,
-            "routers_community.conf"),
         "ssh": {
             "username": "uSeR-NaMe",
             "private-key": "private-key-filename",
@@ -44,6 +41,11 @@ def data_config_filename(tmp_dir_name):
             "hostname": "xxxxxx",
             "port": 6379
         },
+        "junosspace": {
+            "api": "bogus-url",
+            "username": "bogus-username",
+            "password": "bogus-password"
+        },
         "infinera-dna": [
             {"name": "name1", "address": "123.456.789.0"},
             {"name": "name2", "address": "012.345.678.9"},
@@ -61,11 +63,6 @@ def data_config_filename(tmp_dir_name):
         config['oid_list.conf']
     )
 
-    shutil.copyfile(
-        os.path.join(TEST_DATA_DIRNAME, 'routers_community.conf'),
-        config['routers_community.conf']
-    )
-
     filename = os.path.join(tmp_dir_name, "config.json")
     with open(filename, "w") as f:
         f.write(json.dumps(config))
diff --git a/test/test_junosspace_io.py b/test/test_junosspace_io.py
new file mode 100644
index 00000000..39d82889
--- /dev/null
+++ b/test/test_junosspace_io.py
@@ -0,0 +1,26 @@
+import os
+
+import responses
+
+import inventory_provider
+from inventory_provider import juniper
+
+TEST_DATA_FILENAME = os.path.realpath(os.path.join(
+    inventory_provider.__path__[0],
+    '..',
+    'test',
+    'data',
+    'junosspace-devices.xml'))
+
+
+@responses.activate
+def test_junosspace_devices_parsing(data_config):
+    data_config['junosspace']['api'] = 'http://sabababa'
+    with open(TEST_DATA_FILENAME) as f:
+        responses.add(
+            method=responses.GET,
+            url = data_config['junosspace']['api'] + '/device-management/devices',
+            body=f.read())
+
+    doc = juniper.load_routers_from_junosspace(data_config['junosspace'])
+    assert doc
-- 
GitLab