diff --git a/inventory_provider/routes/data.py b/inventory_provider/routes/data.py index 9c9842d9ec2e32b921b585f8d5a66d7032934552..f63197b3ebb52b1023dce2d62ca83f99878fdf35 100644 --- a/inventory_provider/routes/data.py +++ b/inventory_provider/routes/data.py @@ -22,8 +22,12 @@ ROUTER_INTERFACES_SCHEMA = { "type": "object", "properties": { "name": {"type": "string"}, - "router": {"type": "string"}, "description": {"type": "string"}, + "router": {"type": "string"}, + "bundle": { + "type": "array", + "items": {"type": "string"} + }, "ipv4": { "type": "array", "items": {"type": "string"} @@ -31,9 +35,11 @@ ROUTER_INTERFACES_SCHEMA = { "ipv6": { "type": "array", "items": {"type": "string"} - } + }, + # only if not the default + "logical-system": {"type": "string"}, }, - "required": ["name", "description", "router", "ipv4", "ipv6"], + "required": ["name", "description", "ipv4", "router", "ipv6"], "additionalProperties": False } } diff --git a/test/per_router/test_data_routes.py b/test/per_router/test_data_routes.py index b795eb6ef3b9f1200c599613cde9c1ceaadd7701..4bc828acc39ce7faedb3b7ff0d206fec861ecca3 100644 --- a/test/per_router/test_data_routes.py +++ b/test/per_router/test_data_routes.py @@ -3,6 +3,7 @@ import json import pytest import jsonschema from inventory_provider.routes import msr +from inventory_provider.routes.data import ROUTER_INTERFACES_SCHEMA DEFAULT_REQUEST_HEADERS = { "Content-type": "application/json", @@ -11,41 +12,13 @@ DEFAULT_REQUEST_HEADERS = { def test_router_interfaces(router, client): - - interfaces_list_schema = { - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "array", - "items": { - "type": "object", - "properties": { - "name": {"type": "string"}, - "description": {"type": "string"}, - "router": {"type": "string"}, - "bundle": { - "type": "array", - "items": {"type": "string"} - }, - "ipv4": { - "type": "array", - "items": {"type": "string"} - }, - "ipv6": { - "type": "array", - "items": {"type": "string"} - } - }, - "required": ["name", "description", "ipv4", "router", "ipv6"], - "additionalProperties": False - } - } - rv = client.post( "/data/interfaces/" + router, headers=DEFAULT_REQUEST_HEADERS) assert rv.status_code == 200 response = json.loads(rv.data.decode("utf-8")) - jsonschema.validate(response, interfaces_list_schema) + jsonschema.validate(response, ROUTER_INTERFACES_SCHEMA) assert response # at least shouldn't be empty diff --git a/test/test_general_data_routes.py b/test/test_general_data_routes.py index a618f8fb2c7ff6a0e01530511ce3fba166ef9a23..ce98d99c28970eb74565ee0ba28b1aa984b27740 100644 --- a/test/test_general_data_routes.py +++ b/test/test_general_data_routes.py @@ -2,6 +2,9 @@ import contextlib import json import jsonschema +from inventory_provider.routes.data \ + import ROUTER_INTERFACES_SCHEMA, ROUTERS_RESPONSE_SCHEMA + DEFAULT_REQUEST_HEADERS = { "Content-type": "application/json", "Accept": ["application/json"] @@ -9,18 +12,12 @@ DEFAULT_REQUEST_HEADERS = { def test_get_routers(client): - version_schema = { - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "array", - "items": {"type": "string"} - } - rv = client.post( - "data/routers", + "/data/routers", headers=DEFAULT_REQUEST_HEADERS) assert rv.status_code == 200 response = json.loads(rv.data.decode("utf-8")) - jsonschema.validate(response, version_schema) + jsonschema.validate(response, ROUTERS_RESPONSE_SCHEMA) assert response @@ -79,38 +76,11 @@ def test_pop_not_found(client, mocker): def test_router_interfaces_all(client): - interfaces_list_schema = { - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "array", - "items": { - "type": "object", - "properties": { - "name": {"type": "string"}, - "description": {"type": "string"}, - "router": {"type": "string"}, - "bundle": { - "type": "array", - "items": {"type": "string"} - }, - "ipv4": { - "type": "array", - "items": {"type": "string"} - }, - "ipv6": { - "type": "array", - "items": {"type": "string"} - } - }, - "required": ["name", "description", "ipv4", "router", "ipv6"], - "additionalProperties": False - } - } - rv = client.post( '/data/interfaces', headers=DEFAULT_REQUEST_HEADERS) assert rv.status_code == 200 response = json.loads(rv.data.decode("utf-8")) - jsonschema.validate(response, interfaces_list_schema) + jsonschema.validate(response, ROUTER_INTERFACES_SCHEMA) assert response # at least shouldn't be empty diff --git a/test/test_general_routes.py b/test/test_general_routes.py index 228a5db470bc2d3a5607d8410b4e706bed31d1be..254d9db122b4d944bdd66df67f8a41e5ca67712c 100644 --- a/test/test_general_routes.py +++ b/test/test_general_routes.py @@ -30,6 +30,7 @@ def test_load_json_docs(data_config, mocked_redis): "interface": { "type": "object", "properties": { + "logical-system": {"type": "string"}, "name": {"type": "string"}, "description": {"type": "string"}, "bundle": {