def test_validations_for_duplicate_setting(self): root = model.ConfmlConfiguration("dummy_conf") conf1 = root.create_configuration("conf1.confml") fea = conf1.create_feature("fea1") set1 = model.ConfmlStringSetting("setting1", desc="description one", name="setting") fea.add_feature(set1) conf2 = root.create_configuration("conf2.confml") fea = conf2.create_feature("fea1") set2 = model.ConfmlStringSetting("setting1", desc="description two", name="setting new") fea.add_feature(set2) validator_classes = get_validator_classes() context = ValidationContext(root) validators = [vc(context) for vc in validator_classes] for validator in validators: validator.validate() self.assertEquals(len(context.problems), 2, context.problems) self.assertEquals( context.problems[0].msg, "Feature fea1.setting1 has '2' definitions in files ['conf1.confml', 'conf2.confml']", context.problems)
def test_validations_for_lenght_and_duplicate_setting(self): root = model.ConfmlConfiguration("dummy_conf") conf1 = root.create_configuration("conf1.confml") fea = conf1.create_feature("fea1") set1 = model.ConfmlStringSetting("setting1", desc="description one", name="setting", length="4") fea.add_feature(set1) set1.value = "abcdefg" conf2 = root.create_configuration("conf2.confml") fea = conf2.create_feature("fea1") set2 = model.ConfmlStringSetting("setting1", desc="description two", name="setting new") fea.add_feature(set2) validator_classes = get_validator_classes() context = ValidationContext(root) validators = [vc(context) for vc in validator_classes] for validator in validators: validator.validate() self.assertEquals(len(context.problems), 3, context.problems) self.assertEquals( context.problems[0].msg, "Setting fea1.setting1: Exact number of characters must be 4 (value has 7)", context.problems) self.assertEquals( context.problems[1].msg, "Feature fea1.setting1 has '2' definitions in files ['conf1.confml', 'conf2.confml']", context.problems)
def test_duplicate_setting_fix_with_duplicates_with_options(self): root = model.ConfmlConfiguration("dummy_conf") conf1 = root.create_configuration("conf1.confml") fea = conf1.create_feature("fea1") set1 = model.ConfmlStringSetting("setting1", desc="description one", name="setting") set1.add(api.Option('op1', 'val1')) set1.add(api.Option('op2', 'val2')) fea.add_feature(set1) conf2 = root.create_configuration("conf2.confml") fea = conf2.create_feature("fea1") set2 = model.ConfmlStringSetting("setting1", desc="description two", name="setting new") set2.add(api.Option('op3', 'val3')) set2.add(api.Option('op4', 'val4')) fea.add_feature(set2) context = ValidationContext(root) valid = confml.DuplicateFeatureValidator(context) valid.validate() fixer = confml.DuplicateFeatureFixer() fixer.fix(context) set1 = conf1.get_feature('fea1').get_feature('setting1') options = set1.options self.assertEquals( len(options), 2, 'After fix only options from new setting should be preserved') self.assertEquals(options['val3'].name, 'op3') self.assertEquals(options['val4'].name, 'op4')
def test_duplicate_setting_fix_with_duplicates(self): root = model.ConfmlConfiguration("dummy_conf") conf1 = root.create_configuration("conf1.confml") fea = conf1.create_feature("fea1") set1 = model.ConfmlStringSetting("setting1", desc="description one", name="setting") fea.add_feature(set1) conf2 = root.create_configuration("conf2.confml") fea = conf2.create_feature("fea1") set2 = model.ConfmlStringSetting("setting2", desc="description two", name="setting new") fea.add_feature(set2) self.assertEquals(conf1.list_all_features(), ['fea1', 'fea1.setting1']) context = ValidationContext(root) valid = confml.DuplicateFeatureValidator(context) valid.validate() self.assertEquals(len(context.problems), 1, context.problems) self.assertEquals( context.problems[0].msg, "Feature fea1 has '2' definitions in files ['conf1.confml', 'conf2.confml']", context.problems) fixer = confml.DuplicateFeatureFixer() fixer.fix(context) # revalidation should now report no problems context = ValidationContext(root) valid = confml.DuplicateFeatureValidator(context) valid.validate() self.assertEquals(len(context.problems), 0, context.problems) self.assertEquals(conf1.list_all_features(), ['fea1', 'fea1.setting1', 'fea1.setting2']) self.assertEquals(conf2.list_all_features(), [])
def test_length_constraint_validator_with_singe_feature(self): conf = model.ConfmlConfiguration("foo") fea = model.ConfmlStringSetting("test", length="4") conf.add_feature(fea) # Test lenght validation fea.value = "test mee" context = ValidationContext(conf) valid = LengthConstraintValidator(context) valid.validate() self.assertEquals(context.problems[0].type, 'model.confml.invalid_value.length') # Test minLenght validation context.problems = [] del fea.length fea.minLength = 10 valid.validate() self.assertEquals(context.problems[0].type, 'model.confml.invalid_value.minlength', context.problems[0]) # Test maxLenght validation context.problems = [] del fea.minLength fea.maxLength = 4 valid.validate() self.assertEquals(context.problems[0].type, 'model.confml.invalid_value.maxlength', context.problems[0])
def test_duplicate_feature_validator_with_no_duplicates(self): conf = model.ConfmlConfiguration("dummy_conf") fea = conf.create_feature("fea1") set1 = model.ConfmlStringSetting("setting1", desc="description one", name="setting") set2 = model.ConfmlStringSetting("setting2", desc="description two", name="setting") fea.add_feature(set1) fea.add_feature(set2) context = ValidationContext(conf) valid = DuplicateFeatureValidator(context) valid.validate() self.assertEquals(context.problems, [])
def test_duplicate_feature_validator_with_duplicates(self): root = model.ConfmlConfiguration("dummy_conf") conf1 = root.create_configuration("conf1.confml") fea = conf1.create_feature("fea1") set1 = model.ConfmlStringSetting("setting1", desc="description one", name="setting") fea.add_feature(set1) conf2 = root.create_configuration("conf2.confml") fea = conf2.create_feature("fea1") set2 = model.ConfmlStringSetting("setting2", desc="description two", name="setting new") fea.add_feature(set2) context = ValidationContext(root) valid = DuplicateFeatureValidator(context) valid.validate() self.assertEquals(len(context.problems), 1, context.problems) self.assertEquals( context.problems[0].msg, "Feature fea1 has '2' definitions in files ['conf1.confml', 'conf2.confml']", context.problems)
def loads(self, elem): """ @param elem: The xml include elem """ typedef = elem.get('type') if typedef == 'sequence': map_key = elem.get('mapKey') map_value = elem.get('mapValue') display_name = elem.get('displayName') feature = model.ConfmlSequenceSetting(elem.get('ref'), mapKey=map_key, mapValue=map_value, displayName=display_name) elif typedef == 'int': feature = model.ConfmlIntSetting(elem.get('ref')) elif typedef == 'boolean': feature = model.ConfmlBooleanSetting(elem.get('ref')) elif typedef == 'selection': feature = model.ConfmlSelectionSetting(elem.get('ref')) elif typedef == 'multiSelection': feature = model.ConfmlMultiSelectionSetting(elem.get('ref')) elif typedef == 'string': feature = model.ConfmlStringSetting(elem.get('ref')) elif typedef == 'real': feature = model.ConfmlRealSetting(elem.get('ref')) elif typedef == 'file': feature = model.ConfmlFileSetting(elem.get('ref')) elif typedef == 'folder': feature = model.ConfmlFolderSetting(elem.get('ref')) elif typedef == 'date': feature = model.ConfmlDateSetting(elem.get('ref')) elif typedef == 'time': feature = model.ConfmlTimeSetting(elem.get('ref')) elif typedef == 'dateTime': feature = model.ConfmlDateTimeSetting(elem.get('ref')) elif typedef == 'duration': feature = model.ConfmlDurationSetting(elem.get('ref')) elif typedef == 'hexBinary': feature = model.ConfmlHexBinarySetting(elem.get('ref')) else: # Handle the default setting as int type feature = model.ConfmlSetting(elem.get('ref'), type=typedef) feature.lineno = utils.etree.get_lineno(elem) self._get_setting_properties(elem, feature) return feature