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

initial poller route test

parent 7a30623c
No related branches found
No related tags found
No related merge requests found
...@@ -34,9 +34,15 @@ class MockedRedis(object): ...@@ -34,9 +34,15 @@ class MockedRedis(object):
MockedRedis.db[key] = value MockedRedis.db[key] = value
def hget(self, key, field): def hget(self, key, field):
if key == 'interface_services':
return json.dumps([
{'circuit_type': 'service', 'id': 9},
{'circuit_type': 'abc', 'id': 99},
{'circuit_type': 'xyz', 'id': 999},
{'circuit_type': 'service', 'id': 9999}
]).encode('utf-8')
value = MockedRedis.db[key] value = MockedRedis.db[key]
return value[field].encode('utf-8') return value[field].encode('utf-8')
# return json.dumps(value[field]).encode('utf-8')
def hgetall(self, key): def hgetall(self, key):
result = {} result = {}
...@@ -52,8 +58,8 @@ class MockedRedis(object): ...@@ -52,8 +58,8 @@ class MockedRedis(object):
@pytest.fixture @pytest.fixture
def client_with_mocked_data(mocker, client): def client_with_mocked_data(mocker, client):
mocker.patch( mocker.patch(
'inventory_provider.routes.data.redis.StrictRedis', 'inventory_provider.routes.classifier.db.get_redis',
MockedRedis) return_value=MockedRedis())
return client return client
...@@ -61,131 +67,42 @@ def test_router_interfaces(router, client_with_mocked_data): ...@@ -61,131 +67,42 @@ def test_router_interfaces(router, client_with_mocked_data):
interfaces_list_schema = { interfaces_list_schema = {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "http://json-schema.org/draft-07/schema#",
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {"type": "string"},
"description": {"type": "string"},
"ipv4": {
"type": "array",
"items": {"type": "string"}
},
"ipv6": {
"type": "array",
"items": {"type": "string"}
}
},
"required": ["name", "description", "ipv4", "ipv6"],
"additionalProperties": False
}
}
rv = client_with_mocked_data.post(
"/data/interfaces/" + router,
headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 200
response = json.loads(rv.data.decode("utf-8"))
jsonschema.validate(response, interfaces_list_schema)
assert response # at least shouldn't be empty
def test_snmp_ids(router, client_with_mocked_data):
snmp_id_list_schema = {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "array",
"items": {
"type": "object",
"properties": {
"index": {"type": "string"},
"name": {"type": "string"}
},
"required": ["index", "name"],
"additionalProperties": False
}
}
rv = client_with_mocked_data.post( "definitions": {
"/data/snmp/" + router, "circuit": {
headers=DEFAULT_REQUEST_HEADERS) "type": "object",
"properties": {
response = json.loads(rv.data.decode("utf-8")) "type": {"type": "string"},
jsonschema.validate(response, snmp_id_list_schema) "id": {"type": "integer"}
assert response # at least shouldn't be empty },
"required": ["type", "id"],
"additionalProperties": False
def test_router_bgp_routes(router, client_with_mocked_data): }
},
ROUTERS_WITH_BGP_CONFIG = [
"mx1.bud.hu.geant.net",
"mx1.pra.cz.geant.net",
"mx1.lon.uk.geant.net",
"mx1.vie.at.geant.net",
"mx1.ams.nl.geant.net",
"mx1.fra.de.geant.net",
"mx1.gen.ch.geant.net",
"mx1.mil2.it.geant.net",
"mx1.mad.es.geant.net",
"mx1.dub.ie.geant.net",
"mx1.mar.fr.geant.net"
]
if router not in ROUTERS_WITH_BGP_CONFIG:
pytest.skip('%s is not expected to have bgp peers' % router)
return
bgp_list_schema = {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "array", "type": "array",
"items": { "items": {
"type": "object", "type": "object",
"properties": { "properties": {
"name": {"type": "string"}, "circuits": {
"description": {"type": "string"}, "type": "array",
"as": { "items": {"$ref": "#/definitions/circuit"}
"type": "object",
"properties": {
"peer": {"type": "integer"},
"local": {"type": "integer"}
},
"required": ["peer", "local"],
"additionalProperties": False
}, },
"description": {"type": "string"},
"name": {"type": "string"},
"snmp-index": {"type": "integer"}
}, },
"required": ["description", "as", "name"], "required": ["circuits", "description", "name", "snmp-index"],
"additionalProperties": False "additionalProperties": False
} }
} }
rv = client_with_mocked_data.post( rv = client_with_mocked_data.post(
"/data/bgp/" + router, "/poller/interfaces/" + router,
headers=DEFAULT_REQUEST_HEADERS) headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 200 assert rv.status_code == 200
response = json.loads(rv.data.decode("utf-8")) response = json.loads(rv.data.decode("utf-8"))
jsonschema.validate(response, bgp_list_schema) jsonschema.validate(response, interfaces_list_schema)
assert response # at least shouldn't be empty assert response # at least shouldn't be empty
def test_router_debug_data_route(router, client_with_mocked_data):
"""
not really a test ... just providing coverage of temporary code used
for debugging (should be removed eventually)
:param router:
:param client_with_mocked_data:
:return:
"""
debug_data_schema = {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"items": {"type": "object"}
}
rv = client_with_mocked_data.post(
"/data/debug-dump/" + router,
headers=DEFAULT_REQUEST_HEADERS)
response = json.loads(rv.data.decode("utf-8"))
jsonschema.validate(response, debug_data_schema)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment