Example #1
0
def test_load_config(config0_dir):
    with pytest.raises(IOError):
        config.load_config('nonexistent')

    c = config.load_config(config0_dir)
    DEFAULT = config.default_config()
    assert c['sync'] != DEFAULT['sync']
    assert c['sync']['timeout'] == 60
    assert c['sync']['strip_tz'] == DEFAULT['sync']['strip_tz']
    assert c['sync']['url'] != DEFAULT['sync']['url']
Example #2
0
def test_load_config(config0_dir):
    with pytest.raises(IOError):
        config.load_config("nonexistent")

    c = config.load_config(config0_dir)
    DEFAULT = config.default_config()
    assert c["sync"] != DEFAULT["sync"]
    assert c["sync"]["timeout"] == 60
    assert c["sync"]["strip_tz"] == DEFAULT["sync"]["strip_tz"]
    assert c["sync"]["url"] != DEFAULT["sync"]["url"]
Example #3
0
    def __init__(self, cfg=None, **kwargs):
        """
        Arguments:
            - cfg <dict>: dict of complete config options (see config.ClientSchema),
                by default loads from DEFAULT_CONFIG_DIR
            - url<str>: URL to connect to
            - user<str>: username to connect to api with
            - password<str>: password
            - timeout<float>: timeout to fail after
        """
        if cfg is None:
            cfg = config.load_config()
        self.config = cfg
        orm_config = cfg['orm']
        orm_name = orm_config['backend']
        if not peeringdb.backend_initialized():
            peeringdb.initialize_backend(orm_name, **orm_config)

        sync_config = cfg['sync']
        # override config with kwargs
        munge.util.recursive_update(sync_config, kwargs)

        self._fetcher = Fetcher(**sync_config)
        self._updater = Updater(self._fetcher, **sync_config)

        self.update_all = self._updater.update_all
        self.update = self._updater.update
        self.update_where = self._updater.update_where

        tag_attrs = {
            res.tag: _Query(self, res)
            for res in resource.all_resources()
        }
        self._Tags = type('_Tags', (), tag_attrs)
        self.tags = self._Tags()
Example #4
0
    def __init__(self, cfg=None, **kwargs):
        """
        Arguments:
            - cfg <dict>: dict of complete config options (see config.ClientSchema),
                by default loads from DEFAULT_CONFIG_DIR
            - url<str>: URL to connect to
            - user<str>: username to connect to api with
            - password<str>: password
            - timeout<float>: timeout to fail after
        """
        if cfg is None:
            cfg = config.load_config()
        self.config = cfg
        orm_config = cfg["orm"]
        orm_name = orm_config["backend"]
        if not backend_initialized():
            initialize_backend(orm_name, **orm_config)

        sync_config = cfg["sync"]
        # override config with kwargs
        munge.util.recursive_update(sync_config, kwargs)

        self._fetcher = Fetcher(**sync_config)
        self._updater = Updater(self._fetcher, **sync_config)

        self.update_all = self._updater.update_all
        self.update = self._updater.update
        self.update_where = self._updater.update_where

        tag_res = OrderedDict(
            [(res.tag, _Query(self, res)) for res in resource.all_resources()]
        )
        tag_attrs = {
            **tag_res,
            **{
                "keys": lambda self: list(tag_res.keys()),
                "all": lambda self: list(tag_res.values()),
            },
        }
        self._Tags = type("_Tags", (), tag_attrs)
        self.tags = self._Tags()
Example #5
0
def test_default_config():
    DEFAULT = config.default_config()
    with TemporaryDirectory() as path:
        cfg = config.load_config(path)
    assert DEFAULT == cfg