Skip to content
Snippets Groups Projects
Commit 7cb0f75c authored by Robert Latta's avatar Robert Latta
Browse files

general data route tests

parent bd55569a
No related branches found
No related tags found
No related merge requests found
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment