Skip to content

Commit 564849e

Browse files
committed
test: Add e2e test for tag beginning with number
1 parent e055217 commit 564849e

File tree

6 files changed

+100
-5
lines changed

6 files changed

+100
-5
lines changed

end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from my_test_api_client.api.default import DefaultEndpoints
66
from my_test_api_client.api.parameters import ParametersEndpoints
7+
from my_test_api_client.api.tag1 import Tag1Endpoints
78
from my_test_api_client.api.tests import TestsEndpoints
89

910

@@ -19,3 +20,7 @@ def default(cls) -> Type[DefaultEndpoints]:
1920
@classmethod
2021
def parameters(cls) -> Type[ParametersEndpoints]:
2122
return ParametersEndpoints
23+
24+
@classmethod
25+
def tag1(cls) -> Type[Tag1Endpoints]:
26+
return Tag1Endpoints
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
""" Contains methods for accessing the API Endpoints """
2+
3+
import types
4+
5+
from my_test_api_client.api.tag1 import get_tag_with_number
6+
7+
8+
class Tag1Endpoints:
9+
@classmethod
10+
def get_tag_with_number(cls) -> types.ModuleType:
11+
return get_tag_with_number

end_to_end_tests/golden-record/my_test_api_client/api/tag1/__init__.py

Whitespace-only changes.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
from typing import Any, Dict
2+
3+
import httpx
4+
5+
from ...client import Client
6+
from ...types import Response
7+
8+
9+
def _get_kwargs(
10+
*,
11+
client: Client,
12+
) -> Dict[str, Any]:
13+
url = "{}/tag_with_number".format(client.base_url)
14+
15+
headers: Dict[str, Any] = client.get_headers()
16+
cookies: Dict[str, Any] = client.get_cookies()
17+
18+
return {
19+
"url": url,
20+
"headers": headers,
21+
"cookies": cookies,
22+
"timeout": client.get_timeout(),
23+
}
24+
25+
26+
def _build_response(*, response: httpx.Response) -> Response[Any]:
27+
return Response(
28+
status_code=response.status_code,
29+
content=response.content,
30+
headers=response.headers,
31+
parsed=None,
32+
)
33+
34+
35+
def sync_detailed(
36+
*,
37+
client: Client,
38+
) -> Response[Any]:
39+
kwargs = _get_kwargs(
40+
client=client,
41+
)
42+
43+
response = httpx.get(
44+
**kwargs,
45+
)
46+
47+
return _build_response(response=response)
48+
49+
50+
async def asyncio_detailed(
51+
*,
52+
client: Client,
53+
) -> Response[Any]:
54+
kwargs = _get_kwargs(
55+
client=client,
56+
)
57+
58+
async with httpx.AsyncClient() as _client:
59+
response = await _client.get(**kwargs)
60+
61+
return _build_response(response=response)

end_to_end_tests/openapi.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,16 @@
823823
}
824824
}
825825
}
826+
},
827+
"/tag_with_number": {
828+
"get": {
829+
"tags": [1],
830+
"responses": {
831+
"200": {
832+
"description": "Success"
833+
}
834+
}
835+
}
826836
}
827837
},
828838
"components": {

end_to_end_tests/test_end_to_end.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import shutil
23
from filecmp import cmpfiles, dircmp
34
from pathlib import Path
@@ -101,18 +102,25 @@ def test_end_to_end():
101102

102103
def test_custom_templates():
103104
expected_differences = {} # key: path relative to generated directory, value: expected generated content
105+
api_dir = Path("my_test_api_client").joinpath("api")
106+
golden_tpls_root_dir = Path(__file__).parent.joinpath("custom-templates-golden-record")
107+
104108
expected_difference_paths = [
105109
Path("README.md"),
106-
Path("my_test_api_client").joinpath("api", "__init__.py"),
107-
Path("my_test_api_client").joinpath("api", "tests", "__init__.py"),
108-
Path("my_test_api_client").joinpath("api", "default", "__init__.py"),
109-
Path("my_test_api_client").joinpath("api", "parameters", "__init__.py"),
110+
api_dir.joinpath("__init__.py"),
110111
]
111112

112-
golden_tpls_root_dir = Path(__file__).parent.joinpath("custom-templates-golden-record")
113113
for expected_difference_path in expected_difference_paths:
114114
expected_differences[expected_difference_path] = (golden_tpls_root_dir / expected_difference_path).read_text()
115115

116+
# Each API module (defined by tag) has a custom __init__.py in it now.
117+
for endpoint_mod in golden_tpls_root_dir.joinpath(api_dir).iterdir():
118+
if not endpoint_mod.is_dir():
119+
continue
120+
relative_path = api_dir.joinpath(endpoint_mod.name, "__init__.py")
121+
expected_text = endpoint_mod.joinpath("__init__.py").read_text()
122+
expected_differences[relative_path] = expected_text
123+
116124
run_e2e_test(
117125
extra_args=["--custom-template-path=end_to_end_tests/test_custom_templates/"],
118126
expected_differences=expected_differences,

0 commit comments

Comments
 (0)