uranusjr commented on code in PR #51920:
URL: https://github.com/apache/airflow/pull/51920#discussion_r2185475808
##########
airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_dag_run.py:
##########
@@ -1606,3 +1606,49 @@ def test_should_respond_200_with_null_logical_date(self,
test_client):
"conf": {},
"note": None,
}
+
+
+class TestWaitDagRun:
+ # The way we init async engine does not work well with FastAPI app init.
+ # Creating the engine implicitly creates an event loop, which Airflow does
+ # once for the entire process; creating the FastAPI app also does, but our
+ # test setup does it once for each test. I don't know how to properly fix
+ # this without rewriting how Airflow does db; re-configuring the db for
each
+ # test at least makes the tests run correctly.
+ @pytest.fixture(autouse=True)
+ def reconfigure_async_db_engine(self):
+ from airflow.settings import _configure_async_session
+
+ _configure_async_session()
+
+ def test_should_respond_401(self, unauthenticated_test_client):
+ response =
unauthenticated_test_client.get(f"/dags/{DAG1_ID}/dagRuns/{DAG1_RUN1_ID}/wait?interval=1")
+ assert response.status_code == 401
+
+ def test_should_respond_403(self, unauthorized_test_client):
+ response =
unauthorized_test_client.get(f"/dags/{DAG1_ID}/dagRuns/{DAG1_RUN1_ID}/wait?interval=1")
+ assert response.status_code == 403
+
+ def test_should_respond_404(self, test_client):
+ response =
test_client.get(f"/dags/{DAG1_ID}/dagRuns/does-not-exist/wait?interval=1")
+ assert response.status_code == 404
+
+ def test_should_respond_422_without_interval_param(self, test_client):
+ response =
test_client.get(f"/dags/{DAG1_ID}/dagRuns/{DAG1_RUN1_ID}/wait")
+ assert response.status_code == 422
+
+ @pytest.mark.parametrize(
+ "run_id, state",
+ [(DAG1_RUN1_ID, DAG1_RUN1_STATE), (DAG1_RUN2_ID, DAG1_RUN2_STATE)],
+ )
+ def test_should_respond_200_immediately_for_finished_run(self,
test_client, run_id, state):
+ response =
test_client.get(f"/dags/{DAG1_ID}/dagRuns/{run_id}/wait?interval=100")
Review Comment:
I didn’t know you can do that! Definitely will be easier to read.
--
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]