コード例 #1
0
def test_dont_fail_task(single_host):
    results = single_host.run(
        task=wrap_task(get_json_dict),
        tests=[t_jsonpath(path="$.dns_servers", assertion="contains", value="8.8.8.8")],
    )

    for result in results.values():
        assert not result[0].tests[0].passed
        assert not result[0].failed
コード例 #2
0
def test_contains_passed(single_host):
    results = single_host.run(
        task=wrap_task(get_json_dict),
        tests=[
            t_jsonpath(path="$.dns_search", assertion="contains", host_data="$.domain")
        ],
    )

    for result in results.values():
        assert result[0].tests[0].passed
コード例 #3
0
def test_string_input(single_host):
    results = single_host.run(
        task=wrap_task(get_json_str),
        tests=[
            t_jsonpath(path="$.interfaces..mtu", assertion="is_equal_to", value=1500)
        ],
    )

    for result in results.values():
        assert result[0].tests[0].passed
コード例 #4
0
def test_without_one_of_multi_match_passed(single_host):
    results = single_host.run(
        task=wrap_task(get_json_dict),
        tests=[
            t_jsonpath(path="$.interfaces..mtu", assertion="is_equal_to", value="1500")
        ],
    )

    for result in results.values():
        assert not result[0].tests[0].passed
コード例 #5
0
def test_contains_failed(single_host):
    results = single_host.run(
        task=wrap_task(get_json_dict),
        tests=[
            t_jsonpath(path="$.dns_search", assertion="contains", host_data="$.domain2")
        ],
    )

    for result in results.values():
        assert not result[0].tests[0].passed
        assert str(result[0].tests[0].exception).find("Expected") != -1
コード例 #6
0
def test_invalid_input(single_host):
    results = single_host.run(
        task=wrap_task(get_invalid_json),
        tests=[
            t_jsonpath(path="$.interfaces..mtu", assertion="is_equal_to", value="1500")
        ],
    )

    for result in results.values():
        assert not result[0].tests[0].passed
        assert str(result[0].tests[0].exception).find("Expecting value") != -1
コード例 #7
0
def test_path_not_found(single_host):
    results = single_host.run(
        task=wrap_task(get_json_dict),
        tests=[
            t_jsonpath(path="$.invalid", assertion="contains", host_data="$.domain")
        ],
    )

    for result in results.values():
        assert not result[0].tests[0].passed
        assert str(result[0].tests[0].exception) == "no match found from path $.invalid"
コード例 #8
0
def test_match_len_one(single_host):
    results = single_host.run(
        task=wrap_task(get_json_dict),
        tests=[
            t_jsonpath(
                path="$.type", assertion="is_equal_to", value="DeviceConfiguration"
            )
        ],
    )

    for result in results.values():
        assert result[0].tests[0].passed
        assert len(result[0].tests[0].matches) == 1
コード例 #9
0
def test_with_function(two_hosts):
    results = two_hosts.run(
        task=wrap_task(get_json_dict),
        tests=[
            t_jsonpath(path="$.dns_servers",
                       assertion="contains",
                       host_data="$.dns_primary")
        ],
    )
    assert results["test"][0].tests[0].passed
    assert not results["test2"][0].tests[0].passed

    for result in results.values():
        assert len(result[0].tests) == 1
コード例 #10
0
def test_without_one_of_single_match(single_host):
    results = single_host.run(
        task=wrap_task(get_json_dict),
        tests=[
            t_jsonpath(
                path="$.interfaces..address",
                assertion="is_equal_to",
                value="192.168.1.1",
            )
        ],
    )

    for result in results.values():
        assert not result[0].tests[0].passed
        assert str(result[0].tests[0].exception).find("Expected") != -1
コード例 #11
0
def test_found_duplicate_host_data(single_host):
    results = single_host.run(
        task=wrap_task(get_json_dict),
        tests=[
            t_jsonpath(
                path="$.dns_search", assertion="contains", host_data="$..duplicate"
            )
        ],
    )

    for result in results.values():
        assert not result[0].tests[0].passed
        assert (
            str(result[0].tests[0].exception) == "host_data can only return one match"
        )
コード例 #12
0
def test_with_one_of_multi_match_task(single_host):
    results = single_host.run(
        task=wrap_task(get_json_dict),
        tests=[
            t_jsonpath(
                path="$.interfaces..mask",
                assertion="is_equal_to",
                value=24,
                one_of=True,
            )
        ],
    )

    for result in results.values():
        assert result[0].tests[0].passed
        assert len(result[0].tests[0].matches) > 1
コード例 #13
0
def test_with_one_of_single_match(single_host):
    results = single_host.run(
        task=wrap_task(get_json_dict),
        tests=[
            t_jsonpath(
                path="$.interfaces..address",
                assertion="is_equal_to",
                value="192.168.1.1",
                one_of=True,
            )
        ],
    )

    for result in results.values():
        assert result[0].tests[0].passed
        assert len(result[0].tests[0].matches) == 1