def __init__(self): super(RabbitMQingressProcessorTests, self).__init__(self.MODULE_NAME, self.PRIORITY) # Read in the actuator schema for validating messages fileName = os.path.join(RESOURCE_PATH + '/actuators', self.JSON_ACTUATOR_SCHEMA) with open(fileName, 'r') as f: _schema = f.read() # Remove tabs and newlines self._actuator_schema = json.loads(' '.join(_schema.split())) # Validate the schema Draft3Validator.check_schema(self._actuator_schema) # Read in the sensor schema for validating messages fileName = os.path.join(RESOURCE_PATH + '/sensors', self.JSON_SENSOR_SCHEMA) with open(fileName, 'r') as f: _schema = f.read() # Remove tabs and newlines self._sensor_schema = json.loads(' '.join(_schema.split())) # Validate the schema Draft3Validator.check_schema(self._sensor_schema)
def validate(self): try: Draft3Validator.check_schema(self.schema) except SchemaError as err: return 'schema is invalid: {}'.format(err) return None
def __init__(self): """Reads in the json schema for all actuator response messages""" super(BaseActuatorMsg, self).__init__() # Read in the schema for validating messages fileName = os.path.join(RESOURCE_PATH + '/actuators', self.JSON_ACTUATOR_SCHEMA) with open(fileName, 'r') as f: self._schema = json.load(f) # Validate the schema Draft3Validator.check_schema(self._schema)
def _load_schema(self, schema_file): """Loads a schema from a file and validates @param string schema_file location of schema on the file system @return string Trimmed and validated schema """ with open(schema_file, 'r') as f: schema = json.load(f) # Validate the schema to conform to Draft 3 specification Draft3Validator.check_schema(schema) return schema
def __init__(self): """Reads in the json schema for all sensor response messages""" super(BaseSensorMsg, self).__init__() # Read in the sensor schema for validating messages fileName = os.path.join(RESOURCE_PATH + '/sensors', self.JSON_SENSOR_SCHEMA) with open(fileName, 'r') as f: _schema = f.read() # Remove tabs and newlines self._schema = json.loads(' '.join(_schema.split())) # Validate the schema Draft3Validator.check_schema(self._schema)
def _load_schema(self, schema_file): """Loads a schema from a file and validates @param string schema_file location of schema on the file system @return string Trimmed and validated schema """ with open(schema_file, 'r') as f: schema = f.read() # Remove tabs and newlines schema_trimmed = json.loads(' '.join(schema.split())) # Validate the actuator schema Draft3Validator.check_schema(schema_trimmed) return schema_trimmed
def custom_endpoint_body_rules(self): if self.__input == "": return True try: data = json.loads(self.__input) except Exception as e: return False draft3 = True draft4 = True try: Draft3Validator.check_schema(data) except Exception as e: draft3 = False try: Draft4Validator.check_schema(data) except Exception as e: draft4 = False return draft3 or draft4
def test_0(self): """The schema is valid""" Draft3Validator.check_schema(self.widget.schema)
def test_schema_valid(self): """ The schema itself is a valid Draft 3 schema """ Draft3Validator.check_schema(group_schemas.policy)
def test_schema_valid(self): """ The schema itself is valid Draft 3 schema """ Draft3Validator.check_schema(group_schemas.config)
def test_schema_valid(self): """ The schema itself is a valid Draft 3 schema """ Draft3Validator.check_schema(rest_schemas.create_group_request)
msg = " check effect %s ... " % filename try: effect = json.loads(f.read()) script = path.basename(effect['script']) if not path.exists(jsonFiles + '/' + script): raise ValueError('script file: ' + script + ' not found.') schema = path.splitext(script)[0] + '.schema.json' if not path.exists(jsonFiles + '/schema/' + schema): raise ValueError('schema file: ' + schema + ' not found.') schema = jsonFiles + '/schema/' + schema # validate against schema with open(schema) as s: effectSchema = json.loads(s.read()) Draft3Validator.check_schema(effectSchema) validator = Draft3Validator(effectSchema) baseValidator.validate(effect) validator.validate(effect['args']) #print(msg + "ok") except Exception as e: print(msg + 'error (' + str(e) + ')') errors += 1 retval = 1 print(" checked effect files: %s success: %s errors: %s" % (total, (total - errors), errors)) sys.exit(retval)
msg = " check effect %s ... " % filename try: effect = json.loads(f.read()) script = path.basename(effect['script']) if not path.exists(jsonFiles+'/'+script): raise ValueError('script file: '+script+' not found.') schema = path.splitext(script)[0]+'.schema.json' if not path.exists(jsonFiles+'/schema/'+schema): raise ValueError('schema file: '+schema+' not found.') schema = jsonFiles+'/schema/'+schema # validate against schema with open(schema) as s: effectSchema = json.loads(s.read()) Draft3Validator.check_schema(effectSchema) validator = Draft3Validator(effectSchema) baseValidator.validate(effect) validator.validate(effect['args']) #print(msg + "ok") except Exception as e: print(msg + 'error ('+str(e)+')') errors += 1 retval = 1 print(" checked effect files: %s success: %s errors: %s" % (total,(total-errors),errors)) sys.exit(retval)
def test_schema_valid(self): """ The update webhook schema is valid JSON Schema Draft 3. """ Draft3Validator.check_schema(group_schemas.update_webhook)
# Loading example files client_example_file = open(WORKSPACE_DIR + "schema/communication/examples/client-message-example.json") server_example_file = open(WORKSPACE_DIR + "schema/communication/examples/server-message-example.json") client_configuration_example_file = open(WORKSPACE_DIR + "schema/configuration/examples/client-configuration-example.json") client_logging_example_file = open(WORKSPACE_DIR + "schema/communication/examples/client-logging-example.json") # Loading into JSON client_schema = json.load(client_schema_file) server_schema = json.load(server_schema_file) client_configuration_schema = json.load(client_configuration_schema_file) client_logging_schema = json.load(client_logging_schema_file) client_example = json.load(client_example_file) server_example = json.load(server_example_file) client_configuration_example = json.load(client_configuration_example_file) client_logging_example = json.load(client_logging_example_file) # Running verification logging.info("Testing schemes for compliance against the JSON Schema format") Draft3Validator.check_schema(client_schema) Draft3Validator.check_schema(server_schema) Draft3Validator.check_schema(client_configuration_schema) Draft3Validator.check_schema(client_logging_schema) logging.info("Testing example files for compliance against respective schemes") validate(client_example, client_schema) validate(server_example, server_schema) validate(client_configuration_example, client_configuration_schema) validate(client_logging_example, client_logging_schema)
# How do I validate a JSON Schema schema, in Python? from jsonschema import Draft3Validator my_schema = json.loads(my_text_file) #or however else you end up with a dict of the schema Draft3Validator.check_schema(schema)
# How do I validate a JSON Schema schema, in Python? from jsonschema import Draft3Validator my_schema = json.loads( my_text_file) #or however else you end up with a dict of the schema Draft3Validator.check_schema(schema)