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


##########
tests/api_fastapi/core_api/routes/public/test_dag_report.py:
##########
@@ -0,0 +1,83 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+from unittest.mock import patch
+
+import pytest
+import re2 as re
+
+from tests_common.test_utils.config import conf_vars
+from tests_common.test_utils.db import clear_db_dags
+
+pytestmark = pytest.mark.db_test
+
+
+class TestDagReportEndpoint:
+    @pytest.fixture(autouse=True)
+    def setup(self) -> None:
+        self.clear_db()
+
+    def teardown_method(self) -> None:
+        self.clear_db()
+
+    def clear_db(self):
+        clear_db_dags()
+
+    @pytest.mark.parametrize(
+        "subdir,include_example,expected_total_entries",
+        [
+            pytest.param("/root/airflow/dags", True, 58, 
id="dag_path_with_example"),
+            pytest.param("/root/airflow/dags", False, 0, 
id="dag_path_without_example"),
+        ],
+    )
+    def test_should_response_200(self, test_client, subdir, include_example, 
expected_total_entries):
+        with conf_vars({("core", "load_examples"): str(include_example)}):
+            params = {"subdir": subdir} if subdir else {}

Review Comment:
   `subdir` is always defined.
   ```suggestion
               params = {"subdir": subdir}
   ```



##########
tests/api_fastapi/core_api/routes/public/test_dag_report.py:
##########
@@ -0,0 +1,83 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+from unittest.mock import patch
+
+import pytest
+import re2 as re
+
+from tests_common.test_utils.config import conf_vars
+from tests_common.test_utils.db import clear_db_dags
+
+pytestmark = pytest.mark.db_test
+
+
+class TestDagReportEndpoint:
+    @pytest.fixture(autouse=True)
+    def setup(self) -> None:
+        self.clear_db()
+
+    def teardown_method(self) -> None:
+        self.clear_db()
+
+    def clear_db(self):
+        clear_db_dags()
+
+    @pytest.mark.parametrize(
+        "subdir,include_example,expected_total_entries",
+        [
+            pytest.param("/root/airflow/dags", True, 58, 
id="dag_path_with_example"),
+            pytest.param("/root/airflow/dags", False, 0, 
id="dag_path_without_example"),
+        ],
+    )
+    def test_should_response_200(self, test_client, subdir, include_example, 
expected_total_entries):
+        with conf_vars({("core", "load_examples"): str(include_example)}):
+            params = {"subdir": subdir} if subdir else {}
+            response = test_client.get("/public/dagReport", params=params)
+            assert response.status_code == 200
+            response_json = response.json()
+            expected_keys = {"dag_num", "dags", "file", "task_num", 
"warning_num"}
+            assert response_json["total_entries"] == expected_total_entries
+            for dag_report in response_json["dag_reports"]:
+                assert all(key in dag_report for key in expected_keys)
+                # assert duration is in ISO8601 format ( PTnS or PTn.nS )
+                assert re.match(r"^PT\d+(\.\d+)?S$", dag_report["duration"])

Review Comment:
   These chekcs can be omitted. This is enforced by fastapi + pydantic native 
validation.



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