diff --git a/test/test_ims_general_data_routes.py b/test/test_ims_general_data_routes.py new file mode 100644 index 0000000000000000000000000000000000000000..038de3140d4ac16c9ec53a8a73a712e18afefa5e --- /dev/null +++ b/test/test_ims_general_data_routes.py @@ -0,0 +1,103 @@ +import contextlib +import json +import jsonschema + +DEFAULT_REQUEST_HEADERS = { + "Content-type": "application/json", + "Accept": ["application/json"] +} + + +def test_get_routers(ims_client): + version_schema = { + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "array", + "items": {"type": "string"} + } + + rv = ims_client.post( + "data/routers", + headers=DEFAULT_REQUEST_HEADERS) + assert rv.status_code == 200 + response = json.loads(rv.data.decode("utf-8")) + jsonschema.validate(response, version_schema) + assert response + + +def test_pop_info(ims_client): + """ + just check the correct method is called, but mock out all sql access + """ + expected_pop_info = [{ + "equipment-name": "MX1.LON.UK", + "status": "operational", + "pop": { + "name": "LONDON", + "abbreviation": "LON", + "country": "UNITED KINGDOM", + "city": "LONDON", + "longitude": -0.0152639, + "latitude": 51.4981657 + } + }] + + rv = ims_client.get( + '/data/pop/mx1.lon.uk.geant.net', + headers=DEFAULT_REQUEST_HEADERS) + + assert rv.status_code == 200 + assert rv.is_json + response = json.loads(rv.data.decode('utf-8')) + + assert response == expected_pop_info + + +def test_pop_not_found(ims_client, mocker): + """ + just check the correct method is called, but mock out all sql access + """ + + rv = ims_client.get( + '/data/pop/aabbcc', + headers=DEFAULT_REQUEST_HEADERS) + + assert rv.status_code == 404 + + +def test_router_interfaces_all(ims_client): + + interfaces_list_schema = { + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "array", + "items": { + "type": "object", + "properties": { + "name": {"type": "string"}, + "description": {"type": "string"}, + "router": {"type": "string"}, + "bundle": { + "type": "array", + "items": {"type": "string"} + }, + "ipv4": { + "type": "array", + "items": {"type": "string"} + }, + "ipv6": { + "type": "array", + "items": {"type": "string"} + } + }, + "required": ["name", "description", "ipv4", "router", "ipv6"], + "additionalProperties": False + } + } + + rv = ims_client.post( + '/orig-data/interfaces', + 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