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

updated unit tests

parent 73b1925a
No related branches found
No related tags found
No related merge requests found
......@@ -17,7 +17,7 @@ def after_request(resp):
def _load_snmp_indexes(hostname=None):
result = dict()
key_pattern = f'snmp-interfaces:{hostname}' \
key_pattern = f'snmp-interfaces:{hostname}*' \
if hostname else 'snmp-interfaces:*'
for doc in common.load_json_docs(
......@@ -85,7 +85,7 @@ def _load_services(hostname=None):
return result
def _load_interfaces(hostname):
key_pattern = f'netconf:{hostname}' if hostname else 'netconf:*'
key_pattern = f'netconf:{hostname}*' if hostname else 'netconf:*'
for doc in common.load_xml_docs(
config_params=current_app.config['INVENTORY_PROVIDER_CONFIG'],
key_pattern=key_pattern,
......
......@@ -6,61 +6,63 @@ DEFAULT_REQUEST_HEADERS = {
"Accept": ["application/json"]
}
INTERFACE_LIST_SCHEMA = {
'$schema': 'http://json-schema.org/draft-07/schema#',
def test_router_interfaces(router, client):
interfaces_list_schema = {
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"circuit": {
"type": "object",
"properties": {
"name": {"type": "string"},
"status": {"type": "string"},
"type": {"type": "string"},
"id": {"type": "integer"}
},
"required": ["name", "status", "type", "id"],
"additionalProperties": False
}
'definitions': {
'service': {
'type': 'object',
'properties': {
'id': {'type': 'integer'},
'name': {'type': 'string'},
'type': {'type': 'string'},
'status': {'type': 'string'},
},
'required': ['id', 'name', 'type', 'status'],
'additionalProperties': False
},
"type": "array",
"items": {
"type": "object",
"properties": {
"circuits": {
"type": "array",
"items": {"$ref": "#/definitions/circuit"}
'interface': {
'type': 'object',
'properties': {
'router': {'type': 'string'},
'name': {'type': 'string'},
'description': {'type': 'string'},
'snmp-index': {
'type': 'integer',
'minimum': 1
},
"bundle": {
"type": "array",
"items": {"type": "string"}
'bundle': {
'type' : 'array',
'items': {'type': 'string'}
},
"bundle-parents": {
"type": "array",
"items": {"type": "string"}
'bundle-parents': {
'type': 'array',
'items': {'type': 'string'}
},
"description": {"type": "string"},
"name": {"type": "string"},
"snmp-index": {"type": "integer"}
'circuits': {
'type': 'array',
'items': {'$ref': '#/definitions/service'}
}
},
"required": [
"circuits",
"bundle",
"bundle-parents",
"description",
"name",
"snmp-index"],
"additionalProperties": False
}
}
'required': [
'router', 'name', 'description',
'snmp-index', 'bundle', 'bundle-parents',
'circuits'],
'additionalProperties': False
},
},
'type': 'array',
'items': {'$ref': '#/definitions/interface'}
}
def test_router_interfaces(router, client):
rv = client.post(
"/poller/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)
jsonschema.validate(response, INTERFACE_LIST_SCHEMA)
assert response # at least shouldn't be empty
......@@ -11,7 +11,7 @@ DEFAULT_REQUEST_HEADERS = {
}
INTERFACE_LIST_SCHEMA = {
SCHEMA_INTERFACE_LIST_SCHEMA = {
'$schema': 'http://json-schema.org/draft-07/schema#',
'definitions': {
......@@ -33,6 +33,56 @@ INTERFACE_LIST_SCHEMA = {
}
INTERFACE_LIST_SCHEMA = {
'$schema': 'http://json-schema.org/draft-07/schema#',
'definitions': {
'service': {
'type': 'object',
'properties': {
'id': {'type': 'integer'},
'name': {'type': 'string'},
'type': {'type': 'string'},
'status': {'type': 'string'},
},
'required': ['id', 'name', 'type', 'status'],
'additionalProperties': False
},
'interface': {
'type': 'object',
'properties': {
'router': {'type': 'string'},
'name': {'type': 'string'},
'description': {'type': 'string'},
'snmp-index': {
'type': 'integer',
'minimum': 1
},
'bundle': {
'type' : 'array',
'items': {'type': 'string'}
},
'bundle-parents': {
'type': 'array',
'items': {'type': 'string'}
},
'circuits': {
'type': 'array',
'items': {'$ref': '#/definitions/service'}
}
},
'required': [
'router', 'name', 'description',
'snmp-index', 'bundle', 'bundle-parents',
'circuits'],
'additionalProperties': False
},
},
'type': 'array',
'items': {'$ref': '#/definitions/interface'}
}
@pytest.mark.parametrize('category', ['mdvpn', 'lhcone', 'MDVpn', 'LHCONE'])
def test_service_category(client, mocked_worker_module, category):
worker._build_service_category_interface_list()
......@@ -42,7 +92,7 @@ def test_service_category(client, mocked_worker_module, category):
assert rv.status_code == 200
assert rv.is_json
response_data = json.loads(rv.data.decode('utf-8'))
jsonschema.validate(response_data, INTERFACE_LIST_SCHEMA)
jsonschema.validate(response_data, SCHEMA_INTERFACE_LIST_SCHEMA)
assert response_data, 'expected a non-empty list'
......@@ -60,3 +110,7 @@ def test_get_all_interfaces(client):
f'/poller/interfaces',
headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 200
assert rv.is_json
response_data = json.loads(rv.data.decode('utf-8'))
jsonschema.validate(response_data, INTERFACE_LIST_SCHEMA)
assert response_data, 'expected a non-empty list'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment