How to use the schemathesis.models.Endpoint 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_models.py View on Github external
if override:
        case = Case(**kwargs)
        response = case.call(base_url)
    else:
        case = Case(**kwargs)
        endpoint.base_url = base_url
        response = case.call()
    assert response.status_code == 200
    assert response.json() == {"success": True}
    with pytest.warns(None) as records:
        del response
    assert not records


schema = schemathesis.from_path(SIMPLE_PATH)
ENDPOINT = Endpoint("/api/success", "GET", {}, base_url="http://example.com", schema=schema)


@pytest.mark.parametrize(
    "case, expected",
    (
        (Case(ENDPOINT, body={"test": 1}), "requests.get('http://example.com/api/success', json={'test': 1})"),
        (Case(ENDPOINT), "requests.get('http://example.com/api/success')"),
        (Case(ENDPOINT, query={"a": 1}), "requests.get('http://example.com/api/success', params={'a': 1})"),
    ),
)
def test_get_code_to_reproduce(case, expected):
    assert case.get_code_to_reproduce() == expected


def test_validate_response(testdir):
    testdir.make_test(
github kiwicom / schemathesis / test / test_hypothesis.py View on Github external
def make_endpoint(schema, **kwargs) -> Endpoint:
    return Endpoint("/users", "POST", definition={}, schema=schema, **kwargs)
github kiwicom / schemathesis / test / test_direct_access.py View on Github external
def test_endpoint_access(swagger_20, method):
    assert isinstance(swagger_20["/v1/users"][method], Endpoint)
github kiwicom / schemathesis / test / cli / output / test_default.py View on Github external
def test_display_failures(swagger_20, capsys, results_set):
    # Given two test results - success and failure
    endpoint = models.Endpoint("/api/failure", "GET", {}, base_url="http://127.0.0.1:8080", schema=swagger_20)
    failure = models.TestResult(endpoint)
    failure.add_failure("test", models.Case(endpoint), "Message")
    results_set.append(failure)
    # When the failures are displayed
    default.display_failures(results_set)
    out = capsys.readouterr().out.strip()
    # Then section title is displayed
    assert " FAILURES " in out
    # And endpoint with a failure is displayed as a subsection
    assert " GET: /api/failure " in out
    assert "Message" in out
    # And check name is displayed
    assert "Check           : test" in out
    assert "Run this Python code to reproduce this failure: " in out
    assert "requests.get('http://127.0.0.1:8080/api/failure')" in out
github kiwicom / schemathesis / test / test_hypothesis.py View on Github external
def test_no_body_in_get(swagger_20):
    endpoint = Endpoint(
        path="/api/success",
        method="GET",
        definition={},
        schema=swagger_20,
        query={
            "required": ["name"],
            "type": "object",
            "additionalProperties": False,
            "properties": {"name": {"type": "string"}},
            "example": {"name": "John"},
        },
    )
    assert list(get_examples(endpoint))[0].body is None
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)