Skip to content
Snippets Groups Projects
Commit 19a31026 authored by Erik Reid's avatar Erik Reid
Browse files

use updated schema for tests

parent 8da81f7b
No related branches found
No related tags found
No related merge requests found
...@@ -22,8 +22,12 @@ ROUTER_INTERFACES_SCHEMA = { ...@@ -22,8 +22,12 @@ ROUTER_INTERFACES_SCHEMA = {
"type": "object", "type": "object",
"properties": { "properties": {
"name": {"type": "string"}, "name": {"type": "string"},
"router": {"type": "string"},
"description": {"type": "string"}, "description": {"type": "string"},
"router": {"type": "string"},
"bundle": {
"type": "array",
"items": {"type": "string"}
},
"ipv4": { "ipv4": {
"type": "array", "type": "array",
"items": {"type": "string"} "items": {"type": "string"}
...@@ -31,9 +35,11 @@ ROUTER_INTERFACES_SCHEMA = { ...@@ -31,9 +35,11 @@ ROUTER_INTERFACES_SCHEMA = {
"ipv6": { "ipv6": {
"type": "array", "type": "array",
"items": {"type": "string"} "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 "additionalProperties": False
} }
} }
......
...@@ -3,6 +3,7 @@ import json ...@@ -3,6 +3,7 @@ import json
import pytest import pytest
import jsonschema import jsonschema
from inventory_provider.routes import msr from inventory_provider.routes import msr
from inventory_provider.routes.data import ROUTER_INTERFACES_SCHEMA
DEFAULT_REQUEST_HEADERS = { DEFAULT_REQUEST_HEADERS = {
"Content-type": "application/json", "Content-type": "application/json",
...@@ -11,41 +12,13 @@ DEFAULT_REQUEST_HEADERS = { ...@@ -11,41 +12,13 @@ DEFAULT_REQUEST_HEADERS = {
def test_router_interfaces(router, client): 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( rv = client.post(
"/data/interfaces/" + router, "/data/interfaces/" + router,
headers=DEFAULT_REQUEST_HEADERS) headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 200 assert rv.status_code == 200
response = json.loads(rv.data.decode("utf-8")) 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 assert response # at least shouldn't be empty
......
...@@ -2,6 +2,9 @@ import contextlib ...@@ -2,6 +2,9 @@ import contextlib
import json import json
import jsonschema import jsonschema
from inventory_provider.routes.data \
import ROUTER_INTERFACES_SCHEMA, ROUTERS_RESPONSE_SCHEMA
DEFAULT_REQUEST_HEADERS = { DEFAULT_REQUEST_HEADERS = {
"Content-type": "application/json", "Content-type": "application/json",
"Accept": ["application/json"] "Accept": ["application/json"]
...@@ -9,18 +12,12 @@ DEFAULT_REQUEST_HEADERS = { ...@@ -9,18 +12,12 @@ DEFAULT_REQUEST_HEADERS = {
def test_get_routers(client): def test_get_routers(client):
version_schema = {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "array",
"items": {"type": "string"}
}
rv = client.post( rv = client.post(
"data/routers", "/data/routers",
headers=DEFAULT_REQUEST_HEADERS) headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 200 assert rv.status_code == 200
response = json.loads(rv.data.decode("utf-8")) response = json.loads(rv.data.decode("utf-8"))
jsonschema.validate(response, version_schema) jsonschema.validate(response, ROUTERS_RESPONSE_SCHEMA)
assert response assert response
...@@ -79,38 +76,11 @@ def test_pop_not_found(client, mocker): ...@@ -79,38 +76,11 @@ def test_pop_not_found(client, mocker):
def test_router_interfaces_all(client): 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( rv = client.post(
'/data/interfaces', '/data/interfaces',
headers=DEFAULT_REQUEST_HEADERS) headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 200 assert rv.status_code == 200
response = json.loads(rv.data.decode("utf-8")) 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 assert response # at least shouldn't be empty
...@@ -30,6 +30,7 @@ def test_load_json_docs(data_config, mocked_redis): ...@@ -30,6 +30,7 @@ def test_load_json_docs(data_config, mocked_redis):
"interface": { "interface": {
"type": "object", "type": "object",
"properties": { "properties": {
"logical-system": {"type": "string"},
"name": {"type": "string"}, "name": {"type": "string"},
"description": {"type": "string"}, "description": {"type": "string"},
"bundle": { "bundle": {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment