def validate_item(self): """Use the schema-items.json file to validate the populated item.""" # Create JSON out object to validate current_json = self.item_properties.construct_json() # Validate object with schema attached v = config.MyValidator(self.schema_data) v.validate(current_json) assert v.validate(current_json)
def validate_monster(self): """Use the schema-monsters.json file to validate the populated monster.""" # Create JSON out object to validate current_json = self.monster_properties.construct_json() # Validate object with schema attached v = config.MyValidator(self.schema_data) v.validate(current_json) if not v: print(current_json["id"], "ERROR...") print(v.errors) quit()
def validate_monster(self): """Use the schema-monsters.json file to validate the populated monster.""" # Create JSON out object to validate current_json = self.monster_properties.construct_json() # Validate object with schema attached v = config.MyValidator(self.schema_data) v.validate(current_json) # Print any validation errors if v.errors: print(v.errors) exit() assert v.validate(current_json)
def test_monsters_data(): """Unit test to check monsters database contents against JSON schema.""" # Read in the monster schema file path_to_schema = Path(config.DATA_SCHEMAS_PATH / "schema-monsters.json") with open(path_to_schema, 'r') as f: schema = json.loads(f.read()) # Validator object with schema attached v = config.MyValidator(schema) # Set the path to the monsters-json folder and get all the JSON files path_to_monsters_json_dir = Path(config.DOCS_PATH / "monsters-json") fis = path_to_monsters_json_dir.glob("*.json") fis = sorted(fis) # Validate each file for json_file in fis: with open(json_file) as fi: monster = json.load(fi) # print(monster["id"]) assert v.validate(monster)