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


##########
tests/api_fastapi/core_api/routes/public/test_dag_report.py:
##########
@@ -0,0 +1,124 @@
+# 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
+
+from airflow.utils.file import list_py_file_paths
+
+from tests_common.test_utils.config import conf_vars
+from tests_common.test_utils.db import clear_db_dags
+
+pytestmark = pytest.mark.db_test
+
+TEST_DAG_FOLDER = "/opt/airflow/tests/dags"
+TEST_DAG_FOLDER_WITH_SUBDIR = "/opt/airflow/tests/dags/subdir2"
+TEST_DAG_FOLDER_INVALID = "/invalid/path"
+TEST_DAG_FOLDER_INVALID_2 = "/root/airflow/tests/dags/"
+
+
+def get_corresponding_dag_file_count(dir: str, include_examples: bool = True) 
-> int:
+    return len(list_py_file_paths(directory=dir, 
include_examples=include_examples))
+
+
+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(
+                TEST_DAG_FOLDER,
+                True,
+                get_corresponding_dag_file_count(TEST_DAG_FOLDER),
+                id="dag_path_with_example",
+            ),
+            pytest.param(
+                TEST_DAG_FOLDER,
+                False,
+                get_corresponding_dag_file_count(TEST_DAG_FOLDER, False),
+                id="dag_path_without_example",
+            ),
+            pytest.param(
+                TEST_DAG_FOLDER_WITH_SUBDIR,
+                True,
+                get_corresponding_dag_file_count(TEST_DAG_FOLDER_WITH_SUBDIR),
+                id="dag_path_subdir_with_example",
+            ),
+            pytest.param(
+                TEST_DAG_FOLDER_WITH_SUBDIR,
+                False,
+                get_corresponding_dag_file_count(TEST_DAG_FOLDER_WITH_SUBDIR, 
False),
+                id="dag_path_subdir_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)}):
+            response = test_client.get("/public/dagReport", params={"subdir": 
subdir})
+            assert response.status_code == 200
+            response_json = response.json()
+            expected_keys = {"dag_num", "dags", "duration", "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)

Review Comment:
   Keys check can be removed. Enforce by pydantic validation.



##########
tests/api_fastapi/core_api/routes/public/test_dag_report.py:
##########
@@ -0,0 +1,124 @@
+# 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
+
+from airflow.utils.file import list_py_file_paths
+
+from tests_common.test_utils.config import conf_vars
+from tests_common.test_utils.db import clear_db_dags
+
+pytestmark = pytest.mark.db_test
+
+TEST_DAG_FOLDER = "/opt/airflow/tests/dags"

Review Comment:
   To not hardcode it manually in case it changes later.
   ```suggestion
   TEST_DAG_FOLDER = os.environ["AIRFLOW__CORE__DAGS_FOLDER"]
   ```
   



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