-
Robert Latta authoredRobert Latta authored
test_junosspace_io.py 1.45 KiB
import os
import re
import responses
import inventory_provider
from inventory_provider import juniper
from inventory_provider.tasks import worker
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())
routers = juniper.load_routers_from_junosspace(data_config['junosspace'])
hostnames = [r['hostname'] for r in routers]
# test for .re\d+ greediness
assert 'mx1.ams.nl.geant.net' in hostnames
# test that 'qfx1.fra.de' is parsed
assert 'qfx1.fra.de.geant.net' in hostnames
def test_router_hostname_derivation(mocked_redis):
"""
test result depends specifically on the test data set containing
a realistic snapshot
:param mocked_redis:
:return:
"""
config = {
'redis': {
'hostname': None,
'port': None
},
'redis-databases': [0, 11]
}
hostnames = list(worker._derive_router_hostnames(config))
assert hostnames # test data is non-empty
for h in hostnames:
assert re.match(r'^(mx[12]|qfx).+\.geant\.net$', h)