Skip to content
This repository was archived by the owner on Jun 2, 2026. It is now read-only.

Commit e43347c

Browse files
committed
x
1 parent c9bd075 commit e43347c

4 files changed

Lines changed: 10 additions & 47 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ celerybeat.pid
103103

104104
# Environments
105105
.env
106-
.venv
106+
.venv*
107107
env/
108108
/venv/
109109
ENV/

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ lint-check:
66
uv run ruff format --diff
77
uv run ruff check
88

9+
test39:
10+
VIRTUAL_ENV=.venv39 uv run --active --python 3.9 --extra cli pytest --cov
11+
12+
913
test:
1014
if [ -n "$(GITHUB_RUN_ID)" ]; then \
1115
uv run pytest --cov --cov-report=xml --junitxml=junit.xml -o junit_family=legacy; \

defectdojo_api_generated/cli/commands/apis.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def _get_click_type(
179179

180180
if origin is Union or origin is getattr(types, 'UnionType', None):
181181
if _is_file_upload_union(current):
182-
return click.Path(exists=True, dir_okay=False, path_type=Path), multiple, None
182+
return Path, multiple, None
183183

184184
union_args = [arg for arg in get_args(current) if arg is not type(None)]
185185
if not union_args:
@@ -197,11 +197,8 @@ def _get_click_type(
197197

198198

199199
def _get_class_annotation(click_type: Any) -> type:
200-
# Classyclick inspects annotations at import time and expects a runtime type.
201200
if click_type is Any:
202201
return str
203-
if isinstance(click_type, click.Path):
204-
return Path
205202
return click_type
206203

207204

@@ -247,9 +244,7 @@ def _build_model_field_command(
247244
required_fields = [item for item in field_definitions if item[1].is_required()]
248245
optional_fields = [item for item in field_definitions if not item[1].is_required()]
249246

250-
def _convert_value(
251-
name: str, value: Any, converter: Optional[type[BaseModel]], *, multiple: bool
252-
):
247+
def _convert_value(name: str, value: Any, converter: Optional[type[BaseModel]], *, multiple: bool):
253248
if name == 'file':
254249
if multiple:
255250
return tuple(_coerce_file_upload_value(item) for item in value)
@@ -481,9 +476,7 @@ def make_api_command(api_class: type, command_name: str, target_method: str, *,
481476
required_parameters = [item for item in command_parameters if item[1].default is inspect.Signature.empty]
482477
optional_parameters = [item for item in command_parameters if item[1].default is not inspect.Signature.empty]
483478

484-
def _convert_value(
485-
name: str, value: Any, converter: Optional[type[BaseModel]], *, multiple: bool
486-
):
479+
def _convert_value(name: str, value: Any, converter: Optional[type[BaseModel]], *, multiple: bool):
487480
if name == 'file':
488481
if multiple:
489482
return tuple(_coerce_file_upload_value(item) for item in value)

tests/unit/test_cli.py

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import unittest
44
from importlib.metadata import version
55
from pathlib import Path
6-
from typing import Any, Optional, Tuple, Union
6+
from typing import Optional
77
from unittest import mock
88

99
from click.testing import CliRunner
10-
from pydantic import BaseModel, Field
10+
from pydantic import Field
1111
from typing_extensions import Annotated
1212

1313
from defectdojo_api_generated.api.findings_api import FindingsApi
@@ -287,40 +287,6 @@ def test_required_request_body_parameters_become_field_flags(self):
287287
payload = json.loads(run_result.output)
288288
self.assertEqual(payload['name'], 'Example')
289289

290-
def test_request_model_fields_typed_as_any_register_without_import_errors(self):
291-
class AnyRequest(BaseModel):
292-
payload: Any = None
293-
294-
class AnyRequestApi:
295-
def __init__(self, api_client):
296-
self.api_client = api_client
297-
298-
def create(self, any_request: AnyRequest):
299-
return any_request.model_dump()
300-
301-
command = make_api_group('any_request_api', AnyRequestApi).click
302-
option = next(param for param in command.params if getattr(param, 'name', None) == 'payload')
303-
304-
self.assertEqual(option.type.name, 'text')
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-
324290
def test_bad_request_exception_uses_detail_message(self):
325291
runner = CliRunner()
326292

0 commit comments

Comments
 (0)