@@ -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