Skip to content
Snippets Groups Projects
Commit 5f1c6201 authored by Erik Reid's avatar Erik Reid
Browse files

added test of woerk update_equipment_locations

parent 5c31f17d
No related branches found
No related tags found
No related merge requests found
"""
just checks that the worker methods call the right functions
and some data ends up in the right place ... otherwise not very detailed
"""
import contextlib
from inventory_provider.tasks import worker
from inventory_provider.tasks.common import get_redis
def backend_db():
return get_redis({
'redis': {'hostname': None, 'port': None}
}).db
@contextlib.contextmanager
def _mocked_connection(x):
yield x
def test_update_locations(mocker, mocked_worker_module):
mocker.patch(
'inventory_provider.db.opsdb.lookup_pop_info',
lambda c, h: [{'C': c, 'H': h}])
mocker.patch(
'inventory_provider.db.db.connection',
_mocked_connection)
def _cached_locations():
db = backend_db()
for k in db.keys():
if k.startswith('opsdb:location:'):
yield k
db = backend_db()
for k in list(_cached_locations()):
del db[k]
assert len(list(_cached_locations())) == 0 # sanity
worker.update_equipment_locations()
assert len(list(_cached_locations())) > 0
for k in _cached_locations():
print(db[k])
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