Skip to content

Instantly share code, notes, and snippets.

@paulgoetze
Last active May 30, 2017 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulgoetze/fd0fe05344e4151f0c9317d1ad40c1e5 to your computer and use it in GitHub Desktop.
Save paulgoetze/fd0fe05344e4151f0c9317d1ad40c1e5 to your computer and use it in GitHub Desktop.
Testing Your Python API App with JSON Schema - tests/support/assertions.py
# 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