Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
((models.Status.success, ".", "green"), (models.Status.failure, "F", "red"), (models.Status.error, "E", "red")),
)
def test_handle_after_execution(capsys, execution_context, after_execution, status, expected_symbol, color):
# Given AfterExecution even with certain status
after_execution.status = status
# When this event is handled
default.handle_after_execution(execution_context, after_execution)
lines = capsys.readouterr().out.strip().split("\n")
symbol, percentage = lines[0].split()
# Then the symbol corresponding to the status is displayed with a proper color
assert click.style(expected_symbol, fg=color) == symbol
# And percentage is displayed in cyan color
assert click.style("[100%]", fg="cyan") == percentage
def test_unknown_response_code_with_default(args):
app, kwargs = args
# When endpoint returns a status code, that is not listed in "responses", but there is a "default" response
# And "status_code_conformance" is specified
results = execute(**kwargs, checks=(status_code_conformance,), hypothesis_options={"max_examples": 1})
# Then there should be no failure
assert not results.has_failures
check = results.results[0].checks[0]
assert check.name == "status_code_conformance"
assert check.value == Status.success
# When the runner is executed against the default test app
stats = execute(**kwargs)
# Then there are three executed cases
# Two errors - the second one is a flakiness check
headers = {"User-Agent": f"schemathesis/{__version__}"}
assert_schema_requests_num(app, 1)
schema_requests = get_schema_requests(app)
assert schema_requests[0].headers.get("User-Agent") == headers["User-Agent"]
assert_incoming_requests_num(app, 3)
assert_request(app, 0, "GET", "/api/failure", headers)
assert_request(app, 1, "GET", "/api/failure", headers)
assert_request(app, 2, "GET", "/api/success", headers)
# And statistic is showing the breakdown of cases types
assert stats.total == {"not_a_server_error": {Status.success: 1, Status.failure: 2, "total": 3}}