|
2 | 2 | from filecmp import cmpfiles, dircmp
|
3 | 3 | from pathlib import Path
|
4 | 4 | from typing import Dict, Optional
|
| 5 | +from unittest.mock import ANY |
5 | 6 |
|
6 | 7 | import pytest
|
7 | 8 | from typer.testing import CliRunner
|
@@ -49,7 +50,7 @@ def run_e2e_test(extra_args=None, expected_differences=None):
|
49 | 50 | runner = CliRunner()
|
50 | 51 | openapi_path = Path(__file__).parent / "openapi.json"
|
51 | 52 | config_path = Path(__file__).parent / "config.yml"
|
52 |
| - gr_path = Path(__file__).parent / "golden-record" |
| 53 | + gr_path = Path(__file__).parent / "golden_record" |
53 | 54 | output_path = Path.cwd() / "my-test-api-client"
|
54 | 55 | shutil.rmtree(output_path, ignore_errors=True)
|
55 | 56 |
|
@@ -79,3 +80,34 @@ def test_custom_templates():
|
79 | 80 | extra_args=["--custom-template-path=end_to_end_tests/test_custom_templates"],
|
80 | 81 | expected_differences={"README.md": "my-test-api-client"},
|
81 | 82 | )
|
| 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 | + ) |
0 commit comments