Esempio n. 1
0
def test_make_endpoint_invalid_location(parameter):
    with pytest.raises(
            ValueError,
            match=
            f"Parameter `{parameter}` is not defined in endpoint GET /users/{{user_id}}"
    ):
        LINK.make_endpoint([ParsedData({parameter: 4})])
Esempio n. 2
0
def test_make_operation_single():
    operation = LINK.make_operation([ParsedData({"path.user_id": 1, "query.user_id": 2, "code": 7})])
    assert len(operation.path_parameters) == 1
    assert isinstance(operation.path_parameters[0], OpenAPI30Parameter)
    assert operation.path_parameters[0].definition == {"in": "path", "name": "user_id", "schema": {"enum": [1]}}
    for item in operation.query:
        schema = item.definition["schema"]
        if item.name == "code":
            assert schema == {"enum": [7]}
        elif item.name == "user_id":
            assert schema == {"enum": [2]}
        else:
            assert schema == {"type": "integer"}
Esempio n. 3
0
def test_make_endpoint_single():
    endpoint = LINK.make_endpoint([ParsedData({"path.user_id": 1, "query.user_id": 2, "code": 7})])
    assert endpoint.path_parameters == ParameterSet(
        [OpenAPI30Parameter({"in": "path", "name": "user_id", "schema": {"enum": [1]}})]
    )
    for item in endpoint.query:
        schema = item.definition["schema"]
        if item.name == "code":
            assert schema == {"enum": [7]}
        elif item.name == "user_id":
            assert schema == {"enum": [2]}
        else:
            assert schema == {"type": "integer"}
Esempio n. 4
0
def test_make_endpoint_single():
    endpoint = LINK.make_endpoint(
        [ParsedData({
            "path.user_id": 1,
            "query.user_id": 2,
            "code": 7
        })])
    assert endpoint.path_parameters == {
        "properties": {
            "user_id": {
                "in": "path",
                "name": "user_id",
                "type": "integer",
                "const": 1
            }
        },
        "additionalProperties": False,
        "type": "object",
        "required": ["user_id"],
    }
    assert endpoint.query == {
        "properties": {
            "code": {
                "in": "query",
                "name": "code",
                "type": "integer",
                "const": 7
            },
            "user_id": {
                "in": "query",
                "name": "user_id",
                "type": "integer",
                "const": 2
            },
            "common": {
                "in": "query",
                "name": "common",
                "type": "integer"
            },
        },
        "additionalProperties": False,
        "type": "object",
        "required": ["code", "user_id", "common"],
    }
Esempio n. 5
0
def test_make_operation_body(body):
    # See GH-1069
    # When `requestBody` is present in the link definition
    # And in the target operation
    operation = APIOperation(
        path="/users/",
        method="post",
        verbose_name="GET /users/{user_id}",
        definition=ANY,
        schema=ANY,
        base_url=ANY,
        body=PayloadAlternatives([body]),
    )
    body = {"foo": "bar"}  # Literal value
    link = Link(
        name="Link",
        operation=operation,
        parameters={},
        request_body={"requestBody": body},
    )
    # Then it should be taken into account during creation a modified version of that operation
    new_operation = link.make_operation([ParsedData(
        {}, body=body)])  # Actual parsed data will contain the literal
    assert new_operation.body[0].definition["schema"] == {"enum": [body]}
Esempio n. 6
0
        ("/unknown", []),
    ),
)
@pytest.mark.operations("create_user", "get_user", "update_user")
def test_get_links(openapi3_base_url, schema_url, url, expected):
    schema = schemathesis.from_uri(schema_url)
    response = requests.post(f"{openapi3_base_url}{url}", json={"first_name": "TEST", "last_name": "TEST"})
    tests = schema["/users/"]["POST"].get_stateful_tests(response, Stateful.links)
    assert len(tests) == len(expected)
    for test, value in zip(tests, expected):
        assert test.name == value.name
        assert test.parameters == value.parameters


def test_parse(case, response):
    assert LINK.parse(case, response) == ParsedData({"path.user_id": 5, "query.user_id": 5})


EXPECTED_PATH_PARAMETERS = [
    {
        "additionalProperties": False,
        "properties": {"user_id": {"const": 1, "in": "path", "name": "user_id", "type": "integer"}},
        "required": ["user_id"],
        "type": "object",
    },
    {
        "additionalProperties": False,
        "properties": {"user_id": {"const": 3, "in": "path", "name": "user_id", "type": "integer"}},
        "required": ["user_id"],
        "type": "object",
    },
Esempio n. 7
0
def test_hashable(parameters, body):
    # All parsed data should be hashable
    hash(ParsedData(parameters, body))
Esempio n. 8
0
def test_hashable(parameters, body):
    hash(ParsedData(parameters, body))