diff --git a/tests/fixtures/jsonschemas/v1-schema.json b/tests/fixtures/json-schemas/v1.json similarity index 96% rename from tests/fixtures/jsonschemas/v1-schema.json rename to tests/fixtures/json-schemas/v1.json index a74b7ec..a33bbc8 100644 --- a/tests/fixtures/jsonschemas/v1-schema.json +++ b/tests/fixtures/json-schemas/v1.json @@ -19,7 +19,7 @@ "pattern": "^PlaybookNode$" }, "id": { - "format": "^playbook_.+$", + "pattern": "^playbook_.+$", "type": "string" }, "name": { @@ -43,7 +43,7 @@ "type": "object", "properties": { "type": { - "format": "^PlayNode$", + "pattern": "^PlayNode$", "type": "string" }, "id": { @@ -173,6 +173,7 @@ } }, "include_role": { + "description": "Flag indicating if this role is an include role or not.", "type": "boolean" } }, diff --git a/tests/requirements_tests.txt b/tests/requirements_tests.txt index 262f25c..554fbc7 100644 --- a/tests/requirements_tests.txt +++ b/tests/requirements_tests.txt @@ -3,4 +3,5 @@ pytest==8.3.2 pytest-cov==5.0.0 pyquery==2.0.1 black~=24.8 -jq==1.8.0 \ No newline at end of file +jq==1.8.0 +jsonschema[format]==4.23.0 \ No newline at end of file diff --git a/tests/test_json_renderer.py b/tests/test_json_renderer.py index a22a181..e0136e4 100644 --- a/tests/test_json_renderer.py +++ b/tests/test_json_renderer.py @@ -4,6 +4,8 @@ import jq import pytest +from jsonschema import validate +from jsonschema.validators import Draft202012Validator from ansibleplaybookgrapher import __prog__ from ansibleplaybookgrapher.cli import PlaybookGrapherCLI @@ -68,6 +70,17 @@ def _common_tests( with open(json_path, "r") as f: output = json.load(f) + with open(os.path.join(FIXTURES_DIR, "json-schemas/v1.json")) as schema_file: + schema = json.load(schema_file) + + # If no exception is raised by validate(), the instance is valid. + # I currently don't use format but added it here to not forget to add in case I use in the future. + validate( + instance=output, + schema=schema, + format_checker=Draft202012Validator.FORMAT_CHECKER, + ) + playbooks = jq.compile(".playbooks[]").input(output).all() plays = jq.compile(".playbooks[].plays").input(output).first()