def test_execute_base_url_not_found(openapi3_base_url, schema_url, app): # When base URL is pointing to an unknown location schema = oas_loaders.from_uri(schema_url, base_url=f"{openapi3_base_url}/404/") execute(schema) # Then the runner should use this base # And they will not reach the application assert_incoming_requests_num(app, 0)
def test_invalid_path_parameter(schema_url): # When a path parameter is marked as not required # And schema validation is disabled schema = oas_loaders.from_uri(schema_url, validate_schema=False) init, *others, finished = from_schema(schema, hypothesis_settings=hypothesis.settings(max_examples=3)).execute() # Then Schemathesis enforces all path parameters to be required # And there should be no errors assert not finished.has_errors
def test_execute_filter_endpoint(app, schema_url): schema = oas_loaders.from_uri(schema_url, endpoint=["success"]) # When `endpoint` is passed in the `execute` call execute(schema) # Then the runner will make calls only to the specified path assert_incoming_requests_num(app, 1) assert_request(app, 0, "GET", "/api/success") assert_not_request(app, "GET", "/api/failure")
def test_base_url(openapi3_base_url, schema_url, app, converter): base_url = converter(openapi3_base_url) # When `base_url` is specified explicitly with or without trailing slash schema = oas_loaders.from_uri(schema_url, base_url=base_url) execute(schema) # Then each request should reach the app in both cases assert_incoming_requests_num(app, 3) assert_request(app, 0, "GET", "/api/failure") assert_request(app, 1, "GET", "/api/failure") assert_request(app, 2, "GET", "/api/success")
def test_exceptions(schema_url, app, loader_options, from_schema_options): schema = oas_loaders.from_uri(schema_url, **loader_options) results = from_schema(schema, **from_schema_options).execute() assert any([event.status == Status.error for event in results if isinstance(event, events.AfterExecution)])
def test_execute_filter_method(app, schema_url): schema = oas_loaders.from_uri(schema_url, method="POST") # When `method` corresponds to a method that is not defined in the app schema execute(schema) # Then runner will not make any requests assert_incoming_requests_num(app, 0)
def real_app_schema(schema_url): return oas_loaders.from_uri(schema_url)