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)
Esempio n. 2
0
 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)
Esempio n. 3
0
 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
Esempio n. 4
0
 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
Esempio n. 5
0
 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]
Esempio n. 6
0
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))
Esempio n. 7
0
 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)
Esempio n. 8
0
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))
Esempio n. 9
0
 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)