Exemplo n.º 1
0
 def test_new_target_without_path(self):
     configuration = Configuration('Foo')
     configuration.notifier = Mock(Notifier)
     user = '******'
     host = 'example.com'
     port = 666
     configuration_data = {
         'user': user,
         'host': host,
         'port': port,
     }
     with self.assertRaises(ValueError):
         new_target(configuration, 'ssh', configuration_data)
Exemplo n.º 2
0
 def test_new_target_without_host(self):
     configuration = Configuration('Foo')
     configuration.notifier = Mock(Notifier)
     user = '******'
     port = 666
     path = '/var/cache'
     configuration_data = {
         'user': user,
         'port': port,
         'path': path,
     }
     with self.assertRaises(ValueError):
         new_target(configuration, 'ssh', configuration_data)
Exemplo n.º 3
0
 def test_new_target_without_user(self):
     configuration = Configuration('Foo')
     configuration.notifier = Mock(Notifier)
     host = 'example.com'
     port = 666
     path = '/var/cache'
     configuration_data = {
         'host': host,
         'port': port,
         'path': path,
     }
     with self.assertRaises(ValueError):
         new_target(configuration, 'ssh', configuration_data)
Exemplo n.º 4
0
 def test_new_target_with_invalid_port_too_high(self):
     configuration = Configuration('Foo')
     configuration.notifier = Mock(Notifier)
     user = '******'
     host = 'example.com'
     port = 65536
     path = '/var/cache'
     configuration_data = {
         'user': user,
         'host': host,
         'port': port,
         'path': path,
     }
     with self.assertRaises(ValueError):
         new_target(configuration, 'ssh', configuration_data)
Exemplo n.º 5
0
 def test_new_target(self):
     configuration = Configuration('Foo', working_directory='/')
     configuration.notifier = Mock(Notifier)
     path = '/var/cache'
     configuration_data = {
         'path': path,
     }
     target = new_target(configuration, 'path', configuration_data)
     self.assertEquals(target.path, path)
Exemplo n.º 6
0
 def test_new_target_with_default_port(self):
     configuration = Configuration('Foo')
     configuration.notifier = Mock(Notifier)
     user = '******'
     host = 'example.com'
     path = '/var/cache'
     configuration_data = {
         'user': user,
         'host': host,
         'path': path,
     }
     sut = new_target(configuration, 'ssh', configuration_data)
     self.assertEquals(sut.port, 22)
Exemplo n.º 7
0
 def test_new_target(self):
     configuration = Configuration('Foo')
     configuration.notifier = Mock(Notifier)
     user = '******'
     host = 'example.com'
     port = 666
     path = '/var/cache'
     configuration_data = {
         'user': user,
         'host': host,
         'port': port,
         'path': path,
     }
     target = new_target(configuration, 'ssh', configuration_data)
     self.assertEquals(target.path, path)
     self.assertEquals(target.user, user)
     self.assertEquals(target.host, host)
     self.assertEquals(target.port, port)
Exemplo n.º 8
0
 def test_new_target_without_path(self):
     configuration = Configuration('Foo', working_directory='/')
     configuration.notifier = Mock(Notifier)
     configuration_data = {}
     with self.assertRaises(ValueError):
         new_target(configuration, 'path', configuration_data)
Exemplo n.º 9
0
 def test_new_target_of_unknown_type(self):
     with self.assertRaises(ValueError):
         configuration = Mock(Configuration)
         new_target(configuration, 'NonExistentType')
Exemplo n.º 10
0
def from_configuration_data(configuration_file_path,
                            data,
                            verbose=None,
                            interactive=None):
    """Parse configuration from raw, built-in types such as dictionaries, lists, and scalars.

    :param configuration_file_path: str
    :param data: dict
    :param verbose: Optional[bool]
    :param interactive: Optional[bool]
    :return: cls
    :raise: ValueError
    """
    name = data['name'] if 'name' in data else configuration_file_path
    working_directory = os.path.dirname(configuration_file_path)

    if verbose is None and 'verbose' in data:
        if not isinstance(data['verbose'], bool):
            raise ValueError('`verbose` must be a boolean.')
        verbose = data['verbose']

    if interactive is None:
        interactive = True
        if 'interactive' in data:
            if not isinstance(data['interactive'], bool):
                raise ValueError('`interactive` must be a boolean.')
            interactive = data['interactive']

    configuration = Configuration(name, working_directory, verbose,
                                  interactive)

    if 'logging' in data:
        logging_config.dictConfig(data['logging'])

    notifier = GroupedNotifiers()
    if 'notifications' in data:
        for notifier_data in data['notifications']:
            if 'type' not in notifier_data:
                raise ValueError('`notifiers[][type]` is required.')
            notifier_configuration = notifier_data[
                'configuration'] if 'configuration' in notifier_data else None
            notifier.notifiers.append(
                new_notifier(configuration, notifier_data['type'],
                             notifier_configuration))
    if not configuration.verbose:
        notifier = QuietNotifier(notifier)
    configuration.notifier = notifier

    if 'source' not in data:
        raise ValueError('`source` is required.')
    if 'type' not in data['source']:
        raise ValueError('`source[type]` is required.')
    source_configuration = data['source'][
        'configuration'] if 'configuration' in data['source'] else None
    configuration.source = new_source(configuration, data['source']['type'],
                                      source_configuration)

    if 'target' not in data:
        raise ValueError('`target` is required.')
    if 'type' not in data['target']:
        raise ValueError('`target[type]` is required.')
    target_configuration = data['target'][
        'configuration'] if 'configuration' in data['target'] else None
    configuration.target = new_target(configuration, data['target']['type'],
                                      target_configuration)

    return configuration