Exemplo n.º 1
0
def test_display_single_failure(capsys, swagger_20, execution_context,
                                endpoint, body):
    # Given a single test result with multiple successful & failed checks
    success = models.Check("not_a_server_error", models.Status.success)
    failure = models.Check("not_a_server_error", models.Status.failure,
                           models.Case(endpoint, body=body))
    test_statistic = models.TestResult(endpoint, [
        success, success, success, failure, failure,
        models.Check("different_check", models.Status.success)
    ])
    # When this failure is displayed
    default.display_failures_for_single_test(
        execution_context,
        SerializedTestResult.from_test_result(test_statistic))
    out = capsys.readouterr().out
    lines = out.split("\n")
    # Then the endpoint name is displayed as a subsection
    assert " GET: /success " in lines[0]
    # And check name is displayed in red
    assert lines[1] == strip_style_win32(
        click.style("Check           : not_a_server_error", fg="red"))
    # And body should be displayed if it is not None
    if body is None:
        assert "Body" not in out
    else:
        assert strip_style_win32(
            click.style(f"Body            : {body}", fg="red")) in lines
    # And empty parameters are not present in the output
    assert "Path parameters" not in out
    # And not needed attributes are not displayed
    assert "Path" not in out
    assert "Method" not in out
    assert "Base url" not in out
Exemplo n.º 2
0
def test_display_single_failure(capsys, swagger_20, endpoint, body):
    # Given a single test result with multiple successful & failed checks
    success = models.Check("not_a_server_error", models.Status.success)
    failure = models.Check(
        "not_a_server_error",
        models.Status.failure,
        models.Case("/success", "GET", base_url="http://example.com", body=body),
    )
    test_statistic = models.TestResult(
        endpoint,
        swagger_20,
        [success, success, success, failure, failure, models.Check("different_check", models.Status.success)],
    )
    # When this failure is displayed
    output.display_single_failure(test_statistic)
    out = capsys.readouterr().out
    lines = out.split("\n")
    # Then the endpoint name is displayed as a subsection
    assert " GET: /success " in lines[0]
    # And check name is displayed in red
    assert lines[1] == click.style("Check           : not_a_server_error", fg="red")
    # And body should be displayed if it is not None
    if body is None:
        assert "Body" not in out
    else:
        assert click.style(f"Body            : {body}", fg="red") in lines
    # And empty parameters are not present in the output
    assert "Path parameters" not in out
    # And not needed attributes are not displayed
    assert "Path" not in out
    assert "Method" not in out
    assert "Base url" not in out
Exemplo n.º 3
0
def test_display_single_failure(capsys, swagger_20, execution_context, operation, body, response):
    # Given a single test result with multiple successful & failed checks
    success = models.Check("not_a_server_error", models.Status.success, response, 0, models.Case(operation, body=body))
    failure = models.Check("not_a_server_error", models.Status.failure, response, 0, models.Case(operation, body=body))
    test_statistic = models.TestResult(
        operation.method,
        operation.full_path,
        DataGenerationMethod.default(),
        [
            success,
            success,
            success,
            failure,
            failure,
            models.Check("different_check", models.Status.success, response, 0, models.Case(operation, body=body)),
        ],
    )
    # When this failure is displayed
    default.display_failures_for_single_test(execution_context, SerializedTestResult.from_test_result(test_statistic))
    out = capsys.readouterr().out
    lines = out.split("\n")
    # Then the path is displayed as a subsection
    assert " GET /v1/success " in lines[0]
    # And body should be displayed if it is not NOT_SET
    if body is NOT_SET:
        assert "Body" not in out
    else:
        assert strip_style_win32(click.style(f"Body            : {body}", fg="red")) in lines
    # And empty parameters are not present in the output
    assert "Path parameters" not in out
    # And not needed attributes are not displayed
    assert "Path" not in out
    assert "Method" not in out
    assert "Base url" not in out
Exemplo n.º 4
0
def test_display_statistic(capsys, swagger_20, execution_context, operation,
                           response):
    # Given multiple successful & failed checks in a single test
    success = models.Check("not_a_server_error", models.Status.success,
                           response, 0, models.Case(operation))
    failure = models.Check("not_a_server_error", models.Status.failure,
                           response, 0, models.Case(operation))
    single_test_statistic = models.TestResult(
        operation.method,
        operation.full_path,
        DataGenerationMethod.default(),
        [
            success,
            success,
            success,
            failure,
            failure,
            models.Check("different_check", models.Status.success, response, 0,
                         models.Case(operation)),
        ],
    )
    results = models.TestResultSet([single_test_statistic])
    event = Finished.from_results(results, running_time=1.0)
    # When test results are displayed
    default.display_statistic(execution_context, event)

    lines = [line for line in capsys.readouterr().out.split("\n") if line]
    failed = strip_style_win32(click.style("FAILED", bold=True, fg="red"))
    passed = strip_style_win32(click.style("PASSED", bold=True, fg="green"))
    # Then all check results should be properly displayed with relevant colors
    assert lines[2:4] == [
        f"    not_a_server_error                    3 / 5 passed          {failed} ",
        f"    different_check                       1 / 1 passed          {passed} ",
    ]
Exemplo n.º 5
0
def test_display_statistic(capsys, swagger_20, endpoint):
    # Given multiple successful & failed checks in a single test
    success = models.Check("not_a_server_error", models.Status.success)
    failure = models.Check("not_a_server_error", models.Status.failure)
    single_test_statistic = models.TestResult(
        endpoint, [success, success, success, failure, failure, models.Check("different_check", models.Status.success)]
    )
    results = models.TestResultSet([single_test_statistic])
    # When test results are displayed
    default.display_statistic(results)

    lines = [line for line in capsys.readouterr().out.split("\n") if line]
    failed = click.style("FAILED", bold=True, fg="red")
    not_a_server_error = click.style("not_a_server_error", bold=True)
    different_check = click.style("different_check", bold=True)
    passed = click.style("PASSED", bold=True, fg="green")
    # Then all check results should be properly displayed with relevant colors
    assert lines[1:3] == [
        f"{not_a_server_error}            3 / 5 passed          {failed} ",
        f"{different_check}               1 / 1 passed          {passed} ",
    ]