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

updated unit tests

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