def test_valid(self): validator = Validator(SCHEMA) for s in (VALID, MISSING_OPTIONAL_SECTION, MISSING_OPTIONAL_PROPERTY, TEST_MISSING_OPTIONAL_VALUE,): cfg = self.read(s) validator.validate(cfg)
def test_valid(self): validator = Validator(SCHEMA) for s in ( VALID, MISSING_OPTIONAL_SECTION, MISSING_OPTIONAL_PROPERTY, TEST_MISSING_OPTIONAL_VALUE, ): cfg = self.read(s) validator.validate(cfg)
def __init__(self, name, path): """ @param name: The handler name. @type name: str @param path: The absolute path to the descriptor. @type path: str """ cfg = Config(path) validator = Validator(self.SCHEMA) validator.validate(cfg) self.name = name self.cfg = cfg
def __init__(self, cfg, section): """ Construct the object and validate the configuration. @param cfg: The descriptor configuration. @type cfg: INIConfig @param section: The typedef section name within the descriptor. @type section: str """ schema = ( (section, REQUIRED, ( ('class', REQUIRED, ANY), ), ),) cfg = Config(cfg, filter=[section]) validator = Validator(schema) validator.validate(cfg) self.cfg = cfg[section]
def is_valid(source_id, descriptor): """ Get whether a content source descriptor is valid. :param source_id: A content source ID. :type source_id: str :param descriptor: A content source descriptor. :type descriptor: dict :return: True if valid. :rtype: bool """ try: schema = list(SCHEMA) schema[0] = source_id validator = Validator((schema, )) cfg = Config({source_id: descriptor}) validator.validate(cfg) return True except ValidationException, e: log.error(str(e))
def test_invalid(self): validator = Validator(SCHEMA) for s in ( MISSING_REQUIRED_SECTION, MISSING_REQUIRED_PROPERTY, TEST_MISSING_REQUIRED_VALUE, TEST_INVALID_VALUE, ): cfg = self.read(s) self.assertRaises(ValidationException, validator.validate, cfg)
def is_valid(source_id, descriptor): """ Get whether a content source descriptor is valid. :param source_id: A content source ID. :type source_id: str :param descriptor: A content source descriptor. :type descriptor: dict :return: True if valid. :rtype: bool """ try: schema = list(SCHEMA) schema[0] = source_id validator = Validator((schema,)) cfg = Config({source_id: descriptor}) validator.validate(cfg) return True except ValidationException, e: log.error(str(e))
def __init__(self, cfg, section): """ Construct the object and validate the configuration. @param cfg: The descriptor configuration. @type cfg: Config @param section: The typedef section name within the descriptor. @type section: str """ schema = (( section, REQUIRED, (('class', REQUIRED, ANY), ), ), ) cfg = Config(cfg, filter=[section]) if cfg: validator = Validator(schema) validator.validate(cfg) self.cfg = cfg[section] else: raise SectionNotFound(section)