本文整理汇总了Python中hypothesis.HealthCheck.filter_too_much方法的典型用法代码示例。如果您正苦于以下问题:Python HealthCheck.filter_too_much方法的具体用法?Python HealthCheck.filter_too_much怎么用?Python HealthCheck.filter_too_much使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hypothesis.HealthCheck
的用法示例。
在下文中一共展示了HealthCheck.filter_too_much方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_valid_headers
# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import filter_too_much [as 别名]
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()
示例2: test_cookies
# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import filter_too_much [as 别名]
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()
示例3: test_cookies
# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import filter_too_much [as 别名]
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()
示例4: test_form_data
# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import filter_too_much [as 别名]
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()
示例5: test_binary_body
# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import filter_too_much [as 别名]
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()
示例6: test_cookies
# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import filter_too_much [as 别名]
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)
示例7: test_date_deserializing
# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import filter_too_much [as 别名]
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()
示例8: test_hypothesis_parameters
# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import filter_too_much [as 别名]
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
示例9: test_cli_binary_body
# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import filter_too_much [as 别名]
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
示例10: test_pre_run_hook_valid
# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import filter_too_much [as 别名]
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"])