Skip to content

Commit 4bc871e

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

File tree

54 files changed

+38
-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.

54 files changed

+38
-7
lines changed

CONTRIBUTING.md

+1-1

README.md

+1-1

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)