From 2a09da27e9828877f97b3498695f64c276953fa6 Mon Sep 17 00:00:00 2001 From: Erik Reid <erik.reid@geant.org> Date: Mon, 12 Nov 2018 16:43:12 +0100 Subject: [PATCH] validate version response format --- test/test_data_routes.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/test/test_data_routes.py b/test/test_data_routes.py index 3f469141..617e89e6 100644 --- a/test/test_data_routes.py +++ b/test/test_data_routes.py @@ -4,10 +4,11 @@ import os import tempfile import pytest +import jsonschema import inventory_provider -logging.basicConfig(level=logging.DEBUG) +# logging.basicConfig(level=logging.DEBUG) DEFAULT_REQUEST_HEADERS = { "Content-type": "application/json", @@ -132,10 +133,27 @@ def client(app_config): def test_version_request(client): + version_schema = { + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "api": { + "type": "string", + "pattern": r'\d+\.\d+' + }, + "module": { + "type": "string", + "pattern": r'\d+\.\d+' + } + }, + "required": ["api", "module"], + "additionalProperties": False + } + rv = client.post( "data/version", headers=DEFAULT_REQUEST_HEADERS) assert rv.status_code == 200 - logging.debug("rv.data: '%s'" % rv.data.decode("utf-8")) - print(rv.data.decode("utf-8")) - # validate(json.loads(rv.data.decode("utf-8")), SERVICES_SCHEMA) + jsonschema.validate( + json.loads(rv.data.decode("utf-8")), + version_schema) -- GitLab