Skip to content
Snippets Groups Projects
test_general_poller_routes.py 2.04 KiB
import json
import jsonschema
from inventory_provider.routes import poller

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


def test_get_all_interfaces(client):
    rv = client.get(
        '/poller/interfaces',
        headers=DEFAULT_REQUEST_HEADERS)
    assert rv.status_code == 200
    assert rv.is_json
    response_data = json.loads(rv.data.decode('utf-8'))
    jsonschema.validate(response_data, poller.INTERFACE_LIST_SCHEMA)
    response_routers = {ifc['router'] for ifc in response_data}
    assert len(response_routers) > 1, \
        'there should data from be lots of routers'


def test_all_router_interface_speeds(client):
    rv = client.post(
        '/poller/speeds',
        headers=DEFAULT_REQUEST_HEADERS)

    assert rv.status_code == 200
    response = json.loads(rv.data.decode("utf-8"))
    jsonschema.validate(response, poller.INTERFACE_SPEED_LIST_SCHEMA)
    assert response  # at least shouldn't be empty
    response_routers = {ifc['router'] for ifc in response}
    assert len(response_routers) > 1, \
        'there should data from be lots of routers'


def test_eumetsat_multicast(mocker, client):

    # routers don't have snmp acl's for us
    mocker.patch('inventory_provider.juniper.snmp_community_string') \
            .return_value = 'blah'

    rv = client.get(
        '/poller/eumetsat-multicast',
        headers=DEFAULT_REQUEST_HEADERS)
    assert rv.status_code == 200
    assert rv.is_json
    response_data = json.loads(rv.data.decode('utf-8'))
    jsonschema.validate(
        response_data, poller.MULTICAST_SUBSCRIPTION_LIST_SCHEMA)
    assert response_data, "the subscription list shouldn't be empty"


def test_gws_direct(client):

    rv = client.get(
        '/poller/gws/direct',
        headers=DEFAULT_REQUEST_HEADERS)
    assert rv.status_code == 200
    assert rv.is_json
    response_data = json.loads(rv.data.decode('utf-8'))
    jsonschema.validate(response_data, poller.GWS_DIRECT_DATA_SCHEMA)
    assert response_data, "the subscription list shouldn't be empty"