def __init__(self, version, name): self.raw_schema = utils.load_schema(version, name) self.validator = SchemaValidator(self.raw_schema, resolver=resolver)
def test_load_schema_missing(self): with self.assertRaises(exceptions.ResourceNotFound): utils.load_schema("v1", "missing")
for part in parts: part = part.replace("~1", "/").replace("~0", "~") if part not in document: raise jsonschema.RefResolutionError( "Unresolvable JSON pointer: %r" % fragment) document = document[part] return document # TODO: We shouldn't hard code this list.. Or define it half way down the page resolver = StaticResolver( store={ '/schemas/domain': utils.load_schema('v1', 'domain'), '/schemas/domains': utils.load_schema('v1', 'domains'), '/schemas/record': utils.load_schema('v1', 'record'), '/schemas/records': utils.load_schema('v1', 'records'), '/schemas/server': utils.load_schema('v1', 'server'), '/schemas/servers': utils.load_schema('v1', 'servers'), '/schemas/tsigkey': utils.load_schema('v1', 'tsigkey'), '/schemas/tsigkeys': utils.load_schema('v1', 'tsigkeys'), }) class SchemaValidator(jsonschema.Draft3Validator): def validate_type(self, types, instance, schema): # NOTE(kiall): A datetime object is not a string, but is still valid. if ('format' in schema and schema['format'] == 'date-time' and isinstance(instance, datetime)):
def test_load_schema(self): schema = utils.load_schema("v1", "domain") self.assertIsInstance(schema, dict)
def test_load_schema_missing(self): with self.assertRaises(exceptions.ResourceNotFound): utils.load_schema('v1', 'missing')
def test_load_schema(self): schema = utils.load_schema('v1', 'domain') self.assertIsInstance(schema, dict)
import jsonschema import ipaddr import iso8601 from datetime import datetime from moniker.openstack.common import log as logging from moniker import exceptions from moniker import utils LOG = logging.getLogger(__name__) # TODO: I'm sure there is a more accurate regex than this.. _RE_HOSTNAME = ('^(([a-zA-Z0-9_]|[a-zA-Z0-9_][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*' '([A-Za-z0-9_]|[A-Za-z0-9_][A-Za-z0-9\-]*[A-Za-z0-9])\.$') # TODO: We shouldn't hard code this list.. resolver = jsonschema.RefResolver(store={ '/schemas/domain': utils.load_schema('v1', 'domain'), '/schemas/domains': utils.load_schema('v1', 'domains'), '/schemas/record': utils.load_schema('v1', 'record'), '/schemas/records': utils.load_schema('v1', 'records'), '/schemas/server': utils.load_schema('v1', 'server'), '/schemas/servers': utils.load_schema('v1', 'servers'), }) class SchemaValidator(jsonschema.Draft3Validator): def validate_type(self, types, instance, schema): # NOTE(kiall): A datetime object is not a string, but is still valid. if ('format' in schema and schema['format'] == 'date-time' and isinstance(instance, datetime)): return