Python hypothesis.HealthCheck.filter_too_much() Examples
The following are 10
code examples of hypothesis.HealthCheck.filter_too_much().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
hypothesis.HealthCheck
, or try the search function
.
Example #1
Source File: test_hypothesis.py From schemathesis with MIT License | 7 votes |
def test_valid_headers(base_url, swagger_20, definition): endpoint = Endpoint( "/api/success", "GET", definition=EndpointDefinition({}, {}, "foo"), schema=swagger_20, base_url=base_url, headers={ "properties": {"api_key": definition}, "additionalProperties": False, "type": "object", "required": ["api_key"], }, ) @given(case=get_case_strategy(endpoint)) @settings(suppress_health_check=[HealthCheck.filter_too_much, HealthCheck.too_slow], deadline=None, max_examples=10) def inner(case): case.call() inner()
Example #2
Source File: test_asgi.py From schemathesis with MIT License | 5 votes |
def test_cookies(fastapi_app): @fastapi_app.get("/cookies") def cookies(token: str = Cookie(None)): return {"token": token} schema = schemathesis.from_dict( { "openapi": "3.0.2", "info": {"title": "Test", "description": "Test", "version": "0.1.0"}, "paths": { "/cookies": { "get": { "parameters": [ { "name": "token", "in": "cookie", "required": True, "schema": {"type": "string", "enum": ["test"]}, } ], "responses": {"200": {"description": "OK"}}, } } }, }, app=fastapi_app, ) strategy = schema.endpoints["/cookies"]["GET"].as_strategy() @given(case=strategy) @settings(max_examples=3, suppress_health_check=[HealthCheck.filter_too_much]) def test(case): response = case.call_asgi() assert response.status_code == 200 assert response.json() == {"token": "test"} test()
Example #3
Source File: test_wsgi.py From schemathesis with MIT License | 5 votes |
def test_cookies(flask_app): @flask_app.route("/cookies", methods=["GET"]) def cookies(): return jsonify(request.cookies) schema = schemathesis.from_dict( { "openapi": "3.0.2", "info": {"title": "Test", "description": "Test", "version": "0.1.0"}, "paths": { "/cookies": { "get": { "parameters": [ { "name": "token", "in": "cookie", "required": True, "schema": {"type": "string", "enum": ["test"]}, } ], "responses": {"200": {"description": "OK"}}, } } }, }, app=flask_app, ) strategy = schema.endpoints["/cookies"]["GET"].as_strategy() @given(case=strategy) @settings(max_examples=3, suppress_health_check=[HealthCheck.filter_too_much]) def test(case): response = case.call_wsgi() assert response.status_code == 200 assert response.json == {"token": "test"} test()
Example #4
Source File: test_wsgi.py From schemathesis with MIT License | 5 votes |
def test_form_data(schema): strategy = schema.endpoints["/multipart"]["POST"].as_strategy() @given(case=strategy) @settings(max_examples=3, suppress_health_check=[HealthCheck.filter_too_much]) def test(case): response = case.call_wsgi() assert response.status_code == 200 # converted to string in the app assert response.json == {key: str(value) for key, value in case.form_data.items()} test()
Example #5
Source File: test_wsgi.py From schemathesis with MIT License | 5 votes |
def test_binary_body(mocker, flask_app): # When an endpoint accepts a binary input schema = schemathesis.from_dict( { "openapi": "3.0.2", "info": {"title": "Test", "description": "Test", "version": "0.1.0"}, "paths": { "/api/upload_file": { "post": { "requestBody": { "content": {"application/octet-stream": {"schema": {"format": "binary", "type": "string"}}} }, "responses": {"200": {"description": "OK"}}, } } }, }, app=flask_app, ) strategy = schema.endpoints["/api/upload_file"]["POST"].as_strategy() @given(case=strategy) @settings(max_examples=3, suppress_health_check=[HealthCheck.filter_too_much]) def test(case): response = case.call_wsgi() assert response.status_code == 200 assert response.json == {"size": mocker.ANY} # Then it should be send correctly test()
Example #6
Source File: test_parameters.py From schemathesis with MIT License | 5 votes |
def test_cookies(testdir): # When parameter is specified for "cookie" testdir.make_test( """ @schema.parametrize() @settings(suppress_health_check=[HealthCheck.filter_too_much], deadline=None) def test_(case): assert_str(case.cookies["token"]) assert_requests_call(case) """, schema_name="simple_openapi.yaml", **as_param({"name": "token", "in": "cookie", "required": True, "schema": {"type": "string"}}), ) # Then the generated test case should contain it in its `cookies` attribute testdir.run_and_assert(passed=1)
Example #7
Source File: test_parameters.py From schemathesis with MIT License | 5 votes |
def test_date_deserializing(testdir): # When dates in schema are written without quotes (achieved by dumping the schema with date instances) schema = { "openapi": "3.0.2", "info": {"title": "Test", "description": "Test", "version": "0.1.0"}, "paths": { "/teapot": { "get": { "summary": "Test", "parameters": [ { "name": "key", "in": "query", "required": True, "schema": { "allOf": [ # For sake of example to check allOf logic {"type": "string", "example": datetime.date(2020, 1, 1)}, {"type": "string", "example": datetime.date(2020, 1, 1)}, ] }, } ], "responses": {"200": {"description": "OK"}}, } } }, } schema_path = testdir.makefile(".yaml", schema=yaml.dump(schema)) # Then yaml loader should ignore it # And data generation should work without errors schema = schemathesis.from_path(str(schema_path)) @given(case=schema["/teapot"]["GET"].as_strategy()) @settings(suppress_health_check=[HealthCheck.filter_too_much]) def test(case): assert isinstance(case.query["key"], str) test()
Example #8
Source File: test_commands.py From schemathesis with MIT License | 5 votes |
def test_hypothesis_parameters(cli, schema_url): # When Hypothesis options are passed via command line result = cli.run( schema_url, "--hypothesis-deadline=1000", "--hypothesis-derandomize", "--hypothesis-max-examples=1000", "--hypothesis-phases=explicit,generate", "--hypothesis-report-multiple-bugs=0", "--hypothesis-suppress-health-check=too_slow,filter_too_much", "--hypothesis-verbosity=normal", ) # Then they should be correctly converted into arguments accepted by `hypothesis.settings` # Parameters are validated in `hypothesis.settings` assert result.exit_code == ExitCode.OK, result.stdout
Example #9
Source File: test_commands.py From schemathesis with MIT License | 5 votes |
def test_cli_binary_body(cli, schema_url): result = cli.run(schema_url, "--hypothesis-suppress-health-check=filter_too_much") assert result.exit_code == ExitCode.OK, result.stdout assert " HYPOTHESIS OUTPUT " not in result.stdout
Example #10
Source File: test_commands.py From schemathesis with MIT License | 5 votes |
def test_pre_run_hook_valid(testdir, cli, schema_url, app): # When `--pre-run` hook is passed to the CLI call module = testdir.make_importable_pyfile( hook=""" import string import schemathesis from hypothesis import strategies as st schemathesis.register_string_format( "digits", st.text( min_size=1, alphabet=st.characters( whitelist_characters=string.digits, whitelist_categories=() ) ) ) """ ) result = cli.main( "--pre-run", module.purebasename, "run", "--hypothesis-suppress-health-check=filter_too_much", schema_url ) # Then CLI should run successfully assert result.exit_code == ExitCode.OK, result.stdout # And all registered new string format should produce digits as expected assert all(request.query["id"].isdigit() for request in app["incoming_requests"])