Skip to content
Snippets Groups Projects
test_neteng_routes.py 1.67 KiB
import json
import jsonschema
import pytest

from inventory_provider.db.ims_data \
    import NODE_LOCATION_SCHEMA, POP_LOCATION_SCHEMA
from inventory_provider.routes.neteng import STRING_LIST_SCHEMA


@pytest.mark.parametrize('equipment_name', [
    'MX1.AMS.NL',
    'MIL-OLA1',
    'LON02-GRV1'
])
def test_location(client, mocked_redis, equipment_name):
    rv = client.get(
        f'/neteng/location/{equipment_name}',
        headers={'Accept': ['application/json']})
    assert rv.status_code == 200
    jsonschema.validate(
        json.loads(rv.data.decode('utf-8')),
        NODE_LOCATION_SCHEMA)


def test_location_not_found(client, mocked_redis):
    rv = client.get(
        '/neteng/location/BOGUS.EQUIPMENT.NAME',
        headers={'Accept': ['application/json']})
    assert rv.status_code == 404


def test_get_pops(client, mocked_redis):
    rv = client.get(
        '/neteng/pops',
        headers={'Accept': ['application/json']})
    assert rv.status_code == 200
    jsonschema.validate(
        json.loads(rv.data.decode('utf-8')),
        STRING_LIST_SCHEMA)


@pytest.mark.parametrize('pop_name', [
    'AMS', 'LON', 'COR', 'ORB', 'ORBE',
])
def test_pop_location(client, mocked_redis, pop_name):
    rv = client.get(
        f'/neteng/pop/{pop_name}',
        headers={'Accept': ['application/json']})
    assert rv.status_code == 200
    jsonschema.validate(
        json.loads(rv.data.decode('utf-8')),
        POP_LOCATION_SCHEMA)
    s = json.loads(rv.data.decode('utf-8'))
    print(s)


def test_pop_not_found(client, mocked_redis):
    rv = client.get(
        '/neteng/pop/BOGUS.POP.ABBREV',
        headers={'Accept': ['application/json']})
    assert rv.status_code == 404