Skip to content
Snippets Groups Projects
test_general_data_routes.py 1.77 KiB
import json
import jsonschema

from inventory_provider.routes.data \
    import ROUTER_INTERFACES_SCHEMA, ROUTERS_RESPONSE_SCHEMA

DEFAULT_REQUEST_HEADERS = {
    "Content-type": "application/json",
    "Accept": ["application/json"]
}


def test_get_routers(client):
    rv = client.post(
        "/data/routers",
        headers=DEFAULT_REQUEST_HEADERS)
    assert rv.status_code == 200
    response = json.loads(rv.data.decode("utf-8"))
    jsonschema.validate(response, ROUTERS_RESPONSE_SCHEMA)
    assert response


def test_pop_info(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 = 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(client):
    """
    just check the correct method is called, but mock out all sql access
    """

    rv = client.get(
        '/data/pop/aabbcc',
        headers=DEFAULT_REQUEST_HEADERS)

    assert rv.status_code == 404


def test_router_interfaces_all(client):

    rv = client.post(
        '/data/interfaces',
        headers=DEFAULT_REQUEST_HEADERS)

    assert rv.status_code == 200
    response = json.loads(rv.data.decode("utf-8"))
    jsonschema.validate(response, ROUTER_INTERFACES_SCHEMA)
    assert response  # at least shouldn't be empty