Skip to content

Commit 7a66ec9

Browse files
committed
Update end to end tests with camel case check
- Fix broken end to end check - Pretty-print generated OpenAPI document - Add camelCase property and endpoint to E2E
1 parent b523f90 commit 7a66ec9

File tree

8 files changed

+222
-14
lines changed

8 files changed

+222
-14
lines changed

tests/test_end_to_end/fastapi/__init__.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
""" A FastAPI app used to create an OpenAPI document for end-to-end testing """
22
import json
3+
from datetime import datetime
34
from enum import Enum
45
from pathlib import Path
56
from typing import List
@@ -43,9 +44,10 @@ class AModel(BaseModel):
4344
a_list_of_enums: List[AnEnum]
4445
a_list_of_strings: List[str]
4546
a_list_of_objects: List[OtherModel]
47+
aCamelDateTime: datetime
4648

4749

48-
@test_router.get("/", response_model=List[AModel])
50+
@test_router.get("/", response_model=List[AModel], operation_id="getUserList")
4951
def get_list(statuses: List[AnEnum] = Query(...),):
5052
""" Get users, filtered by statuses """
5153
return
@@ -55,4 +57,4 @@ def get_list(statuses: List[AnEnum] = Query(...),):
5557

5658
if __name__ == "__main__":
5759
path = Path(__file__).parent / "openapi.json"
58-
path.write_text(json.dumps(app.openapi()))
60+
path.write_text(json.dumps(app.openapi(), indent=4))
+202-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,202 @@
1-
{"openapi": "3.0.2", "info": {"title": "My Test API", "description": "An API for testing openapi-python-client", "version": "0.1.0"}, "paths": {"/ping": {"get": {"summary": "Ping", "description": "A quick check to see if the system is running ", "operationId": "ping_ping_get", "responses": {"200": {"description": "Successful Response", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/_ABCResponse"}}}}}}}, "/tests/": {"get": {"tags": ["users"], "summary": "Get List", "description": "Get users, filtered by statuses ", "operationId": "get_list_tests__get", "parameters": [{"required": true, "schema": {"title": "Statuses", "type": "array", "items": {"enum": ["FIRST_VALUE", "SECOND_VALUE"]}}, "name": "statuses", "in": "query"}], "responses": {"200": {"description": "Successful Response", "content": {"application/json": {"schema": {"title": "Response Get List Tests Get", "type": "array", "items": {"$ref": "#/components/schemas/AModel"}}}}}, "422": {"description": "Validation Error", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/HTTPValidationError"}}}}}}}}, "components": {"schemas": {"AModel": {"title": "AModel", "required": ["an_enum_value", "a_list_of_enums", "a_list_of_strings", "a_list_of_objects"], "type": "object", "properties": {"an_enum_value": {"title": "An Enum Value", "enum": ["FIRST_VALUE", "SECOND_VALUE"]}, "a_list_of_enums": {"title": "A List Of Enums", "type": "array", "items": {"enum": ["FIRST_VALUE", "SECOND_VALUE"]}}, "a_list_of_strings": {"title": "A List Of Strings", "type": "array", "items": {"type": "string"}}, "a_list_of_objects": {"title": "A List Of Objects", "type": "array", "items": {"$ref": "#/components/schemas/OtherModel"}}}, "description": "A Model for testing all the ways custom objects can be used "}, "HTTPValidationError": {"title": "HTTPValidationError", "type": "object", "properties": {"detail": {"title": "Detail", "type": "array", "items": {"$ref": "#/components/schemas/ValidationError"}}}}, "OtherModel": {"title": "OtherModel", "required": ["a_value"], "type": "object", "properties": {"a_value": {"title": "A Value", "type": "string"}}, "description": "A different model for calling from TestModel "}, "ValidationError": {"title": "ValidationError", "required": ["loc", "msg", "type"], "type": "object", "properties": {"loc": {"title": "Location", "type": "array", "items": {"type": "string"}}, "msg": {"title": "Message", "type": "string"}, "type": {"title": "Error Type", "type": "string"}}}, "_ABCResponse": {"title": "_ABCResponse", "required": ["success"], "type": "object", "properties": {"success": {"title": "Success", "type": "boolean"}}}}}}
1+
{
2+
"openapi": "3.0.2",
3+
"info": {
4+
"title": "My Test API",
5+
"description": "An API for testing openapi-python-client",
6+
"version": "0.1.0"
7+
},
8+
"paths": {
9+
"/ping": {
10+
"get": {
11+
"summary": "Ping",
12+
"description": "A quick check to see if the system is running ",
13+
"operationId": "ping_ping_get",
14+
"responses": {
15+
"200": {
16+
"description": "Successful Response",
17+
"content": {
18+
"application/json": {
19+
"schema": {
20+
"$ref": "#/components/schemas/_ABCResponse"
21+
}
22+
}
23+
}
24+
}
25+
}
26+
}
27+
},
28+
"/tests/": {
29+
"get": {
30+
"tags": [
31+
"users"
32+
],
33+
"summary": "Get List",
34+
"description": "Get users, filtered by statuses ",
35+
"operationId": "getUserList",
36+
"parameters": [
37+
{
38+
"required": true,
39+
"schema": {
40+
"title": "Statuses",
41+
"type": "array",
42+
"items": {
43+
"enum": [
44+
"FIRST_VALUE",
45+
"SECOND_VALUE"
46+
]
47+
}
48+
},
49+
"name": "statuses",
50+
"in": "query"
51+
}
52+
],
53+
"responses": {
54+
"200": {
55+
"description": "Successful Response",
56+
"content": {
57+
"application/json": {
58+
"schema": {
59+
"title": "Response Get List Tests Get",
60+
"type": "array",
61+
"items": {
62+
"$ref": "#/components/schemas/AModel"
63+
}
64+
}
65+
}
66+
}
67+
},
68+
"422": {
69+
"description": "Validation Error",
70+
"content": {
71+
"application/json": {
72+
"schema": {
73+
"$ref": "#/components/schemas/HTTPValidationError"
74+
}
75+
}
76+
}
77+
}
78+
}
79+
}
80+
}
81+
},
82+
"components": {
83+
"schemas": {
84+
"AModel": {
85+
"title": "AModel",
86+
"required": [
87+
"an_enum_value",
88+
"a_list_of_enums",
89+
"a_list_of_strings",
90+
"a_list_of_objects",
91+
"aCamelDateTime"
92+
],
93+
"type": "object",
94+
"properties": {
95+
"an_enum_value": {
96+
"title": "An Enum Value",
97+
"enum": [
98+
"FIRST_VALUE",
99+
"SECOND_VALUE"
100+
]
101+
},
102+
"a_list_of_enums": {
103+
"title": "A List Of Enums",
104+
"type": "array",
105+
"items": {
106+
"enum": [
107+
"FIRST_VALUE",
108+
"SECOND_VALUE"
109+
]
110+
}
111+
},
112+
"a_list_of_strings": {
113+
"title": "A List Of Strings",
114+
"type": "array",
115+
"items": {
116+
"type": "string"
117+
}
118+
},
119+
"a_list_of_objects": {
120+
"title": "A List Of Objects",
121+
"type": "array",
122+
"items": {
123+
"$ref": "#/components/schemas/OtherModel"
124+
}
125+
},
126+
"aCamelDateTime": {
127+
"title": "Acameldatetime",
128+
"type": "string",
129+
"format": "date-time"
130+
}
131+
},
132+
"description": "A Model for testing all the ways custom objects can be used "
133+
},
134+
"HTTPValidationError": {
135+
"title": "HTTPValidationError",
136+
"type": "object",
137+
"properties": {
138+
"detail": {
139+
"title": "Detail",
140+
"type": "array",
141+
"items": {
142+
"$ref": "#/components/schemas/ValidationError"
143+
}
144+
}
145+
}
146+
},
147+
"OtherModel": {
148+
"title": "OtherModel",
149+
"required": [
150+
"a_value"
151+
],
152+
"type": "object",
153+
"properties": {
154+
"a_value": {
155+
"title": "A Value",
156+
"type": "string"
157+
}
158+
},
159+
"description": "A different model for calling from TestModel "
160+
},
161+
"ValidationError": {
162+
"title": "ValidationError",
163+
"required": [
164+
"loc",
165+
"msg",
166+
"type"
167+
],
168+
"type": "object",
169+
"properties": {
170+
"loc": {
171+
"title": "Location",
172+
"type": "array",
173+
"items": {
174+
"type": "string"
175+
}
176+
},
177+
"msg": {
178+
"title": "Message",
179+
"type": "string"
180+
},
181+
"type": {
182+
"title": "Error Type",
183+
"type": "string"
184+
}
185+
}
186+
},
187+
"_ABCResponse": {
188+
"title": "_ABCResponse",
189+
"required": [
190+
"success"
191+
],
192+
"type": "object",
193+
"properties": {
194+
"success": {
195+
"title": "Success",
196+
"type": "boolean"
197+
}
198+
}
199+
}
200+
}
201+
}
202+
}

tests/test_end_to_end/golden-master/my_test_api_client/api/default.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def ping_ping_get(
1414
ABCResponse,
1515
]:
1616
""" A quick check to see if the system is running """
17-
url = f"{client.base_url}/ping"
17+
url = "{}/ping".format(client.base_url)
1818

1919
response = httpx.get(url=url, headers=client.get_headers(),)
2020

tests/test_end_to_end/golden-master/my_test_api_client/api/users.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
from ..models.statuses import Statuses
1111

1212

13-
def get_list_tests__get(
13+
def get_user_list(
1414
*, client: Client, statuses: List[Statuses],
1515
) -> Union[
1616
List[AModel], HTTPValidationError,
1717
]:
1818
""" Get users, filtered by statuses """
19-
url = f"{client.base_url}/tests/"
19+
url = "{}/tests/".format(client.base_url)
2020

2121
params = {
2222
"statuses": statuses,

tests/test_end_to_end/golden-master/my_test_api_client/async_api/default.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ async def ping_ping_get(
1414
ABCResponse,
1515
]:
1616
""" A quick check to see if the system is running """
17-
url = f"{client.base_url}/ping"
17+
url = "{}/ping".format(client.base_url)
1818

1919
async with httpx.AsyncClient() as _client:
2020
response = await _client.get(url=url, headers=client.get_headers(),)

tests/test_end_to_end/golden-master/my_test_api_client/async_api/users.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
from ..models.statuses import Statuses
1111

1212

13-
async def get_list_tests__get(
13+
async def get_user_list(
1414
*, client: Client, statuses: List[Statuses],
1515
) -> Union[
1616
List[AModel], HTTPValidationError,
1717
]:
1818
""" Get users, filtered by statuses """
19-
url = f"{client.base_url}/tests/"
19+
url = "{}/tests/".format(client.base_url)
2020

2121
params = {
2222
"statuses": statuses,

tests/test_end_to_end/golden-master/my_test_api_client/models/a_model.py

+6
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ class AModel:
1717
a_list_of_enums: List[AListOfEnums]
1818
a_list_of_strings: List[str]
1919
a_list_of_objects: List[OtherModel]
20+
a_camel_date_time: datetime
2021

2122
def to_dict(self) -> Dict[str, Any]:
2223
return {
2324
"an_enum_value": self.an_enum_value.value,
2425
"a_list_of_enums": self.a_list_of_enums,
2526
"a_list_of_strings": self.a_list_of_strings,
2627
"a_list_of_objects": self.a_list_of_objects,
28+
"aCamelDateTime": self.a_camel_date_time,
2729
}
2830

2931
@staticmethod
@@ -40,9 +42,13 @@ def from_dict(d: Dict[str, Any]) -> AModel:
4042
a_list_of_objects = []
4143
for a_list_of_objects_item in d.get("a_list_of_objects", []):
4244
a_list_of_objects.append(OtherModel.from_dict(a_list_of_objects_item))
45+
46+
a_camel_date_time = datetime.fromisoformat(d["aCamelDateTime"])
47+
4348
return AModel(
4449
an_enum_value=an_enum_value,
4550
a_list_of_enums=a_list_of_enums,
4651
a_list_of_strings=a_list_of_strings,
4752
a_list_of_objects=a_list_of_objects,
53+
a_camel_date_time=a_camel_date_time,
4854
)

tests/test_end_to_end/test_end_to_end.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ def _compare_directories(first: Path, second: Path, /):
1818

1919
match, mismatch, errors = cmpfiles(first, second, dc.common_files, shallow=False)
2020
if mismatch:
21-
for error in errors:
22-
pytest.fail(
23-
f"{first_printable} and {second_printable} had differing files: {mismatch}, first error is {error}",
24-
pytrace=False,
25-
)
21+
pytest.fail(
22+
f"{first_printable} and {second_printable} had differing files: {mismatch}, and errors {errors}",
23+
pytrace=False,
24+
)
2625

2726
for sub_path in dc.common_dirs:
2827
_compare_directories(first / sub_path, second / sub_path)

0 commit comments

Comments
 (0)