def test_get_config_basefolder(mocker): """ Test get_config using basefolder. """ mocker.patch('etcdgo.config.YamlConfig.__init__', return_value=None) client = etcd3.Etcd3Client() test_basefolder = "/config_test" etcdgo.get_config(client, "yaml", basefolder=test_basefolder) etcdgo.config.YamlConfig.__init__.assert_called_with( client, basefolder=test_basefolder)
def push(args, label, config): """ Push/update a configuration. """ if not label: raise ValueError("label can't be empty.") if not config: raise ValueError("config can't be empty.") if not os.path.isfile(config): raise ValueError("configuration file doesn't exist.") filename, fileext = os.path.splitext(config) if not filename: raise ValueError("filename can't be empty.") config_type = None if fileext == ".json": config_type = "json" elif fileext in [".yaml", ".yml"]: config_type = "yaml" elif fileext == ".ini": config_type = "ini" else: raise ValueError("'%s' extension type is not supported." % fileext) config_client = etcdgo.get_config( args.client, config_type, basefolder=args.base_folder) config_client.push(label, config)
def test_get_config_ini(): """ Test get_config with ini type. """ client = etcd3.Etcd3Client() obj = etcdgo.get_config(client, "ini") assert isinstance(obj, etcdgo.config.IniConfig)
def test_get_config_yaml(): """ Test get_config with yaml type. """ client = etcd3.Etcd3Client() obj = etcdgo.get_config(client, "yaml") assert isinstance(obj, etcdgo.config.YamlConfig)
def test_get_config_json(): """ Test get_config with json type. """ client = etcd3.Etcd3Client() obj = etcdgo.get_config(client, "json") assert isinstance(obj, etcdgo.config.JsonConfig)
def pull(args, label, output_type): """ Pull a configuration and convert it into a specific type. """ if not label: raise ValueError("label can't be empty.") if not output_type: raise ValueError("output_type can't be empty.") config_client = etcdgo.get_config( args.client, output_type, basefolder=args.base_folder) data_str = config_client.dump(label) click.echo(data_str)
def test_get_config_error(): """ Test get_config with json type. """ with pytest.raises(ValueError): etcdgo.get_config(None, "json") with pytest.raises(ValueError): client = etcd3.Etcd3Client() etcdgo.get_config(client, None) with pytest.raises(NotImplementedError): client = etcd3.Etcd3Client() etcdgo.get_config(client, "txt")
def _callback(type): obj = etcdgo.get_config(etcd3.Etcd3Client(), type, basefolder="/config_test") return obj