Skip to content

Commit b69bbeb

Browse files
author
Constantinos Symeonides
committed
test: Add end to end test (requires renaming golden record directories)
1 parent b719316 commit b69bbeb

File tree

56 files changed

+142
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+142
-7
lines changed

CONTRIBUTING.md

+1-1

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from typing import Any, Dict, List, Type, TypeVar
2+
3+
import attr
4+
5+
T = TypeVar("T", bound="ModelName")
6+
7+
8+
@attr.s(auto_attribs=True)
9+
class ModelName:
10+
""" """
11+
12+
additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)
13+
14+
def to_dict(self) -> Dict[str, Any]:
15+
16+
field_dict: Dict[str, Any] = {}
17+
field_dict.update(self.additional_properties)
18+
field_dict.update({})
19+
20+
return field_dict
21+
22+
@classmethod
23+
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
24+
d = src_dict.copy()
25+
model_name = cls()
26+
27+
model_name.additional_properties = d
28+
return model_name
29+
30+
@property
31+
def additional_keys(self) -> List[str]:
32+
return list(self.additional_properties.keys())
33+
34+
def __getitem__(self, key: str) -> Any:
35+
return self.additional_properties[key]
36+
37+
def __setitem__(self, key: str, value: Any) -> None:
38+
self.additional_properties[key] = value
39+
40+
def __delitem__(self, key: str) -> None:
41+
del self.additional_properties[key]
42+
43+
def __contains__(self, key: str) -> bool:
44+
return key in self.additional_properties
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from typing import Any, Dict, List, Type, TypeVar, Union
2+
3+
import attr
4+
5+
from ..models.model_name import ModelName
6+
from ..types import UNSET, Unset
7+
8+
T = TypeVar("T", bound="ModelWithPropertyRef")
9+
10+
11+
@attr.s(auto_attribs=True)
12+
class ModelWithPropertyRef:
13+
""" """
14+
15+
inner: Union[Unset, ModelName] = UNSET
16+
additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)
17+
18+
def to_dict(self) -> Dict[str, Any]:
19+
inner: Union[Unset, Dict[str, Any]] = UNSET
20+
if not isinstance(self.inner, Unset):
21+
inner = self.inner.to_dict()
22+
23+
field_dict: Dict[str, Any] = {}
24+
field_dict.update(self.additional_properties)
25+
field_dict.update({})
26+
if inner is not UNSET:
27+
field_dict["inner"] = inner
28+
29+
return field_dict
30+
31+
@classmethod
32+
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
33+
d = src_dict.copy()
34+
inner: Union[Unset, ModelName] = UNSET
35+
_inner = d.pop("inner", UNSET)
36+
if not isinstance(_inner, Unset):
37+
inner = ModelName.from_dict(_inner)
38+
39+
model_with_property_ref = cls(
40+
inner=inner,
41+
)
42+
43+
model_with_property_ref.additional_properties = d
44+
return model_with_property_ref
45+
46+
@property
47+
def additional_keys(self) -> List[str]:
48+
return list(self.additional_properties.keys())
49+
50+
def __getitem__(self, key: str) -> Any:
51+
return self.additional_properties[key]
52+
53+
def __setitem__(self, key: str, value: Any) -> None:
54+
self.additional_properties[key] = value
55+
56+
def __delitem__(self, key: str) -> None:
57+
del self.additional_properties[key]
58+
59+
def __contains__(self, key: str) -> bool:
60+
return key in self.additional_properties

end_to_end_tests/regen_golden_record.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
""" Regenerate golden-record """
1+
""" Regenerate golden_record """
22
import shutil
3-
import sys
43
from pathlib import Path
54

65
from typer.testing import CliRunner
@@ -11,7 +10,7 @@
1110
runner = CliRunner()
1211
openapi_path = Path(__file__).parent / "openapi.json"
1312

14-
gr_path = Path(__file__).parent / "golden-record"
13+
gr_path = Path(__file__).parent / "golden_record"
1514
output_path = Path.cwd() / "my-test-api-client"
1615
config_path = Path(__file__).parent / "config.yml"
1716

end_to_end_tests/test_end_to_end.py

+33-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from filecmp import cmpfiles, dircmp
33
from pathlib import Path
44
from typing import Dict, Optional
5+
from unittest.mock import ANY
56

67
import pytest
78
from typer.testing import CliRunner
@@ -49,7 +50,7 @@ def run_e2e_test(extra_args=None, expected_differences=None):
4950
runner = CliRunner()
5051
openapi_path = Path(__file__).parent / "openapi.json"
5152
config_path = Path(__file__).parent / "config.yml"
52-
gr_path = Path(__file__).parent / "golden-record"
53+
gr_path = Path(__file__).parent / "golden_record"
5354
output_path = Path.cwd() / "my-test-api-client"
5455
shutil.rmtree(output_path, ignore_errors=True)
5556

@@ -79,3 +80,34 @@ def test_custom_templates():
7980
extra_args=["--custom-template-path=end_to_end_tests/test_custom_templates"],
8081
expected_differences={"README.md": "my-test-api-client"},
8182
)
83+
84+
85+
def test_file_upload(mocker):
86+
# Arrange
87+
from io import StringIO
88+
89+
from end_to_end_tests.golden_record.my_test_api_client.models import BodyUploadFileTestsUploadPost
90+
from end_to_end_tests.golden_record.my_test_api_client.types import File
91+
92+
payload = StringIO("my payload")
93+
file = File(payload=payload, file_name="my_file_name", mime_type="foo/bar")
94+
multipart_data = BodyUploadFileTestsUploadPost(some_file=file, some_string="my_string")
95+
96+
base_url = "http://my.base.url"
97+
client = mocker.MagicMock(base_url=base_url)
98+
get = mocker.patch("httpx.post")
99+
100+
# Act
101+
from .golden_record.my_test_api_client.api.tests import upload_file_tests_upload_post
102+
103+
upload_file_tests_upload_post.sync(client=client, multipart_data=multipart_data)
104+
105+
# Assert
106+
get.assert_called_once_with(
107+
url=f"{base_url}/tests/upload",
108+
headers=ANY,
109+
cookies=ANY,
110+
timeout=ANY,
111+
files={"some_file": ("my_file_name", payload, "foo/bar")},
112+
data={"some_string": "my_string"},
113+
)

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ exclude = '''
7878
| openapi_python_client/templates
7979
| tests/test_templates
8080
| end_to_end_tests/test_custom_templates
81-
| end_to_end_tests/golden-record-custom
81+
| end_to_end_tests/golden_record_custom
8282
)/
8383
)
8484
'''

0 commit comments

Comments
 (0)