Esempio n. 1
0
def test_config_service_none0(setup_config_file, config_file):
    with Path(config_file).open(mode="w") as f:
        print("", file=f)

    with pytest.raises(NoConfigError):
        from sinetstream.configs import get_config_params
        get_config_params(None, config_file=config_file)
Esempio n. 2
0
def test_config_service_none0_v2(setup_config_file, config_file):
    import yaml
    with Path(config_file).open(mode="r") as f:
        y = yaml.safe_load(f)
    if "header" in y:
        # V2
        y["config"] = {}
    else:
        # V1
        y = {}
    with Path(config_file).open(mode="w") as f:
        yaml.safe_dump(y, f)

    with pytest.raises(InvalidConfigError):
        from sinetstream.configs import get_config_params
        get_config_params(None, config_file=config_file)
Esempio n. 3
0
def test_config_service_none2(setup_config_file, config_file):
    import yaml
    with Path(config_file).open(mode="r") as f:
        y = yaml.safe_load(f)
    if "header" in y:
        # V2
        config = y["config"]
    else:
        # V1
        config = y
    k1, v1 = config.items().__iter__().__next__()
    config[k1 + "-second"] = v1
    with Path(config_file).open(mode="w") as f:
        yaml.safe_dump(y, f)

    with pytest.raises(NoConfigError):
        from sinetstream.configs import get_config_params
        get_config_params(None, config_file=config_file)
Esempio n. 4
0
def test_config_encrypted(setup_privkey, setup_config_file, config_file):
    with Path(config_file).open(mode="r") as f:
        y = f.read()
    y = y.replace("PLACEHOLDER", f"!sinetstream/encrypted {make_secret(b'text in enen')}")
    with Path(config_file).open(mode="w") as f:
        f.write(y)
    from sinetstream.configs import get_config_params
    svc, params = get_config_params(SERVICE, config_file=config_file)
    assert svc == SERVICE
    assert params["binbin"] == b"text in binbin"
    assert params["enen"] == b"text in enen"
Esempio n. 5
0
def merge_parameter(service,
                    kwargs,
                    default_values,
                    config=None,
                    config_file=None):
    service, raw_params = get_config_params(service, config, config_file)
    svc_params = convert_params(raw_params)
    # Merge parameters
    # Priority:
    #  ctor's argument (highest)
    #  config file
    #  sinetstream's default parameter
    #  plugin's default parameter (lowest)
    params = copy.deepcopy(default_values)
    deepupdate(params, svc_params)
    deepupdate(params, convert_params(kwargs))
    normalize_params(params)
    return service, params