From 93a009e027b72f02f30fd39618fa9d35a29d6f16 Mon Sep 17 00:00:00 2001 From: Gaurav Vaidya Date: Tue, 14 Sep 2021 19:08:21 -0400 Subject: [PATCH] Added test for JSON Schema validation. --- Pipfile | 1 + Pipfile.lock | 42 +++++++++++++++++++++++++++++--- tests/test_validate_artifacts.py | 7 +++++- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/Pipfile b/Pipfile index 9514b6039..ee9012c68 100644 --- a/Pipfile +++ b/Pipfile @@ -28,6 +28,7 @@ python-dotenv = "*" # For reading .env files. mike = "*" mkdocs-material = "*" assertpy = "*" +jsonschema = "*" [pipenv] allow_prereleases = true # added by migration to linkml model template diff --git a/Pipfile.lock b/Pipfile.lock index a929bb84d..94305a7cf 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "274b61ff41c3f0c22d638face999d9a605375a14c451f3b93422f7d17b53624e" + "sha256": "75997458519222b53271dfa4c3d8da8d7eee674d9b282a915a4898fef1273b37" }, "pipfile-spec": 6, "requires": {}, @@ -188,7 +188,7 @@ "sha256:9a6e76c9d1afc1b977374a5dc430a1ebb0ea0488205546d4678d6e31cc5f6801", "sha256:d2c132f8ba6276d794c66224c3297cec25c8079d0a4cf019c061611e0a3b94fa" ], - "markers": "python_full_version >= '3.7.0'", + "markers": "python_version >= '3.7'", "version": "==0.9.1" }, "idna": { @@ -227,7 +227,7 @@ "sha256:9a3d7c45e0b3636268efdb1a9d78734f0573e2a05ec4f00b6a677c69a63d1e3f", "sha256:af41c05fb15b6b9881faa95191e942e1387e305574b2269ebbecb4289173395b" ], - "markers": "python_full_version >= '3.7.0'", + "markers": "python_version >= '3.7'", "version": "==0.1.7" }, "jsonasobj": { @@ -513,7 +513,7 @@ "sha256:6f75e26dfda605c994031a72ca74b2b0079e1f7b12ab713e030078d8fa05dc3a", "sha256:ad83bb2a645f64becbf946d4bd170e35fd9b903616c7ee25d5a4ed188cf2d1dd" ], - "markers": "python_full_version >= '3.7.0'", + "markers": "python_version >= '3.7'", "version": "==0.8.3" }, "python-dateutil": { @@ -1055,6 +1055,13 @@ "markers": "python_version >= '3.6'", "version": "==3.0.1" }, + "jsonschema": { + "hashes": [ + "sha256:25ebdfe8a3c40974e318cdc250f2fbd6c9c86336c5a03710bb8256d019bb3630", + "sha256:6016b56a0f26b93162cfe2eb157fff34f46f631395327d7070c5b11162c0fc81" + ], + "version": "==4.0.0a6" + }, "keyring": { "hashes": [ "sha256:6334aee6073db2fb1f30892697b1730105b5e9a77ce7e61fca6b435225493efe", @@ -1326,6 +1333,33 @@ "index": "pypi", "version": "==2.4.7" }, + "pyrsistent": { + "hashes": [ + "sha256:097b96f129dd36a8c9e33594e7ebb151b1515eb52cceb08474c10a5479e799f2", + "sha256:2aaf19dc8ce517a8653746d98e962ef480ff34b6bc563fc067be6401ffb457c7", + "sha256:404e1f1d254d314d55adb8d87f4f465c8693d6f902f67eb6ef5b4526dc58e6ea", + "sha256:48578680353f41dca1ca3dc48629fb77dfc745128b56fc01096b2530c13fd426", + "sha256:4916c10896721e472ee12c95cdc2891ce5890898d2f9907b1b4ae0f53588b710", + "sha256:527be2bfa8dc80f6f8ddd65242ba476a6c4fb4e3aedbf281dfbac1b1ed4165b1", + "sha256:58a70d93fb79dc585b21f9d72487b929a6fe58da0754fa4cb9f279bb92369396", + "sha256:5e4395bbf841693eaebaa5bb5c8f5cdbb1d139e07c975c682ec4e4f8126e03d2", + "sha256:6b5eed00e597b5b5773b4ca30bd48a5774ef1e96f2a45d105db5b4ebb4bca680", + "sha256:73ff61b1411e3fb0ba144b8f08d6749749775fe89688093e1efef9839d2dcc35", + "sha256:772e94c2c6864f2cd2ffbe58bb3bdefbe2a32afa0acb1a77e472aac831f83427", + "sha256:773c781216f8c2900b42a7b638d5b517bb134ae1acbebe4d1e8f1f41ea60eb4b", + "sha256:a0c772d791c38bbc77be659af29bb14c38ced151433592e326361610250c605b", + "sha256:b29b869cf58412ca5738d23691e96d8aff535e17390128a1a52717c9a109da4f", + "sha256:c1a9ff320fa699337e05edcaae79ef8c2880b52720bc031b219e5b5008ebbdef", + "sha256:cd3caef37a415fd0dae6148a1b6957a8c5f275a62cca02e18474608cb263640c", + "sha256:d5ec194c9c573aafaceebf05fc400656722793dac57f254cd4741f3c27ae57b4", + "sha256:da6e5e818d18459fa46fac0a4a4e543507fe1110e808101277c5a2b5bab0cd2d", + "sha256:e79d94ca58fcafef6395f6352383fa1a76922268fa02caa2272fff501c2fdc78", + "sha256:f3ef98d7b76da5eb19c37fda834d50262ff9167c65658d1d8f974d2e4d90676b", + "sha256:f4c8cabb46ff8e5d61f56a037974228e978f26bfefce4f61a4b1ac0ba7a2ab72" + ], + "markers": "python_version >= '3.6'", + "version": "==0.18.0" + }, "pytest": { "hashes": [ "sha256:131b36680866a76e6781d13f101efb86cf674ebb9762eb70d3082b6f29889e89", diff --git a/tests/test_validate_artifacts.py b/tests/test_validate_artifacts.py index c59a5df31..944706532 100644 --- a/tests/test_validate_artifacts.py +++ b/tests/test_validate_artifacts.py @@ -1,7 +1,8 @@ import json import os.path import unittest -from assertpy import assert_that +from assertpy import assert_that, fail +import jsonschema MODEL_PATH = 'crdch_model' @@ -19,4 +20,8 @@ def test_validate_json_schema(self): json_schema = json.load(f) assert_that(json_schema).is_not_empty() + try: + jsonschema.Draft7Validator.check_schema(json_schema) + except jsonschema.exceptions.SchemaError as e: + fail(f'JSON Schema {json_schema_file_path} is not valid: {e}')