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]}
def test_invalid_request_body_definition(): # When a link defines `requestBody` for operation that does not accept one operation = APIOperation( path="/users/", method="get", verbose_name="GET /users/{user_id}", definition=ANY, schema=ANY, base_url=ANY, ) # Then a proper error should be triggered with pytest.raises(ValueError): Link(name="Link", operation=operation, parameters={}, request_body={"requestBody": { "foo": "bar" }})
path_parameters=ParameterSet( [ OpenAPI30Parameter({"in": "path", "name": "user_id", "schema": {"type": "integer"}}), ] ), query=ParameterSet( [ OpenAPI30Parameter({"in": "query", "name": "code", "schema": {"type": "integer"}}), OpenAPI30Parameter({"in": "query", "name": "user_id", "schema": {"type": "integer"}}), OpenAPI30Parameter({"in": "query", "name": "common", "schema": {"type": "integer"}}), ] ), ) LINK = Link( name="GetUserByUserId", operation=API_OPERATION, parameters={"path.user_id": "$response.body#/id", "query.user_id": "$response.body#/id"}, ) @pytest.fixture(scope="module") def case(): return Case(API_OPERATION) @pytest.fixture(scope="module") def response(): response = requests.Response() response._content = b'{"id": 5}' response.status_code = 201 response.headers["Content-Type"] = "application/json"
}, "common": { "in": "query", "name": "common", "type": "integer" }, }, "additionalProperties": False, "type": "object", "required": ["code", "user_id", "common"], }, ) LINK = Link( name="GetUserByUserId", endpoint=ENDPOINT, parameters={ "path.user_id": "$response.body#/id", "query.user_id": "$response.body#/id" }, ) @pytest.fixture(scope="module") def case(): return Case(ENDPOINT) @pytest.fixture(scope="module") def response(): response = requests.Response() response._content = b'{"id": 5}' response.status_code = 201
}, "common": { "in": "query", "name": "common", "type": "integer" }, }, "additionalProperties": False, "type": "object", "required": ["code", "user_id", "common"], }, ) LINK = Link( name="GetUserByUserId", endpoint=ENDPOINT, parameters={ "path.user_id": "$response.body#/id", "query.user_id": "$response.body#/id" }, ) @pytest.fixture(scope="module") def case(): return Case(ENDPOINT) @pytest.fixture(scope="module") def response(): response = requests.Response() response._content = b'{"id": 5}' response.status_code = 201