From 5c31f17ddbd8e891c8daa590762a459f64d7baba Mon Sep 17 00:00:00 2001
From: Erik Reid <erik.reid@geant.org>
Date: Sat, 13 Apr 2019 11:54:32 +0200
Subject: [PATCH] merged duplicate MockedRedis classes

---
 test/conftest.py            | 20 +++++++++++++++++
 test/per_router/conftest.py | 45 -------------------------------------
 2 files changed, 20 insertions(+), 45 deletions(-)

diff --git a/test/conftest.py b/test/conftest.py
index 17fa67de..35b5f122 100644
--- a/test/conftest.py
+++ b/test/conftest.py
@@ -109,6 +109,26 @@ class MockedRedis(object):
             return None
         return value.encode('utf-8')
 
+    def delete(self, key):
+        if isinstance(key, bytes):
+            key = key.decode('utf-8')
+        del MockedRedis.db[key]
+
+    def scan_iter(self, glob=None):
+        if not glob:
+            for k in MockedRedis.db.keys():
+                yield k.encode('utf-8')
+
+        m = re.match(r'^([^*]+)\*$', glob)
+        assert m  # all expected globs are like this
+        for k in MockedRedis.db.keys():
+            if k.startswith(m.group(1)):
+                yield k.encode('utf-8')
+
+    def keys(self, glob=None):
+        return list(self.scan_iter(glob))
+
+
     def keys(self, glob=None):
         if not glob:
             return list([k.encode("utf-8") for k in MockedRedis.db.keys()])
diff --git a/test/per_router/conftest.py b/test/per_router/conftest.py
index 798252d3..60d82aec 100644
--- a/test/per_router/conftest.py
+++ b/test/per_router/conftest.py
@@ -15,42 +15,6 @@ TEST_DATA_DIRNAME = os.path.realpath(os.path.join(
     "data"))
 
 
-class MockedRedis(object):
-
-    db = None
-
-    def __init__(self, *args, **kwargs):
-        if MockedRedis.db is None:
-            test_data_filename = os.path.join(
-                TEST_DATA_DIRNAME,
-                "router-info.json")
-            with open(test_data_filename) as f:
-                MockedRedis.db = json.loads(f.read())
-
-    def set(self, name, value):
-        MockedRedis.db[name] = value
-
-    def get(self, name):
-        value = MockedRedis.db.get(name, None)
-        if value is None:
-            return None
-        return value.encode('utf-8')
-
-    def keys(self, glob=None):
-        if not glob:
-            return list([k.encode("utf-8") for k in MockedRedis.db.keys()])
-        m = re.match(r'^([^*]+)\*$', glob)
-        assert m  # all expected global are like this
-        return list([
-            k.encode("utf-8") for k in MockedRedis.db.keys()
-            if k.startswith(m.group(1))])
-
-    def delete(self, key):
-        if isinstance(key, bytes):
-            key = key.decode('utf-8')
-        del MockedRedis.db[key]
-
-
 @pytest.fixture
 def classifier_cache_test_entries():
     filename = os.path.join(
@@ -58,15 +22,6 @@ def classifier_cache_test_entries():
     with open(filename) as f:
         return json.loads(f.read())
 
-
-@pytest.fixture
-def mocked_redis(mocker):
-    mocker.patch(
-        'inventory_provider.tasks.common.redis.StrictRedis',
-        MockedRedis)
-    return MockedRedis()
-
-
 def pytest_generate_tests(metafunc):
 
     def _junosspace_hosts():
-- 
GitLab