Skip to content

Commit 2715dbf

Browse files
committed
task / regen / regen custom template golden record
1 parent b9a67e1 commit 2715dbf

File tree

5 files changed

+70
-4
lines changed

5 files changed

+70
-4
lines changed

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
""" Contains methods for accessing the API """
22

3-
43
from typing import Type
54

65
from my_test_api_client.api.default import DefaultEndpoints
6+
from my_test_api_client.api.parameters import ParametersEndpoints
77
from my_test_api_client.api.tests import TestsEndpoints
88

99

@@ -15,3 +15,7 @@ def tests(cls) -> Type[TestsEndpoints]:
1515
@classmethod
1616
def default(cls) -> Type[DefaultEndpoints]:
1717
return DefaultEndpoints
18+
19+
@classmethod
20+
def parameters(cls) -> Type[ParametersEndpoints]:
21+
return ParametersEndpoints

Diff for: end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/default/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
""" Contains methods for accessing the API Endpoints """
22

3-
43
import types
54

65
from my_test_api_client.api.default import get_common_parameters, post_common_parameters
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.parameters import get_same_name_multiple_locations_param
6+
7+
8+
class ParametersEndpoints:
9+
@classmethod
10+
def get_same_name_multiple_locations_param(cls) -> types.ModuleType:
11+
return get_same_name_multiple_locations_param

Diff for: end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/tests/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
""" Contains methods for accessing the API Endpoints """
22

3-
43
import types
54

65
from my_test_api_client.api.tests import (

Diff for: end_to_end_tests/regen_golden_record.py

+54-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
""" Regenerate golden-record """
2+
import filecmp
3+
import os
24
import shutil
5+
import tempfile
36
from pathlib import Path
47

58
from typer.testing import CliRunner
69

710
from openapi_python_client.cli import app
811

9-
if __name__ == "__main__":
12+
13+
def regen_golden_record():
1014
runner = CliRunner()
1115
openapi_path = Path(__file__).parent / "openapi.json"
1216

@@ -24,3 +28,52 @@
2428
if result.exception:
2529
raise result.exception
2630
output_path.rename(gr_path)
31+
32+
33+
def regen_custom_template_golden_record():
34+
runner = CliRunner()
35+
openapi_path = Path(__file__).parent / "openapi.json"
36+
tpl_dir = Path(__file__).parent / "test_custom_templates"
37+
38+
gr_path = Path(__file__).parent / "golden-record"
39+
tpl_gr_path = Path(__file__).parent / "custom-templates-golden-record"
40+
41+
output_path = Path(tempfile.mkdtemp())
42+
config_path = Path(__file__).parent / "config.yml"
43+
44+
shutil.rmtree(tpl_gr_path, ignore_errors=True)
45+
46+
os.chdir(str(output_path.absolute()))
47+
result = runner.invoke(
48+
app, ["generate", f"--config={config_path}", f"--path={openapi_path}", f"--custom-template-path={tpl_dir}"]
49+
)
50+
51+
if result.stdout:
52+
generated_output_path = output_path / "my-test-api-client"
53+
for f in generated_output_path.glob("**/*"): # nb: works for Windows and Unix
54+
relative_to_generated = f.relative_to(generated_output_path)
55+
gr_file = gr_path / relative_to_generated
56+
if not gr_file.exists():
57+
print(f"{gr_file} does not exist, ignoring")
58+
continue
59+
60+
if not gr_file.is_file():
61+
continue
62+
63+
if not filecmp.cmp(gr_file, f, shallow=False):
64+
target_file = tpl_gr_path / relative_to_generated
65+
target_dir = target_file.parent
66+
67+
target_dir.mkdir(parents=True, exist_ok=True)
68+
shutil.copy(f"{f}", f"{target_file}")
69+
70+
shutil.rmtree(output_path, ignore_errors=True)
71+
72+
if result.exception:
73+
shutil.rmtree(output_path, ignore_errors=True)
74+
raise result.exception
75+
76+
77+
if __name__ == "__main__":
78+
regen_golden_record()
79+
regen_custom_template_golden_record()

0 commit comments

Comments
 (0)