import json
import jsonschema
from inventory_provider.routes.poller import INTERFACE_LIST_SCHEMA

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, 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'