test_lg_routes.py 1.61 KiB
import json
import jsonschema
import pytest
from inventory_provider.routes.lg import LG_ROUTERS_SCHEMA
DEFAULT_REQUEST_HEADERS = {
"Content-type": "application/json",
"Accept": ["application/json"]
}
def test_public_routers(client):
rv = client.get(
'/lg/routers/public',
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, LG_ROUTERS_SCHEMA)
assert response_data # test data is non-empty
# no internal routers should be present
assert all(r['type'] == 'CORE' for r in response_data)
def test_internal_routers(client):
rv = client.get(
'/lg/routers/all',
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, LG_ROUTERS_SCHEMA)
assert response_data # test data is non-empty
# response should contain both public & internal routers
assert any(r['type'] == 'INTERNAL' for r in response_data)
assert any(r['type'] == 'CORE' for r in response_data)
@pytest.mark.parametrize('bad_endpoint', [
# bad access param keyword
'/lg/routers/ALL',
'/lg/routers/any',
'/lg/routers/internal',
# no access param keyword
'/lg/routers',
'/lg/routers/',
# other endpoints
'/lg',
'/lg/',
'/lg/something'
])
def test_bad_endpoints(client, bad_endpoint):
rv = client.get(
bad_endpoint,
headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 404