|
3 | 3 | import unittest |
4 | 4 | from importlib.metadata import version |
5 | 5 | from pathlib import Path |
6 | | -from typing import Any, Optional |
| 6 | +from typing import Any, Optional, Tuple, Union |
7 | 7 | from unittest import mock |
8 | 8 |
|
9 | 9 | from click.testing import CliRunner |
@@ -303,6 +303,24 @@ def create(self, any_request: AnyRequest): |
303 | 303 |
|
304 | 304 | self.assertEqual(option.type.name, 'text') |
305 | 305 |
|
| 306 | + def test_request_model_file_fields_annotate_as_path(self): |
| 307 | + class FileRequest(BaseModel): |
| 308 | + file: Optional[Union[bytes, str, Tuple[str, bytes]]] = None |
| 309 | + |
| 310 | + class FileRequestApi: |
| 311 | + def __init__(self, api_client): |
| 312 | + self.api_client = api_client |
| 313 | + |
| 314 | + def create(self, file_request: FileRequest): |
| 315 | + return file_request.model_dump() |
| 316 | + |
| 317 | + command_class = make_api_group('file_request_api', FileRequestApi) |
| 318 | + command = command_class.click |
| 319 | + option = next(param for param in command.params if getattr(param, 'name', None) == 'file') |
| 320 | + |
| 321 | + self.assertIs(command_class.__annotations__['file'], Path) |
| 322 | + self.assertEqual(option.type.name, 'file') |
| 323 | + |
306 | 324 | def test_bad_request_exception_uses_detail_message(self): |
307 | 325 | runner = CliRunner() |
308 | 326 |
|
|
0 commit comments