Skip to content

Commit 5dc87ee

Browse files
Leondon9ruvnet
andcommitted
Use AirflowConsole for non-JSON pool export output
Replace `rich.print(pools_list)` with `AirflowConsole().print_as()` so non-JSON export formats (table, yaml, plain) are rendered consistently with other airflow-ctl commands. Add test verifying the delegation. Co-Authored-By: claude-flow <ruv@ruv.net>
1 parent bca7ac3 commit 5dc87ee

File tree

2 files changed

+30
-26
lines changed

2 files changed

+30
-26
lines changed

airflow-ctl/src/airflowctl/ctl/commands/pool_command.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
BulkCreateActionPoolBody,
3232
PoolBody,
3333
)
34+
from airflowctl.ctl.console_formatting import AirflowConsole
3435

3536

3637
@provide_api_client(kind=ClientKind.CLI)
@@ -78,7 +79,7 @@ def export(args, api_client: Client = NEW_API_CLIENT) -> None:
7879
rich.print(f"Exported {pools_response.total_entries} pool(s) to {args.file}")
7980
else:
8081
# For non-json formats, print the pools directly to console
81-
rich.print(pools_list)
82+
AirflowConsole().print_as(data=pools_list, output=args.output)
8283
except Exception as e:
8384
raise SystemExit(f"Failed to export pools: {e}")
8485

airflow-ctl/tests/airflow_ctl/ctl/commands/test_pool_command.py

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -149,35 +149,38 @@ def test_export_json_to_file(self, mock_client, tmp_path, capsys):
149149
expected_output = f"Exported {len(exported_data)} pool(s) to {export_file}"
150150
assert expected_output in captured.out.replace("\n", "")
151151

152-
def test_export_non_json_output(self, mock_client, tmp_path, capsys):
153-
"""Test pool export with non-json output format."""
154-
# Create a proper dictionary structure
155-
mock_pool = {
156-
"name": "test_pool",
157-
"slots": 1,
158-
"description": "Test pool",
159-
"include_deferred": True,
160-
"occupied_slots": 0,
161-
"running_slots": 0,
162-
"queued_slots": 0,
163-
"scheduled_slots": 0,
164-
"open_slots": 1,
165-
"deferred_slots": 0,
166-
}
167-
# Create a mock response with a proper pools attribute
152+
def test_export_non_json_uses_airflow_console(self, mock_client, tmp_path):
153+
"""Test that non-JSON export delegates to AirflowConsole.print_as()."""
154+
pool = type(
155+
"Pool",
156+
(),
157+
{
158+
"name": "test_pool",
159+
"slots": 5,
160+
"description": "Test pool",
161+
"include_deferred": True,
162+
"occupied_slots": 0,
163+
"running_slots": 0,
164+
"queued_slots": 0,
165+
"scheduled_slots": 0,
166+
"open_slots": 5,
167+
"deferred_slots": 0,
168+
},
169+
)()
168170
mock_pools = mock.MagicMock()
169-
mock_pools.pools = [mock.MagicMock(**mock_pool)]
171+
mock_pools.pools = [pool]
170172
mock_pools.total_entries = 1
171173
mock_client.pools.list.return_value = mock_pools
172174

173-
pool_command.export(mock.MagicMock(file=tmp_path / "unused.json", output="table"))
174-
175-
# Verify console output contains the raw dict
176-
captured = capsys.readouterr()
177-
assert "test_pool" in captured.out
178-
assert "slots" in captured.out
179-
assert "description" in captured.out
180-
assert "include_deferred" in captured.out
175+
with mock.patch("airflowctl.ctl.commands.pool_command.AirflowConsole") as mock_console_cls:
176+
mock_console = mock_console_cls.return_value
177+
pool_command.export(mock.MagicMock(file=tmp_path / "unused.json", output="table"))
178+
mock_console.print_as.assert_called_once()
179+
call_kwargs = mock_console.print_as.call_args.kwargs
180+
assert call_kwargs["output"] == "table"
181+
assert len(call_kwargs["data"]) == 1
182+
assert call_kwargs["data"][0]["name"] == "test_pool"
183+
assert call_kwargs["data"][0]["slots"] == 5
181184

182185
def test_export_failure(self, mock_client, tmp_path):
183186
"""Test pool export with API failure."""

0 commit comments

Comments
 (0)