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


##########
airflow-core/tests/unit/api_fastapi/core_api/routes/ui/test_dags.py:
##########
@@ -116,6 +124,86 @@ def test_should_return_200(self, test_client, 
query_params, expected_ids, expect
                     assert previous_run_after > dag_run["run_after"]
                 previous_run_after = dag_run["run_after"]
 
+    def test_should_return_200_with_hitl(
+        self,
+        test_client: TestClient,
+        create_task_instance: TaskInstance,
+        session: Session,
+    ):
+        # 3 Dags (test_dag0 created here and test_dag1, test_dag2 created in 
setup_dag_runs)
+        # 5 task instances in test_dag0
+        TI_COUNT = 5
+        tis = [
+            create_task_instance(
+                dag_id="test_dag0",
+                run_id=f"hitl_run_{ti_i}",
+                task_id=f"test_task_{ti_i}",
+                session=session,
+            )
+            for ti_i in range(TI_COUNT)
+        ]
+        session.add_all(tis)
+        session.commit()
+
+        # test_dag_0 has 3 HITL details not responded, 2 already responded
+        # test_dag_0 has 3 HITL details that have not been responded to, while 
2 have already received responses.
+        hitl_detail_models = [
+            HITLDetail(
+                ti_id=tis[i].id,
+                options=["Approve", "Reject"],
+                subject=f"This is subject {i}",
+                defaults=["Approve"],
+            )
+            for i in range(3)
+        ] + [
+            HITLDetail(
+                ti_id=tis[i].id,
+                options=["Approve", "Reject"],
+                subject=f"This is subject {i}",
+                defaults=["Approve"],
+                response_at=utcnow(),
+                chosen_options=["Approve"],
+                user_id="test",
+            )
+            for i in range(3, 5)
+        ]
+        session.add_all(hitl_detail_models)
+        session.commit()
+
+        # Without `has_pending_actions` params, it should query all Dags 
without pending actions
+        response = test_client.get("/dags")
+        assert response.status_code == 200
+        body = response.json()
+        assert body["total_entries"] == 3
+
+        # With `has_pending_actions` params set to true, it should only query 
Dags with pending actions
+        response = test_client.get("/dags", params={"has_pending_actions": 
True})
+        assert response.status_code == 200
+        body = response.json()
+        assert body["total_entries"] == 1
+        for dag_json in body["dags"]:
+            assert dag_json["pending_actions"] == [
+                {
+                    "task_instance": mock.ANY,
+                    "options": ["Approve", "Reject"],
+                    "subject": f"This is subject {i}",
+                    "defaults": ["Approve"],
+                    "multiple": False,
+                    "params": {},
+                    "params_input": {},
+                    "response_received": False,
+                }
+                for i in range(3)
+            ]
+
+        # With `has_pending_actions` params set to true, it should only query 
Dags without pending actions
+        response = test_client.get("/dags", params={"has_pending_actions": 
False})
+        assert response.status_code == 200
+        body = response.json()
+        assert body["total_entries"] == 2
+        for dag_json in body["dags"]:
+            assert dag_json["pending_actions"] == []

Review Comment:
   Nit: We could parametrize the test, so we run it with 
`has_pending_actions=None`, `has_pending_actions=True`, 
`has_pending_actions=None`, instead of having it in one block. When there are a 
lot of assertions in one test, it's harder to debug



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