pierrejeambrun commented on code in PR #44170:
URL: https://github.com/apache/airflow/pull/44170#discussion_r1856749628


##########
tests/api_fastapi/core_api/routes/public/test_dag_run.py:
##########
@@ -432,6 +469,333 @@ def test_invalid_state(self, test_client):
         )
 
 
+class TestListDagRunsBatch:
+    @staticmethod
+    def parse_datetime(datetime_str):
+        return datetime_str.isoformat().replace("+00:00", "Z") if datetime_str 
else None
+
+    @staticmethod
+    def get_dag_run_dict(run: DagRun):
+        return {
+            "dag_run_id": run.run_id,
+            "dag_id": run.dag_id,
+            "logical_date": TestGetDagRuns.parse_datetime(run.logical_date),
+            "queued_at": TestGetDagRuns.parse_datetime(run.queued_at),
+            "start_date": TestGetDagRuns.parse_datetime(run.start_date),
+            "end_date": TestGetDagRuns.parse_datetime(run.end_date),
+            "data_interval_start": 
TestGetDagRuns.parse_datetime(run.data_interval_start),
+            "data_interval_end": 
TestGetDagRuns.parse_datetime(run.data_interval_end),
+            "last_scheduling_decision": 
TestGetDagRuns.parse_datetime(run.last_scheduling_decision),
+            "run_type": run.run_type,
+            "state": run.state,
+            "external_trigger": run.external_trigger,
+            "triggered_by": run.triggered_by.value,
+            "conf": run.conf,
+            "note": run.note,
+        }
+
+    def test_list_dag_runs_return_200(self, test_client, session):
+        response = test_client.post("/public/dags/~/dagRuns/list", json={})
+        assert response.status_code == 200
+        body = response.json()
+        assert body["total_entries"] == 4
+        for each in body["dag_runs"]:
+            run = session.query(DagRun).where(DagRun.run_id == 
each["dag_run_id"]).one()
+            expected = self.get_dag_run_dict(run)
+            assert each == expected
+
+    def test_list_dag_runs_with_invalid_dag_id(self, test_client):
+        response = test_client.post("/public/dags/invalid/dagRuns/list", 
json={})
+        assert response.status_code == 422
+        body = response.json()
+        assert body["detail"] == [
+            {
+                "type": "literal_error",
+                "loc": ["path", "dag_id"],
+                "msg": "Input should be '~'",
+                "input": "invalid",
+                "ctx": {"expected": "'~'"},
+            }
+        ]
+
+    @pytest.mark.parametrize(
+        "dag_ids, status_code, expected_dag_id_list",
+        [
+            ([], 200, DAG_RUNS_LIST),
+            ([DAG1_ID], 200, [DAG1_RUN1_ID, DAG1_RUN2_ID]),
+            [["invalid"], 200, []],
+        ],
+    )
+    def test_list_dag_runs_with_dag_ids_filter(self, test_client, dag_ids, 
status_code, expected_dag_id_list):
+        response = test_client.post("/public/dags/~/dagRuns/list", 
json={"dag_ids": dag_ids})
+        assert response.status_code == status_code
+        assert set([each["dag_run_id"] for each in 
response.json()["dag_runs"]]) == set(expected_dag_id_list)
+
+    def test_invalid_order_by_raises_400(self, test_client):
+        response = test_client.post("/public/dags/~/dagRuns/list", 
json={"order_by": "invalid"})
+        assert response.status_code == 400
+        body = response.json()
+        assert (
+            body["detail"]
+            == "Ordering with 'invalid' is disallowed or the attribute does 
not exist on the model"
+        )
+
+    @pytest.mark.parametrize(
+        "order_by, expected_dag_id_order",
+        [
+            ("id", DAG_RUNS_LIST),
+            ("state", [DAG1_RUN2_ID, DAG1_RUN1_ID, DAG2_RUN1_ID, 
DAG2_RUN2_ID]),
+            ("dag_id", DAG_RUNS_LIST),
+            ("logical_date", DAG_RUNS_LIST),
+            ("dag_run_id", DAG_RUNS_LIST),
+            ("start_date", DAG_RUNS_LIST),
+            ("end_date", DAG_RUNS_LIST),
+            ("updated_at", DAG_RUNS_LIST),
+            ("external_trigger", DAG_RUNS_LIST),
+            ("conf", DAG_RUNS_LIST),

Review Comment:
   Be sure to test with `-` as well. Is that just a coincidence that all of the 
different orders return the same order ?
   
   I'd like to see some different orders returned, maybe use `-dag_run_id`, 
`-logical_date` etc...



-- 
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]

Reply via email to