Skip to content

Commit 453db88

Browse files
Add list test
1 parent d09aa84 commit 453db88

2 files changed

Lines changed: 68 additions & 7 deletions

File tree

linodecli/documentation/template_data.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,7 @@ def from_openapi(cls, operation: OpenAPIOperation) -> Self:
309309

310310
result = cls(
311311
command=operation.command,
312-
action=(
313-
operation.action
314-
if isinstance(operation.action, list)
315-
else [operation.action]
316-
),
312+
action=[operation.action] + (operation.action_aliases or []),
317313
summary=_markdown_to_rst(operation.summary),
318314
description=(
319315
_markdown_to_rst(operation.description)
@@ -322,7 +318,8 @@ def from_openapi(cls, operation: OpenAPIOperation) -> Self:
322318
),
323319
usage=cls._get_usage(operation),
324320
api_documentation_url=operation.docs_url,
325-
deprecated=operation.deprecated,
321+
deprecated=operation.deprecated is not None
322+
and operation.deprecated,
326323
)
327324

328325
if operation.samples:

tests/unit/test_documentation_template.py

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from linodecli.documentation.template_data import (
44
Action,
55
Argument,
6+
Param,
67
ResponseAttribute,
78
Root,
89
)
@@ -28,6 +29,59 @@ def test_data_group(self, mock_cli_with_parsed_template):
2829
assert group.pretty_name == "Test Resource"
2930
assert len(group.actions) == 4
3031

32+
def test_data_action_view(self, mock_cli_with_parsed_template):
33+
cli, tmpl_data = mock_cli_with_parsed_template
34+
35+
group = get_first(tmpl_data.groups, lambda v: v.name == "test-resource")
36+
action = get_first(group.actions, lambda v: v.action[0] == "view")
37+
38+
assert action.command == "test-resource"
39+
assert action.action == ["view"]
40+
41+
assert "linode-cli test-resource view [-h]" in action.usage
42+
assert "resourceId" in action.usage
43+
44+
assert "Get information about a test resource." == action.summary
45+
assert "Get information about a test resource." == action.description
46+
assert "https://linode.com" == action.api_documentation_url
47+
assert not action.deprecated
48+
49+
assert len(action.argument_sections) == 0
50+
assert len(action.filterable_attributes) == 0
51+
52+
self._validate_resource_parameters(action)
53+
self._validate_resource_response_attributes(action)
54+
55+
def test_data_action_list(self, mock_cli_with_parsed_template):
56+
cli, tmpl_data = mock_cli_with_parsed_template
57+
58+
group = get_first(tmpl_data.groups, lambda v: v.name == "test-resource")
59+
action = get_first(group.actions, lambda v: v.action[0] == "list")
60+
61+
assert action.command == "test-resource"
62+
assert action.action == ["list", "ls"]
63+
64+
assert "linode-cli test-resource list [-h]" in action.usage
65+
66+
assert "List test resources." == action.summary
67+
assert "List test resources." == action.description
68+
assert "https://linode.com" == action.api_documentation_url
69+
assert not action.deprecated
70+
71+
assert len(action.argument_sections) == 0
72+
assert len(action.parameters) == 0
73+
74+
assert action.filterable_attributes == [
75+
ResponseAttribute(
76+
name="boolean_field",
77+
type="bool",
78+
description="An arbitrary boolean.",
79+
example="true",
80+
)
81+
]
82+
83+
self._validate_resource_response_attributes(action)
84+
3185
def test_data_action_create(self, mock_cli_with_parsed_template):
3286
cli, tmpl_data = mock_cli_with_parsed_template
3387

@@ -41,7 +95,7 @@ def test_data_action_create(self, mock_cli_with_parsed_template):
4195
assert "Create a new test resource." == action.summary
4296
assert "Create a new test resource." == action.description
4397
assert "https://linode.com" == action.api_documentation_url
44-
assert action.deprecated is None
98+
assert not action.deprecated
4599

46100
assert len(action.parameters) == 0
47101
assert len(action.samples) == 0
@@ -129,6 +183,16 @@ def test_data_action_create(self, mock_cli_with_parsed_template):
129183
),
130184
]
131185

186+
@staticmethod
187+
def _validate_resource_parameters(action: Action):
188+
assert action.parameters == [
189+
Param(
190+
name="resourceId",
191+
type="int",
192+
description="The ID of the resource.",
193+
)
194+
]
195+
132196
@staticmethod
133197
def _validate_resource_response_attributes(
134198
action: Action,

0 commit comments

Comments
 (0)