def test_dynamic_schemas_against_generated(self):
     """This test checks that previously generated schemas haven't changed
     by later modifications to the Python definitions.
     When you define new schemas or new versions of schemas, you'll need
     to run data/schemas/generate.py to get them generated.
     """
     all_schemas = load_all_server_schemas()
     test_library = BundledSchemaLibrary(self.schemas_path, __package__)
     for ref, schema in all_schemas.items():
         assert test_library.load_schema(ref) == schema
 def test_get_server_schemas(self, accept_json):
     """Test that all server schemas are provided in all versions through the API."""
     for schema_ref, _ in load_all_server_schemas().items():
         path = api_route_for('/schemas/api/{}/{}'.format(
             schema_ref.name, schema_ref.version))
         res = self.client.get(path, headers=accept_json)
         assert res.status_code == 200
         received_schema = res.json
         self._check_schema_id(received_schema, path)
         received_schema.pop('id')
         json_path = os.path.join(
             os.path.abspath(os.path.dirname(__file__)), 'data', 'schemas',
             '{}-v{}.schema.json'.format(schema_ref.name,
                                         schema_ref.version))
         with open(json_path) as f:
             assert received_schema == json.load(f)
#!/usr/bin/env python3
from collections import OrderedDict
import json
import os
import sys

if sys.version_info[0] < 3:
    print('Must be run under Python 3, since Python 2 adds trailing whitespaces to JSON')
    sys.exit(1)

from bayesian.schemas import load_all_server_schemas

here = os.path.dirname(__file__)

for ref, schema in load_all_server_schemas().items():
    # we don't want to overwrite previously generated schemas
    fname = os.path.join(here, '{}-v{}.schema.json'.format(*ref))
    if os.path.exists(fname):
        print('{} already exists, skipping'.format(fname))
        continue
    if 'definitions' in schema:
        definitions = schema['definitions'].items()
        schema['definitions'] = OrderedDict(sorted(definitions))
    # write schema
    with open(fname, 'w') as f:
        json.dump(schema, f, indent=4)