Skip to content
Snippets Groups Projects
Commit e089f045 authored by Robert Latta's avatar Robert Latta
Browse files

added IMS client

parent 4d66f4b0
No related branches found
No related tags found
No related merge requests found
......@@ -80,29 +80,33 @@ class MockedRedis(object):
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())
MockedRedis.db['db:latch'] = json.dumps({
'current': 0,
'next': 0,
'this': 0,
'pending': False,
'failure': False
})
# remove any cached data from the captured snapshot
def _is_cache(s):
if s.startswith('classifier-cache'):
return True
if s.startswith('joblog'):
return True
return False
keys_to_delete = filter(_is_cache, MockedRedis.db.keys())
for k in list(keys_to_delete):
del MockedRedis.db[k]
MockedRedis.prep()
@staticmethod
def prep(data_source_file="router-info.json"):
test_data_filename = os.path.join(
TEST_DATA_DIRNAME,
data_source_file)
with open(test_data_filename) as f:
MockedRedis.db = json.loads(f.read())
MockedRedis.db['db:latch'] = json.dumps({
'current': 0,
'next': 0,
'this': 0,
'pending': False,
'failure': False
})
# remove any cached data from the captured snapshot
def _is_cache(s):
if s.startswith('classifier-cache'):
return True
if s.startswith('joblog'):
return True
return False
keys_to_delete = filter(_is_cache, MockedRedis.db.keys())
for k in list(keys_to_delete):
del MockedRedis.db[k]
def set(self, name, value):
MockedRedis.db[name] = value
......@@ -174,6 +178,22 @@ def client(flask_config_filename, data_config_filename, mocked_redis):
with inventory_provider.create_app().test_client() as c:
yield c
@pytest.fixture
def mocked_ims_redis(mocker):
MockedRedis.prep("router-info-ims.json")
mocker.patch(
'inventory_provider.tasks.common.redis.StrictRedis',
MockedRedis)
@pytest.fixture
def ims_client(flask_config_filename, data_config_filename, mocked_ims_redis):
os.environ['FLASK_SETTINGS_FILENAME'] = flask_config_filename
os.environ['INVENTORY_PROVIDER_CONFIG_FILENAME'] = data_config_filename
with inventory_provider.create_app().test_client() as c:
yield c
#
# @pytest.fixture
# def client(client, mocked_redis):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment