Skip to content
Snippets Groups Projects
test_testing_routes.py 2.39 KiB
Newer Older
import json
import jsonschema

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

ROUTER_LIST_SCHEMA = {
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "array",
    "items": {"type": "string"}
}

Erik Reid's avatar
Erik Reid committed

def test_flushdb(client):
    rv = client.post("/testing/flushdb")
Erik Reid's avatar
Erik Reid committed
    assert rv.status_code == 200
def test_juniper_addresses(client):
    rv = client.post(
        "/testing/juniper-server-addresses",
        headers=DEFAULT_REQUEST_HEADERS)
    assert rv.status_code == 200
    response_data = json.loads(rv.data.decode('utf-8'))
    jsonschema.validate(response_data, ROUTER_LIST_SCHEMA)
    assert len(response_data) > 0  # test data is not empty


def test_get_equipment_location(client_with_mocked_data):
    rv = client_with_mocked_data.get(
        '/testing/opsdb/equipment-location',
        headers=DEFAULT_REQUEST_HEADERS)
    assert rv.status_code == 200
    assert rv.is_json
    # TODO: validate against schema


def test_get_interface_info(client_with_mocked_data):
    rv = client_with_mocked_data.get(
        '/testing/opsdb/interfaces',
        headers=DEFAULT_REQUEST_HEADERS)
    assert rv.status_code == 200
    assert rv.is_json
    # TODO: validate against schema


def test_get_interface_info_for_equipment(client_with_mocked_data):
    rv = client_with_mocked_data.get(
        '/testing/opsdb/interfaces/mx1.ams.nl.geant.net',
        headers=DEFAULT_REQUEST_HEADERS)
    assert rv.status_code == 200
    assert rv.is_json
    # TODO: validate against schema


def test_get_interface_info_for_equipment_and_interface(
            client_with_mocked_data):
    rv = client_with_mocked_data.get(
        '/testing/opsdb/interfaces/mx1.ams.nl.geant.net/ae0.0',
        headers=DEFAULT_REQUEST_HEADERS)
    assert rv.status_code == 200
    assert rv.is_json
    # TODO: validate against schema


def test_get_children(client_with_mocked_data):
    rv = client_with_mocked_data.get(
        '/testing/opsdb/circuit-hierarchy/children/12363',
        headers=DEFAULT_REQUEST_HEADERS)
    assert rv.status_code == 200
    assert rv.is_json
    # TODO: validate against schema


def test_get_parents(client_with_mocked_data):
    rv = client_with_mocked_data.get(
        '/testing/opsdb/circuit-hierarchy/parents/11725',
        headers=DEFAULT_REQUEST_HEADERS)
    assert rv.status_code == 200
    assert rv.is_json
    # TODO: validate against schema