henry3260 commented on code in PR #72109:
URL: https://github.com/apache/airflow/pull/72109#discussion_r3941040985
##########
airflow-core/tests/unit/cli/commands/test_dag_command.py:
##########
@@ -564,6 +564,31 @@ def test_pause(self):
dag_command.dag_unpause(args)
assert not DagModel.get_dagmodel("example_bash_operator").is_paused
+ def test_pause_unpause_from_dag_cli(self):
+ """``DAG.cli()`` passes the Dag positionally and its parser drops
``--dag-id``."""
+ parser = cli_parser.get_parser(dag_parser=True)
+ dag = DAG("example_bash_operator")
+
+ dag_command.dag_pause(parser.parse_args(["dags", "pause"]), dag)
+ assert DagModel.get_dagmodel("example_bash_operator").is_paused
+
+ dag_command.dag_unpause(parser.parse_args(["dags", "unpause"]), dag)
+ assert not DagModel.get_dagmodel("example_bash_operator").is_paused
+
+ @mock.patch("airflow.cli.commands.dag_command.ask_yesno")
+ def test_pause_from_dag_cli_ignores_treat_dag_id_as_regex(self,
mock_yesno):
+ """The Dag fixes the target, so its dag_id must not be read back as a
pattern."""
+ target = DAG("dag.cli_regex_target")
+ sync_dag_to_db(target)
+ sync_dag_to_db(DAG("dagXcli_regex_target"))
+ parser = cli_parser.get_parser(dag_parser=True)
+
+ dag_command.dag_pause(parser.parse_args(["dags", "pause",
"--treat-dag-id-as-regex"]), target)
+
+ mock_yesno.assert_not_called()
+ assert DagModel.get_dagmodel("dag.cli_regex_target").is_paused
+ assert not DagModel.get_dagmodel("dagXcli_regex_target").is_paused
Review Comment:
This test syncs two extra Dags into `DagModel` and leaves one of them
paused, but never cleans them up. `TestCliDags` only rebuilds the example Dags
once in `setup_class` and clears them in `teardown_class`, so these rows stay
visible to every test that runs after this one in the class. Other tests in
this class that add their own Dags (e.g. `test_next_execution`,
`test_cli_list_dags_with_multiple_dag_versions`) restore the shared state at
the end.
```suggestion
assert not DagModel.get_dagmodel("dagXcli_regex_target").is_paused
clear_db_dags()
self.setup_class()
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]