Last active
May 30, 2017 16:44
-
-
Save paulgoetze/fd0fe05344e4151f0c9317d1ad40c1e5 to your computer and use it in GitHub Desktop.
Testing Your Python API App with JSON Schema - tests/support/assertions.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# tests/support/assertions.py | |
import json | |
from os.path import join, dirname | |
from jsonschema import validate | |
def assert_valid_schema(data, schema_file): | |
""" Checks whether the given data matches the schema """ | |
schema = _load_json_schema(schema_file) | |
return validate(data, schema) | |
def _load_json_schema(filename): | |
""" Loads the given schema file """ | |
relative_path = join('schemas', filename) | |
absolute_path = join(dirname(__file__), relative_path) | |
with open(absolute_path) as schema_file: | |
return json.loads(schema_file.read()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment