rawwar commented on code in PR #42973:
URL: https://github.com/apache/airflow/pull/42973#discussion_r1797997821


##########
tests/api_fastapi/views/public/test_dag_run.py:
##########
@@ -136,3 +136,37 @@ def test_get_dag_run_not_found(test_client):
     assert response.status_code == 404
     body = response.json()
     assert body["detail"] == "The DagRun with dag_id: `test_dag1` and run_id: 
`invalid` was not found"
+
+
+class TestModifyDagRun:
+    @pytest.mark.parametrize(
+        "dag_id, run_id, state, response_state",
+        [
+            (DAG1_ID, DAG1_RUN1_ID, DagRunState.FAILED, DagRunState.FAILED),
+            (DAG1_ID, DAG1_RUN2_ID, DagRunState.SUCCESS, DagRunState.SUCCESS),
+            (DAG2_ID, DAG2_RUN1_ID, DagRunState.QUEUED, DagRunState.QUEUED),
+        ],
+    )
+    def test_modify_dag_run(self, test_client, dag_id, run_id, state, 
response_state):
+        response = 
test_client.patch(f"/public/dags/{dag_id}/dagRuns/{run_id}", json={"state": 
state})
+        assert response.status_code == 200
+        body = response.json()
+        assert body["dag_id"] == dag_id
+        assert body["run_id"] == run_id
+        assert body["state"] == response_state
+
+    def test_modify_dag_run_not_found(self, test_client):
+        response = test_client.patch(
+            f"/public/dags/{DAG1_ID}/dagRuns/invalid", json={"state": 
DagRunState.SUCCESS}
+        )
+        assert response.status_code == 404
+        body = response.json()
+        assert body["detail"] == "The DagRun with dag_id: `test_dag1` and 
run_id: `invalid` was not found"
+
+    def test_modify_dag_run_bad_request(self, test_client):
+        response = test_client.patch(
+            f"/public/dags/{DAG1_ID}/dagRuns/{DAG1_RUN1_ID}", json={"state": 
"running"}
+        )
+        assert response.status_code == 422

Review Comment:
   @pierrejeambrun , FastAPI seems to return 422 when there is an invalid data 
in request body. In legacy, we return BadRequest(400). 
   
   I tried to add a test by sending similar invalid data to dag endpoint and 
received a 422.
   
   Do we add 422 to response status codes or modify the code so that it returns 
a 400?



-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to