How to use the schemathesis._hypothesis.get_case_strategy function in schemathesis

To help you get started, we’ve selected a few schemathesis examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kiwicom / schemathesis / test / test_hypothesis.py View on Github external
def test_default_strategies_bytes(swagger_20):
    endpoint = make_endpoint(
        swagger_20,
        body={
            "required": ["byte"],
            "type": "object",
            "additionalProperties": False,
            "properties": {"byte": {"type": "string", "format": "byte"}},
        },
    )
    result = get_case_strategy(endpoint).example()
    assert isinstance(result.body["byte"], str)
    b64decode(result.body["byte"])
github kiwicom / schemathesis / test / test_hypothesis.py View on Github external
def test_custom_strategies(swagger_20):
    register_string_format("even_4_digits", strategies.from_regex(r"\A[0-9]{4}\Z").filter(lambda x: int(x) % 2 == 0))
    endpoint = make_endpoint(
        swagger_20,
        query={
            "required": ["id"],
            "type": "object",
            "additionalProperties": False,
            "properties": {"id": {"type": "string", "format": "even_4_digits"}},
        },
    )
    result = get_case_strategy(endpoint).example()
    assert len(result.query["id"]) == 4
    assert int(result.query["id"]) % 2 == 0
github kiwicom / schemathesis / test / test_hypothesis.py View on Github external
    @given(case=get_case_strategy(endpoint))
    def inner(case):
        case.call()
github kiwicom / schemathesis / test / test_hypothesis.py View on Github external
def test_invalid_body_in_get(swagger_20):
    endpoint = Endpoint(
        path="/foo",
        method="GET",
        definition={},
        schema=swagger_20,
        body={"required": ["foo"], "type": "object", "properties": {"foo": {"type": "string"}}},
    )
    with pytest.raises(InvalidSchema, match=r"^Body parameters are defined for GET request.$"):
        get_case_strategy(endpoint)
github kiwicom / schemathesis / test / test_hypothesis.py View on Github external
def test_default_strategies_binary(swagger_20):
    endpoint = make_endpoint(
        swagger_20,
        form_data={
            "required": ["file"],
            "type": "object",
            "additionalProperties": False,
            "properties": {"file": {"type": "string", "format": "binary"}},
        },
    )
    result = get_case_strategy(endpoint).example()
    assert isinstance(result.form_data["file"], bytes)