pierrejeambrun commented on code in PR #45546:
URL: https://github.com/apache/airflow/pull/45546#discussion_r1910284610
##########
tests/api_connexion/endpoints/test_dag_run_endpoint.py:
##########
@@ -1522,6 +1522,63 @@ def test_should_respond_200(self, state, run_type,
dag_maker, session):
assert response.status_code == 200
assert response.json == expected_response_json
+ @pytest.mark.parametrize("state", ["failed", "success", "queued"])
+ @pytest.mark.parametrize("run_type", [state.value for state in DagRunType])
+ def test_action_logging(self, state, run_type, dag_maker, session):
+ dag_id = "TEST_DAG_ID"
+ dag_run_id = "TEST_DAG_RUN_ID"
+ with dag_maker(dag_id) as dag:
+ task = EmptyOperator(task_id="task_id", dag=dag)
+ self.app.dag_bag.bag_dag(dag, root_dag=dag)
+ dr = dag_maker.create_dagrun(run_id=dag_run_id, run_type=run_type)
+ ti = dr.get_task_instance(task_id="task_id")
+ ti.task = task
+ ti.state = State.RUNNING
+ session.merge(ti)
+ session.commit()
+
+ request_json = {"state": state}
+
+ self.client.patch(
+ f"api/v1/dags/{dag_id}/dagRuns/{dag_run_id}",
+ json=request_json,
+ environ_overrides={"REMOTE_USER": "test"},
+ )
+
+ from airflow.models import Log
Review Comment:
move imports at the top of the file if possible, or top of the function if
cyclic imports are witnessed.
`json` should go at the top
##########
tests/api_connexion/endpoints/test_dag_run_endpoint.py:
##########
@@ -1522,6 +1522,63 @@ def test_should_respond_200(self, state, run_type,
dag_maker, session):
assert response.status_code == 200
assert response.json == expected_response_json
+ @pytest.mark.parametrize("state", ["failed", "success", "queued"])
+ @pytest.mark.parametrize("run_type", [state.value for state in DagRunType])
+ def test_action_logging(self, state, run_type, dag_maker, session):
+ dag_id = "TEST_DAG_ID"
+ dag_run_id = "TEST_DAG_RUN_ID"
+ with dag_maker(dag_id) as dag:
+ task = EmptyOperator(task_id="task_id", dag=dag)
+ self.app.dag_bag.bag_dag(dag, root_dag=dag)
+ dr = dag_maker.create_dagrun(run_id=dag_run_id, run_type=run_type)
+ ti = dr.get_task_instance(task_id="task_id")
+ ti.task = task
+ ti.state = State.RUNNING
+ session.merge(ti)
+ session.commit()
+
+ request_json = {"state": state}
+
+ self.client.patch(
+ f"api/v1/dags/{dag_id}/dagRuns/{dag_run_id}",
+ json=request_json,
+ environ_overrides={"REMOTE_USER": "test"},
+ )
+
+ from airflow.models import Log
+
+ log = (
+ session.query(Log)
+ .filter(
+ Log.dag_id == dag_id,
+ Log.run_id == dag_run_id,
+ Log.event == "api.update_dag_run_state",
+ )
+ .order_by(Log.id.desc())
+ .first()
+ )
+ import json
Review Comment:
to move
--
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]