Beispiel #1
0
def test_dirs(sample_args):
    args = options.Args(**sample_args)
    opt = options.Options(args)

    assert len(opt.dirs) == 2
    assert opt.dirs[0] == "/tmp"
    assert opt.dirs[1] == "/home/user/tmp"
Beispiel #2
0
def test_syslog_server_port_both_none(monkeypatch):
    args_dict = get_args_dict(monkeypatch, "syslog_server", None)
    args_dict["syslog_port"] = None
    args = options.Args(**args_dict)

    o = options.Options(args)
    assert o.syslog_server is None
    assert o.syslog_port is None
Beispiel #3
0
def test_invalid_perms_mask_type(sample_args):
    sample_args["perms_mask"] = "bogus"
    args = options.Args(**sample_args)

    with pytest.raises(TypeError) as te:
        options.Options(args)

    assert "The permissions mask must be an octal integer" in str(te.value)
Beispiel #4
0
def test_realpath_archive_path(monkeypatch, sample_args):
    realpath = "/home/user/tmp"
    monkeypatch.setattr(os.path, "realpath", lambda _: realpath)

    sample_args["archive_path"] = "../tmp"
    args = options.Args(**sample_args)
    opt = options.Options(args)

    assert opt.archive_path == realpath
Beispiel #5
0
def test_invalid_archive_path(SAMPLE_ARGS):
    SAMPLE_ARGS["dirs"] = "."
    SAMPLE_ARGS["archive_path"] = "/fake/directory/doesnt/exist/"
    args = options.Args(**SAMPLE_ARGS)

    with pytest.raises(ValueError) as ve:
        options.Options(args)

    assert "Cannot archive files:" in str(ve.value)
Beispiel #6
0
def test_invalid_perms_mask_small(sample_args):
    sample_args['perms_mask'] = -0o1
    args = options.Args(**sample_args)

    with pytest.raises(ValueError) as ve:
        opt = options.Options(args)

    assert "ValueError: -1 is an invalid permissions mask. The permissions mask must be an octal integer (e.g. 755) between 0 and 777 inclusive." in str(
        ve)
Beispiel #7
0
def test_config_to_tuple_invalid_stdout(monkeypatch, config):
    patch_isdir(monkeypatch, config["DEFAULT"]["dirs"])
    config["DEFAULT"]["stdout"] = "yes"
    t = options.Options.config_to_tuple(config, False)

    with pytest.raises(ValueError) as ve:
        opt = options.Options(t)

    assert "'yes' is not a valid value for the stdout option. Valid values are 'True' or 'False'." in str(
        ve)
Beispiel #8
0
def test_config_to_tuple_invalid_protocol(monkeypatch, config):
    patch_isdir(monkeypatch, config["DEFAULT"]["dirs"])
    config["DEFAULT"]["protocol"] = "bogus"
    t = options.Options.config_to_tuple(config, False)

    with pytest.raises(ValueError) as ve:
        opt = options.Options(t)

    assert "Unknown protocol 'bogus'. Valid protocols are 'udp' or 'tcp'" in str(
        ve)
Beispiel #9
0
def test_invalid_perms_mask_large(sample_args):
    sample_args["perms_mask"] = 0o1000
    args = options.Args(**sample_args)

    with pytest.raises(ValueError) as ve:
        options.Options(args)

    assert (
        "1000 is an invalid permissions mask. The permissions mask must be an "
        "octal integer (e.g. 755) between 0 and 777 inclusive."
    ) in str(ve.value)
Beispiel #10
0
def test_invalid_debug(sample_args):
    sample_args["debug"] = "bogus"
    args = options.Args(**sample_args)

    with pytest.raises(ValueError):
        options.Options(args)
Beispiel #11
0
def test_invalid_recursive(sample_args):
    sample_args["recursive"] = "bogus"
    args = options.Args(**sample_args)

    with pytest.raises(ValueError):
        options.Options(args)
Beispiel #12
0
def test_invalid_stdout(sample_args):
    sample_args['stdout'] = "bogus"
    args = options.Args(**sample_args)

    with pytest.raises(ValueError):
        opt = options.Options(args)
Beispiel #13
0
def test_syslog_port_negative(monkeypatch):
    with pytest.raises(ValueError):
        args = mock_args_syslog_port(monkeypatch, -1)
        options.Options(args)
Beispiel #14
0
def test_dir_no_exist(monkeypatch):
    with pytest.raises(ValueError):
        args = mock_args_dir(monkeypatch, False)
        options.Options(args)
Beispiel #15
0
def test_syslog_server_is_empty_port_defined(monkeypatch):
    args_dict = get_args_dict(monkeypatch, 'syslog_server', "")
    args = options.Args(**args_dict)

    with pytest.raises(ValueError):
        o = options.Options(args)
Beispiel #16
0
def test_syslog_port_not_int(monkeypatch):
    with pytest.raises(ValueError):
        args = mock_args_syslog_port(monkeypatch, "iv")
        options.Options(args)
Beispiel #17
0
def test_syslog_port_zero(monkeypatch):
    with pytest.raises(ValueError):
        args = mock_args_syslog_port(monkeypatch, 0)
        options.Options(args)
Beispiel #18
0
def test_invalid_protocol(sample_args):
    sample_args["tcp"] = "bogus"
    args = options.Args(**sample_args)

    with pytest.raises(ValueError):
        options.Options(args)
Beispiel #19
0
def test_syslog_port_too_high(monkeypatch):
    with pytest.raises(ValueError):
        args = mock_args_syslog_port(monkeypatch, 65536)
        options.Options(args)
Beispiel #20
0
def test_protocol_tcp(sample_args):
    sample_args["tcp"] = True
    args = options.Args(**sample_args)

    opt = options.Options(args)
    assert opt.protocol == "tcp"
Beispiel #21
0
def test_syslog_server_is_none_port_defined(monkeypatch):
    args_dict = get_args_dict(monkeypatch, "syslog_server", None)
    args = options.Args(**args_dict)

    with pytest.raises(ValueError):
        options.Options(args)
Beispiel #22
0
def test_protocol_udp(sample_args):
    sample_args["tcp"] = False
    args = options.Args(**sample_args)

    opt = options.Options(args)
    assert opt.protocol == "udp"