|
25 | 25 | import httpx |
26 | 26 | import pytest |
27 | 27 |
|
28 | | -from airflowctl.api.client import ClientKind |
| 28 | +from airflowctl.api.client import Client, ClientKind |
29 | 29 | from airflowctl.api.datamodels.generated import ClearTaskInstancesBody, DAGResponse, DagSchedulingState |
30 | 30 | from airflowctl.api.operations import DagRunOperations, ServerResponseError, TasksOperations |
31 | 31 | from airflowctl.ctl import cli_parser |
@@ -228,6 +228,33 @@ def test_pause_fail(self, api_client_maker, monkeypatch): |
228 | 228 | api_client=api_client, |
229 | 229 | ) |
230 | 230 |
|
| 231 | + def test_pause_fail_prints_server_error_containing_markup(self, api_client_maker, capsys): |
| 232 | + api_client = api_client_maker( |
| 233 | + path=f"/api/v2/dags/{self.dag_id}", |
| 234 | + response_json={"detail": "bad [/x] value"}, |
| 235 | + expected_http_status_code=404, |
| 236 | + kind=ClientKind.CLI, |
| 237 | + ) |
| 238 | + with pytest.raises(SystemExit): |
| 239 | + dag_command.pause( |
| 240 | + self.parser.parse_args(["dags", "pause", self.dag_id]), |
| 241 | + api_client=api_client, |
| 242 | + ) |
| 243 | + |
| 244 | + assert "[/x]" in capsys.readouterr().err |
| 245 | + |
| 246 | + def test_pause_fail_prints_dag_id_containing_markup(self, capsys): |
| 247 | + api_client = Mock(spec=Client) |
| 248 | + api_client.dags.update.side_effect = _make_server_error(404) |
| 249 | + |
| 250 | + with pytest.raises(SystemExit): |
| 251 | + dag_command.pause( |
| 252 | + self.parser.parse_args(["dags", "pause", "my_dag[/y]"]), |
| 253 | + api_client=api_client, |
| 254 | + ) |
| 255 | + |
| 256 | + assert "my_dag[/y]" in capsys.readouterr().err |
| 257 | + |
231 | 258 | def test_unpause_dag(self, api_client_maker, monkeypatch): |
232 | 259 | api_client = api_client_maker( |
233 | 260 | path=f"/api/v2/dags/{self.dag_id}", |
@@ -364,6 +391,33 @@ def test_next_execution_no_schedule(self, api_client_maker): |
364 | 391 | ) |
365 | 392 | assert result is None |
366 | 393 |
|
| 394 | + def test_next_execution_fail_prints_dag_id_containing_markup(self, capsys): |
| 395 | + api_client = Mock(spec=Client) |
| 396 | + api_client.dags.get.side_effect = _make_server_error(404) |
| 397 | + |
| 398 | + with pytest.raises(SystemExit): |
| 399 | + dag_command.next_execution( |
| 400 | + self.parser.parse_args(["dags", "next-execution", "my_dag[/y]"]), |
| 401 | + api_client=api_client, |
| 402 | + ) |
| 403 | + |
| 404 | + assert "my_dag[/y]" in capsys.readouterr().out |
| 405 | + |
| 406 | + def test_next_execution_fail_prints_server_error_containing_markup(self, api_client_maker, capsys): |
| 407 | + api_client = api_client_maker( |
| 408 | + path=f"/api/v2/dags/{self.dag_id}", |
| 409 | + response_json={"detail": "bad [/x] value"}, |
| 410 | + expected_http_status_code=404, |
| 411 | + kind=ClientKind.CLI, |
| 412 | + ) |
| 413 | + with pytest.raises(SystemExit): |
| 414 | + dag_command.next_execution( |
| 415 | + self.parser.parse_args(["dags", "next-execution", self.dag_id]), |
| 416 | + api_client=api_client, |
| 417 | + ) |
| 418 | + |
| 419 | + assert "[/x]" in capsys.readouterr().out |
| 420 | + |
367 | 421 | def test_next_execution_fail(self, api_client_maker): |
368 | 422 | api_client = api_client_maker( |
369 | 423 | path=f"/api/v2/dags/{self.dag_id}", |
@@ -730,6 +784,19 @@ def test_clear_prompts_before_clearing(self, monkeypatch): |
730 | 784 | assert result == {"dag_run_count": 1, "cleared_task_instances": 0, "cancelled": True} |
731 | 785 | api_client.tasks.clear.assert_not_called() |
732 | 786 |
|
| 787 | + @pytest.mark.parametrize("run_id", ["run_[/x]", "run[abc]"]) |
| 788 | + def test_clear_prompt_lists_run_id_containing_markup(self, run_id, monkeypatch, capsys): |
| 789 | + api_client = self._api_client_mock() |
| 790 | + api_client.dag_runs.get.return_value = self._dag_run(run_id) |
| 791 | + monkeypatch.setattr("builtins.input", lambda _: "n") |
| 792 | + |
| 793 | + dag_command.clear( |
| 794 | + self.parser.parse_args(["dags", "clear", self.dag_id, "--run-id", run_id]), |
| 795 | + api_client=api_client, |
| 796 | + ) |
| 797 | + |
| 798 | + assert f"- {run_id} (" in capsys.readouterr().out |
| 799 | + |
733 | 800 | @pytest.mark.parametrize( |
734 | 801 | "command", |
735 | 802 | [ |
|
0 commit comments