-
-
Notifications
You must be signed in to change notification settings - Fork 227
/
Copy pathtest_open_api.py
45 lines (39 loc) · 1.26 KB
/
test_open_api.py
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
41
42
43
44
45
import pytest
from pydantic import ValidationError
from openapi_python_client.schema import OpenAPI
@pytest.mark.parametrize(
"version, valid",
[
("abc", False),
("1", False),
("2.0", False),
("3.0.0", True),
("3.1.1", True),
("3.2.0", False),
("4.0.0", False),
],
)
def test_validate_version(version, valid):
data = {"openapi": version, "info": {"title": "test", "version": ""}, "paths": {}}
if valid:
OpenAPI.model_validate(data)
else:
with pytest.raises(ValidationError):
OpenAPI.model_validate(data)
def test_parse_with_callback():
data = {
"openapi": "3.0.1",
"info": {"title": "API with Callback", "version": ""},
"paths": {
"/create": {
"post": {
"responses": {"200": {"description": "Success"}},
"callbacks": {"event": {"callback": {"post": {"responses": {"200": {"description": "Success"}}}}}},
}
}
},
}
open_api = OpenAPI.model_validate(data)
create_endpoint = open_api.paths["/create"]
assert "200" in create_endpoint.post.responses
assert "200" in create_endpoint.post.callbacks["event"]["callback"].post.responses