forked from openapi-generators/openapi-python-client
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_bodies.py
More file actions
40 lines (36 loc) · 1.48 KB
/
test_bodies.py
File metadata and controls
40 lines (36 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from openapi_python_client import schema as oai
from openapi_python_client.parser.bodies import body_from_data
from openapi_python_client.parser.errors import ParseError
from openapi_python_client.parser.properties import Schemas
def test_errors(config):
operation = oai.Operation(
requestBody=oai.RequestBody(
content={
"invalid content type": oai.MediaType(
media_type_schema=oai.Schema(
type=oai.DataType.STRING,
)
),
"application/json": oai.MediaType(
media_type_schema=None # Missing media type schema is an error
),
"text/html": oai.MediaType( # content type not supported by the generator
media_type_schema=oai.Schema(
type=oai.DataType.STRING,
)
),
"application/sushi+json": oai.MediaType(
media_type_schema=oai.Schema(
type=oai.DataType.INTEGER,
default="make this an invalid property",
)
),
}
),
responses={},
)
errs, _ = body_from_data(
data=operation, schemas=Schemas(), config=config, endpoint_name="this will not succeed", request_bodies={}
)
assert len(errs) == len(operation.request_body.content)
assert all(isinstance(err, ParseError) for err in errs)