Update schema_validation to use new import structure.

pull/167/head
Graham Welch 10 years ago
parent 6672511e53
commit 6e4ccdbf8d

@ -108,7 +108,7 @@ def Validate(properties, schema_name, template_name, imports):
properties: dict, the properties to be validated properties: dict, the properties to be validated
schema_name: name of the schema file to validate schema_name: name of the schema file to validate
template_name: name of the template whose properties are being validated template_name: name of the template whose properties are being validated
imports: the map of imported files names to file contents imports: the map of imported files names to map containing path and content
Returns: Returns:
Dict containing the validated properties, with defaults filled in Dict containing the validated properties, with defaults filled in
@ -122,7 +122,7 @@ def Validate(properties, schema_name, template_name, imports):
raise ValidationErrors(schema_name, template_name, raise ValidationErrors(schema_name, template_name,
["Could not find schema file '%s'." % schema_name]) ["Could not find schema file '%s'." % schema_name])
raw_schema = imports[schema_name] raw_schema = imports[schema_name]['content']
if properties is None: if properties is None:
properties = {} properties = {}

@ -37,11 +37,20 @@ def RawValidate(raw_properties, schema_name, raw_schema):
{schema_name: raw_schema}) {schema_name: raw_schema})
def ConvertImportMap(import_map):
"""Makes each import a map of {'content': value}."""
out = {}
for key in import_map:
out[key] = { 'content': import_map[key]}
return out
def ImportsRawValidate(raw_properties, schema_name, import_map): def ImportsRawValidate(raw_properties, schema_name, import_map):
"""Takes raw properties, calls validate and returns yaml properties.""" """Takes raw properties, calls validate and returns yaml properties."""
properties = yaml.safe_load(raw_properties) properties = yaml.safe_load(raw_properties)
return schema_validation.Validate(properties, schema_name, 'template.py', return schema_validation.Validate(properties, schema_name, 'template.py',
import_map) ConvertImportMap(import_map))
class SchemaValidationTest(unittest.TestCase): class SchemaValidationTest(unittest.TestCase):

Loading…
Cancel
Save