def test_convert_schema_to_latest(self): schema_v1 = _schema_dict(DATA_DIRECTORY, GOOD_SCHEMA_V1_PATH) assert schema_v1['version'] == 1 newest_schema = schema.convert_to_latest_version(schema_v1) schema.validate_schema_dict(newest_schema) assert newest_schema['version'] == max( schema.MASTER_SCHEMA_FILE_NAMES.keys())
def convert_schema(schema_json, output): """convert the given schema file to the latest version. """ schema_dict = json.load(schema_json) validate_schema_dict(schema_dict) new_schema_dict = convert_to_latest_version(schema_dict, validate_result=True) json.dump(new_schema_dict, output)
def test_schema_conversion(self): schema_v1 = _schema_dict(DATA_DIRECTORY, GOOD_SCHEMA_V1_PATH) assert schema_v1['version'] == 1 schema_v2 = schema._convert_v1_to_v2(schema_v1) assert schema_v2['version'] == 2 schema.validate_schema_dict(schema_v2) schema_v3 = schema._convert_v2_to_v3(schema_v2) assert schema_v3['version'] == 3 schema.validate_schema_dict(schema_v3)
def test_missing_master(self): # This shouldn't happen but we need to be able to handle it if, # for example, we have a corrupt install. original_paths = schema.MASTER_SCHEMA_FILE_NAMES schema.MASTER_SCHEMA_FILE_NAMES = {1: 'nonexistent.json'} msg = 'Missing master schema should raise MasterSchemaError.' with self.assertRaises(MasterSchemaError, msg=msg): schema.validate_schema_dict({'version': 1}) schema.MASTER_SCHEMA_FILE_NAMES = original_paths
def convert_schema(schema_json, output): """convert the given schema file to the latest version. """ try: schema_dict = json.load(schema_json) except ValueError as e: # In Python 3 we can be more specific # with json.decoder.JSONDecodeError, # but that doesn't exist in Python 2. msg = 'The provided schema is not a valid JSON file.' raise_from(SchemaError(msg), e) validate_schema_dict(schema_dict) new_schema_dict = convert_to_latest_version(schema_dict, validate_result=True) json.dump(new_schema_dict, output)
def test_convert_v1_to_v2(self): schema_v1 = _schema_dict(DATA_DIRECTORY, 'randomnames-schema.json') schema.validate_schema_dict(schema_v1) schema_v2 = schema.convert_v1_to_v2(schema_v1) schema.validate_schema_dict(schema_v2)