def test_display_errors(swagger_20, capsys, results_set, execution_context, show_errors_tracebacks, verbosity): execution_context.verbosity = verbosity # Given two test results - success and error endpoint = models.Endpoint("/api/error", "GET", {}, swagger_20) error = models.TestResult(endpoint, seed=123) error.add_error(ConnectionError("Connection refused!"), models.Case(endpoint, query={"a": 1})) results_set.append(error) execution_context.results.append( SerializedTestResult.from_test_result(error)) event = Finished.from_results(results_set, 1.0) # When the errors are displayed execution_context.show_errors_tracebacks = show_errors_tracebacks default.display_errors(execution_context, event) out = capsys.readouterr().out.strip() # Then section title is displayed assert " ERRORS " in out help_message_exists = ( "Add this option to your command line parameters to see full tracebacks: --show-errors-tracebacks" in out) # And help message is displayed only if tracebacks are not shown assert help_message_exists is not show_errors_tracebacks # And endpoint with an error is displayed as a subsection assert " GET: /api/error " in out # And the error itself is displayed assert "ConnectionError: Connection refused!" in out # And the example is displayed assert "Query : {'a': 1}" in out assert "Or add this option to your command line parameters: --hypothesis-seed=123" in out
def make_case(schema: BaseSchema, definition: Dict[str, Any]) -> models.Case: endpoint = models.Endpoint("/path", "GET", definition=EndpointDefinition( definition, definition, None, []), schema=schema) return models.Case(endpoint)
def test_display_failures(swagger_20, capsys, results_set): # Given two test results - success and failure failure = models.TestResult(models.Endpoint("/api/failure", "GET", {}), swagger_20) failure.add_failure("test", models.Case("/api/failure", "GET", base_url="http://127.0.0.1:8080")) results_set.append(failure) # When the failures are displayed output.display_failures(results_set) out = capsys.readouterr().out.strip() # Then section title is displayed assert " FAILURES " in out # And endpoint with a failure is displayed as a subsection assert " GET: /api/failure " in out # And check name is displayed assert "Check : test" in out assert "Run this Python code to reproduce this failure: " in out assert "requests.get('http://127.0.0.1:8080/api/failure')" in out
def test_display_errors(swagger_20, capsys, results_set): # Given two test results - success and error endpoint = models.Endpoint("/api/error", "GET", {}, swagger_20) error = models.TestResult(endpoint, seed=123) error.add_error(ConnectionError("Connection refused!"), models.Case(endpoint, query={"a": 1})) results_set.append(error) # When the errors are displayed default.display_errors(results_set) out = capsys.readouterr().out.strip() # Then section title is displayed assert " ERRORS " in out # And endpoint with an error is displayed as a subsection assert " GET: /api/error " in out # And the error itself is displayed assert "ConnectionError: Connection refused!" in out # And the example is displayed assert "Query : {'a': 1}" in out assert "Or add this option to your command line parameters: --hypothesis-seed=123" in out
def test_display_errors(swagger_20, capsys, results_set): # Given two test results - success and error error = models.TestResult(models.Endpoint("/api/error", "GET", {}), swagger_20) error.add_error( ConnectionError("Connection refused!"), models.Case("/api/error", "GET", base_url="http://127.0.0.1:8080", query={"a": 1}), ) results_set.append(error) # When the errors are displayed output.display_errors(results_set) out = capsys.readouterr().out.strip() # Then section title is displayed assert " ERRORS " in out # And endpoint with an error is displayed as a subsection assert " GET: /api/error " in out # And the error itself is displayed assert "ConnectionError: Connection refused!" in out # And the example is displayed assert "Query : {'a': 1}" in out
def test_display_failures(swagger_20, capsys, execution_context, results_set, verbosity): execution_context.verbosity = verbosity # Given two test results - success and failure endpoint = models.Endpoint("/api/failure", "GET", {}, base_url="http://127.0.0.1:8080", schema=swagger_20) failure = models.TestResult(endpoint, DataGenerationMethod.default()) failure.add_failure("test", models.Case(endpoint), "Message") execution_context.results.append(SerializedTestResult.from_test_result(failure)) results_set.append(failure) event = Finished.from_results(results_set, 1.0) # When the failures are displayed default.display_failures(execution_context, event) out = capsys.readouterr().out.strip() # Then section title is displayed assert " FAILURES " in out # And endpoint with a failure is displayed as a subsection assert " GET: /v1/api/failure " in out assert "Message" in out assert "Run this Python code to reproduce this failure: " in out assert f"requests.get('http://127.0.0.1:8080/api/failure', headers={{'User-Agent': '{USER_AGENT}'}})" in out
def test_display_failures(swagger_20, capsys, execution_context, results_set): # Given two test results - success and failure endpoint = models.Endpoint("/api/failure", "GET", {}, base_url="http://127.0.0.1:8080", schema=swagger_20) failure = models.TestResult(endpoint) failure.add_failure("test", models.Case(endpoint), "Message") execution_context.results.append(SerializedTestResult.from_test_result(failure)) results_set.append(failure) event = Finished.from_results(results_set, 1.0) # When the failures are displayed default.display_failures(execution_context, event) out = capsys.readouterr().out.strip() # Then section title is displayed assert " FAILURES " in out # And endpoint with a failure is displayed as a subsection assert " GET: /api/failure " in out assert "Message" in out # And check name is displayed assert "Check : test" in out assert "Run this Python code to reproduce this failure: " in out assert "requests.get('http://127.0.0.1:8080/api/failure')" in out
def endpoint(swagger_20): return models.Endpoint("/success", "GET", definition={}, base_url="http://127.0.0.1:8080", schema=swagger_20)
def endpoint(): return models.Endpoint("/success", "GET", definition={})
def results(request, swagger_20) -> models.TestResult: endpoint = models.Endpoint("/path", "GET", definition={"produces": request.param}) return models.TestResult(endpoint, swagger_20)
def make_test_result(schema: BaseSchema, definition: Dict[str, Any]) -> models.TestResult: endpoint = models.Endpoint("/path", "GET", definition=definition) return models.TestResult(endpoint, schema)