From d8e9365b48f4cc1ec26cb8dc370544a8f165de5b Mon Sep 17 00:00:00 2001 From: Graham Welch Date: Fri, 18 Dec 2015 10:45:06 -0800 Subject: [PATCH] Update schema_validation to use new import structure. --- expandybird/expansion/schema_validation.py | 4 ++-- expandybird/expansion/schema_validation_test.py | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/expandybird/expansion/schema_validation.py b/expandybird/expansion/schema_validation.py index b0460d218..e5b0dec16 100644 --- a/expandybird/expansion/schema_validation.py +++ b/expandybird/expansion/schema_validation.py @@ -108,7 +108,7 @@ def Validate(properties, schema_name, template_name, imports): properties: dict, the properties to be validated schema_name: name of the schema file to validate 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: 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, ["Could not find schema file '%s'." % schema_name]) - raw_schema = imports[schema_name] + raw_schema = imports[schema_name]['content'] if properties is None: properties = {} diff --git a/expandybird/expansion/schema_validation_test.py b/expandybird/expansion/schema_validation_test.py index c00d223ec..dfa9e6554 100644 --- a/expandybird/expansion/schema_validation_test.py +++ b/expandybird/expansion/schema_validation_test.py @@ -37,11 +37,20 @@ def RawValidate(raw_properties, 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): """Takes raw properties, calls validate and returns yaml properties.""" properties = yaml.safe_load(raw_properties) return schema_validation.Validate(properties, schema_name, 'template.py', - import_map) + ConvertImportMap(import_map)) class SchemaValidationTest(unittest.TestCase):