Example #1
0
 def test_load_from_bad_yml(self):
     """Test load from bad yml file."""
     filename = 'tests/fixtures/test_incorrect_format.yml'
     message = ("Some error with file format in {} (should be YAML)".format(
         filename))
     with self.assertRaises(OSError) as contextmanager:
         DotConfig.load(filename)
     self.assertEqual(str(contextmanager.exception), message)
Example #2
0
 def test_load_from_bad_file_content(self):
     """Test load from bad yml file."""
     filename = 'tests/fixtures/test_incorrect_content.yml'
     message = (
         'Config {} is empty or have not "config" block'.format(filename))
     with self.assertRaises(OSError) as contextmanager:
         DotConfig.load(filename)
     self.assertEqual(str(contextmanager.exception), message)
Example #3
0
 def test_load_from_good_file(self):
     """Test load from yml file."""
     filename = 'tests/fixtures/test_correct.yml'
     config = DotConfig.load(filename)
     self.assertEqual(config.user, 'username')
     self.assertEqual(config.ask_password, False)
     self.assertEqual(config.connection.host, 'example.org')
     self.assertEqual(config.connection.port, 8080)
Example #4
0
 def test_getattr(self):
     """Test __getattr__ method."""
     config = DotConfig({
         'user': '******',
         'passwd': 'password1234',
     })
     self.assertEqual(config['user'], 'jack')
     self.assertEqual(config['passwd'], 'password1234')
Example #5
0
 def test_str_method(self):
     """Test get_attribute."""
     data = {
         'text': 'hello',
         'count': 10,
     }
     config = DotConfig(data)
     self.assertEqual(str(config), str(data))
Example #6
0
 def add_alias(self, alias_record):
     """Add alias to builder."""
     new_record = DotConfig(alias_record)
     name = new_record.hostname
     refs = new_record.address
     result = self.search_record(refs)
     if result:
         return result.add_alias(name)
     elif self._is_not_stored(name):
         alias = DnsRecord(self.zone, name, DnsRecord(self.zone, refs, ''))
         self._aliases_without_ref[refs] = alias
         return alias
Example #7
0
 def test_dict_in_dics(self):
     """Test get_attribute."""
     config = DotConfig({
         'parameters': {
             'clients': 10
         },
         'somekey': 'data',
     })
     self.assertIsInstance(config.parameters, DotConfig)
     self.assertIsInstance(config.parameters.clients, int)
     self.assertEqual(config.parameters.clients, 10)
     self.assertIsInstance(config.somekey, str)
     self.assertEqual(config.somekey, 'data')
Example #8
0
 def __init__(self, config_path):
     """Init connection and fetchers from config."""
     config = DotConfig.load(config_path)
     self.connection = SqlConnection(**config.connection)
     host_fetcher = HostDataFetcher(self.connection,
                                    **config.database_hosts)
     self.host_updater = HostUpdater(fetcher=host_fetcher,
                                     dns_dir=config.dnspath,
                                     zones=config.zones,
                                     cache_dir=config.zone_cache_dir)
     domain_fetcher = HostDataFetcher(self.connection,
                                      **config.database_hosts)
     self.domain_updater = DomainUpdater(fetcher=domain_fetcher,
                                         dns_dir=config.dnspath,
                                         zones=config.zones,
                                         cache_dir=config.zone_cache_dir)
Example #9
0
    def add_record(self, record):
        """Add record to builder."""
        new_record = DotConfig(record)

        fqdn = new_record.hostname + '.' + self.zone
        domain_name = new_record.hostname
        address = new_record.address
        if fqdn not in self._records:
            self._records[fqdn] = DnsRecord(self.zone, domain_name, address)
            if fqdn in self._aliases_without_ref:
                alias = self._aliases_without_ref[fqdn]
                del self._aliases_without_ref[fqdn]
                self._records[fqdn].add_alias(alias.domain_name)

        else:
            self._records[fqdn].add_references(address)
Example #10
0
 def test_constructor(self):
     """Test simple constructor."""
     config = DotConfig({})
     self.assertIsInstance(config, DotConfig)
     self.assertEqual(set(config.keys()), set([]))
Example #11
0
 def test_load_fail_wrong_file(self):
     """Test error when file not found."""
     with self.assertRaises(OSError):
         DotConfig.load('file does not exists')
Example #12
0
 def test_getattr_failed(self):
     """Test key which not exists."""
     config = DotConfig({})
     with self.assertRaises(KeyError):
         config.some_key_not_exists()
Example #13
0
 def test_give_some_data(self):
     """Test simple constructor without args."""
     config = DotConfig({'startup': True, 'clients': 10})
     self.assertEqual(set(config.keys()), set(['startup', 'clients']))
     self.assertEqual(config.startup, True)
     self.assertEqual(config.clients, 10)
Example #14
0
 def test_constructor_with_bad_arg(self):
     """Test simple constructor without args."""
     with self.assertRaises(TypeError):
         DotConfig('some string')
Example #15
0
 def test_constructor_without_args(self):
     """Test simple constructor without args."""
     with self.assertRaises(TypeError):
         DotConfig()  # noqa # pylint: disable=no-value-for-parameter