当前位置: 首页>>代码示例>>Python>>正文


Python HealthCheck.filter_too_much方法代码示例

本文整理汇总了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() 
开发者ID:kiwicom,项目名称:schemathesis,代码行数:23,代码来源:test_hypothesis.py

示例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() 
开发者ID:kiwicom,项目名称:schemathesis,代码行数:40,代码来源:test_asgi.py

示例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() 
开发者ID:kiwicom,项目名称:schemathesis,代码行数:40,代码来源:test_wsgi.py

示例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() 
开发者ID:kiwicom,项目名称:schemathesis,代码行数:14,代码来源:test_wsgi.py

示例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() 
开发者ID:kiwicom,项目名称:schemathesis,代码行数:32,代码来源:test_wsgi.py

示例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) 
开发者ID:kiwicom,项目名称:schemathesis,代码行数:17,代码来源:test_parameters.py

示例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() 
开发者ID:kiwicom,项目名称:schemathesis,代码行数:42,代码来源:test_parameters.py

示例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 
开发者ID:kiwicom,项目名称:schemathesis,代码行数:17,代码来源:test_commands.py

示例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 
开发者ID:kiwicom,项目名称:schemathesis,代码行数:6,代码来源:test_commands.py

示例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"]) 
开发者ID:kiwicom,项目名称:schemathesis,代码行数:31,代码来源:test_commands.py


注:本文中的hypothesis.HealthCheck.filter_too_much方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。