Exemple #1
0
def test_already_consildated(fake_results):
    """Make sure we can consolidate before preparing."""

    results = formatting.consolidate(fake_results)
    with patch.object(formatting, "consolidate") as patched:
        formatting.prepare_results(results)

    assert not patched.called
Exemple #2
0
def test_already_consildated(fake_results):
    """Make sure we can consolidate before preparing."""

    results = formatting.consolidate(fake_results)
    with patch.object(formatting, "consolidate") as patched:
        formatting.prepare_results(results)

    assert not patched.called
Exemple #3
0
def test_results_max_length(fake_results, capfd):
    """Ensure the vertical alignment with multi line output commands."""

    fake_output = ["many", "lines", "of", "output"]
    fake_results.insert(
        0,
        {
            "name": "server_d_1",
            "results": [("obviously fake", "\n".join(fake_output))],
        }
    )
    results, options = formatting.prepare_results(
        fake_results,
        {"style": 1},
    )

    formatting._pretty_result(results[0], options, results)
    stdout, _ = capfd.readouterr()
    stdout = stdout.splitlines()

    # top line should be a space separators
    topline = str("{0}".format(options["chars"]["top"][options["style"]] * 10))
    assert topline in stdout[0]

    # then it should be the server name, separator and first line of cmd
    assert str("server_d_1") in stdout[1]
    assert options["chars"]["side"][options["style"]] in stdout[1]

    # then the multi line command should fill down the right column
    for line, fake_out in enumerate(fake_output, 1):
        assert str(fake_out) in stdout[line]

    # finally check total length
    assert len(stdout) == 5
Exemple #4
0
def test_results_max_length(fake_results, capfd):
    """Ensure the vertical alignment with multi line output commands."""

    fake_output = ["many", "lines", "of", "output"]
    fake_results.insert(
        0, {
            "name": "server_d_1",
            "results": [("obviously fake", "\n".join(fake_output))],
        })
    results, options = formatting.prepare_results(
        fake_results,
        {"style": 1},
    )

    formatting._pretty_result(results[0], options, results)
    stdout, _ = capfd.readouterr()
    stdout = stdout.splitlines()

    # top line should be a space separators
    topline = str("{0}".format(options["chars"]["top"][options["style"]] * 10))
    assert topline in stdout[0]

    # then it should be the server name, separator and first line of cmd
    assert str("server_d_1") in stdout[1]
    assert options["chars"]["side"][options["style"]] in stdout[1]

    # then the multi line command should fill down the right column
    for line, fake_out in enumerate(fake_output, 1):
        assert str(fake_out) in stdout[line]

    # finally check total length
    assert len(stdout) == 5
Exemple #5
0
def test_minimum_left_len(fake_results):
    """Left len should have a minimum of 6 chars."""

    for count, result_set in enumerate(fake_results):
        result_set["name"] = chr(97 + count)

    _, options = formatting.prepare_results(fake_results)
    assert options["left_len"] == 6
Exemple #6
0
def test_minimum_left_len(fake_results):
    """Left len should have a minimum of 6 chars."""

    for count, result_set in enumerate(fake_results):
        result_set["name"] = chr(97 + count)

    _, options = formatting.prepare_results(fake_results)
    assert options["left_len"] == 6
Exemple #7
0
def test_pretty_header(fake_results, capfd):
    """Ensure proper formatting in the header line of pretty_output."""

    _, options = formatting.prepare_results(fake_results)
    formatting.pretty_header(options)
    stdout, _ = capfd.readouterr()

    assert str("Server") in stdout
    assert str("Result") in stdout
Exemple #8
0
def test_pretty_header(fake_results, capfd):
    """Ensure proper formatting in the header line of pretty_output."""

    _, options = formatting.prepare_results(fake_results)
    formatting.pretty_header(options)
    stdout, _ = capfd.readouterr()

    assert str("Server") in stdout
    assert str("Result") in stdout
Exemple #9
0
def test_prepare_results(fake_results):
    """Ensure the results and options dicts are prepared for printing."""

    results, options = formatting.prepare_results(fake_results, {"width": 101})

    assert options["left_len"] == 10
    assert "chars" in options
    assert options["style"] == 0
    assert options["width"] == 101
    assert "names" in results[0]
    assert "name" not in results[0]
Exemple #10
0
def test_prepare_results(fake_results):
    """Ensure the results and options dicts are prepared for printing."""

    results, options = formatting.prepare_results(fake_results, {"width": 101})

    assert options["left_len"] == 10
    assert "chars" in options
    assert options["style"] == 0
    assert options["width"] == 101
    assert "names" in results[0]
    assert "name" not in results[0]
Exemple #11
0
def test_pretty_result(fake_results, capfd):
    """Ensure pretty results are correctly printed."""

    results, options = formatting.prepare_results(fake_results)

    formatting._pretty_result(results[0], options, results)

    stdout, _ = capfd.readouterr()

    for server in results[0]["names"]:
        assert str(server) in stdout
    for _, result in results[0]["results"]:
        assert str(result) in stdout
Exemple #12
0
def test_header_with_jumphost(fake_results, capfd):
    """The jumphost should appear in the header."""

    options = {"jump_host": "some_server"}
    _, options = formatting.prepare_results(fake_results, options)
    formatting.pretty_header(options)

    stdout, _ = capfd.readouterr()

    assert str("Server") in stdout
    assert str("Result") in stdout
    assert str("Jumpbox") in stdout
    assert str("some_server") in stdout
Exemple #13
0
def test_pretty_result(fake_results, capfd):
    """Ensure pretty results are correctly printed."""

    results, options = formatting.prepare_results(fake_results)

    formatting._pretty_result(results[0], options, results)

    stdout, _ = capfd.readouterr()

    for server in results[0]["names"]:
        assert str(server) in stdout
    for _, result in results[0]["results"]:
        assert str(result) in stdout
Exemple #14
0
def test_header_with_jumphost(fake_results, capfd):
    """The jumphost should appear in the header."""

    options = {"jump_host": "some_server"}
    _, options = formatting.prepare_results(fake_results, options)
    formatting.pretty_header(options)

    stdout, _ = capfd.readouterr()

    assert str("Server") in stdout
    assert str("Result") in stdout
    assert str("Jumpbox") in stdout
    assert str("some_server") in stdout
Exemple #15
0
def test_bottom_up_in_first_result(fake_results, capfd):
    """The first result when using a jumpbox should have a bot_up char."""

    results, options = formatting.prepare_results(
        fake_results,
        {"jump_host": "some_server", "style": 1},
    )

    formatting._pretty_result(results[0], options, results)

    stdout, _ = capfd.readouterr()

    for server in results[0]["names"]:
        assert str(server) in stdout
    for _, result in results[0]["results"]:
        assert str(result) in stdout

    assert options["chars"]["bot_up"][options["style"]] in stdout
Exemple #16
0
def test_bottom_up_in_first_result(fake_results, capfd):
    """The first result when using a jumpbox should have a bot_up char."""

    results, options = formatting.prepare_results(
        fake_results,
        {
            "jump_host": "some_server",
            "style": 1
        },
    )

    formatting._pretty_result(results[0], options, results)

    stdout, _ = capfd.readouterr()

    for server in results[0]["names"]:
        assert str(server) in stdout
    for _, result in results[0]["results"]:
        assert str(result) in stdout

    assert options["chars"]["bot_up"][options["style"]] in stdout