This is an automated email from the ASF dual-hosted git repository.

pierrejeambrun pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new f84d16e6fc Add views tests (#41957)
f84d16e6fc is described below

commit f84d16e6fcef04875cb1156478caa742709b0ead
Author: Pierre Jeambrun <[email protected]>
AuthorDate: Tue Sep 3 10:27:41 2024 +0200

    Add views tests (#41957)
---
 airflow/api_ui/views/datasets.py                   |  2 +-
 contributing-docs/testing/unit_tests.rst           |  2 +-
 dev/breeze/src/airflow_breeze/utils/run_tests.py   |  2 +-
 .../src/airflow_breeze/utils/selective_checks.py   |  2 +
 .../tests/test_pytest_args_for_test_types.py       |  5 ++-
 dev/breeze/tests/test_selective_checks.py          | 27 +++++++++++-
 .../ci/pre_commit/check_tests_in_right_folders.py  |  1 +
 tests/api_ui/__init__.py                           | 16 +++++++
 tests/api_ui/conftest.py                           | 27 ++++++++++++
 tests/api_ui/views/__init__.py                     | 16 +++++++
 tests/api_ui/views/test_datasets.py                | 50 ++++++++++++++++++++++
 11 files changed, 144 insertions(+), 6 deletions(-)

diff --git a/airflow/api_ui/views/datasets.py b/airflow/api_ui/views/datasets.py
index fe7f2e901f..2ab983082f 100644
--- a/airflow/api_ui/views/datasets.py
+++ b/airflow/api_ui/views/datasets.py
@@ -30,7 +30,7 @@ dataset_router = APIRouter(tags=["Dataset"])
 # Ultimately we want async routes, with async sqlalchemy session / context 
manager.
 # Additional effort to make airflow utility code async, not handled for now 
and most likely part of the AIP-70
 @dataset_router.get("/next_run_datasets/{dag_id}")
-def next_run_datasets(dag_id: str, request: Request) -> dict:
+async def next_run_datasets(dag_id: str, request: Request) -> dict:
     dag = request.app.state.dag_bag.get_dag(dag_id)
 
     if not dag:
diff --git a/contributing-docs/testing/unit_tests.rst 
b/contributing-docs/testing/unit_tests.rst
index 8d27db19c2..9b4027843f 100644
--- a/contributing-docs/testing/unit_tests.rst
+++ b/contributing-docs/testing/unit_tests.rst
@@ -96,7 +96,7 @@ test types you want to use in various ``breeze testing`` 
sub-commands in three w
 Those test types are defined:
 
 * ``Always`` - those are tests that should be always executed (always 
sub-folder)
-* ``API`` - Tests for the Airflow API (api, api_connexion and api_internal 
sub-folders)
+* ``API`` - Tests for the Airflow API (api, api_connexion, api_internal, 
api_ui sub-folders)
 * ``CLI`` - Tests for the Airflow CLI (cli folder)
 * ``Core`` - for the core Airflow functionality (core, executors, jobs, 
models, ti_deps, utils sub-folders)
 * ``Operators`` - tests for the operators (operators folder with exception of 
Virtualenv Operator tests and
diff --git a/dev/breeze/src/airflow_breeze/utils/run_tests.py 
b/dev/breeze/src/airflow_breeze/utils/run_tests.py
index 850abf4c19..1e8887b60b 100644
--- a/dev/breeze/src/airflow_breeze/utils/run_tests.py
+++ b/dev/breeze/src/airflow_breeze/utils/run_tests.py
@@ -133,7 +133,7 @@ def get_excluded_provider_args(python_version: str) -> 
list[str]:
 
 TEST_TYPE_MAP_TO_PYTEST_ARGS: dict[str, list[str]] = {
     "Always": ["tests/always"],
-    "API": ["tests/api", "tests/api_connexion", "tests/api_internal"],
+    "API": ["tests/api", "tests/api_connexion", "tests/api_internal", 
"tests/api_ui"],
     "BranchPythonVenv": [
         "tests/operators/test_python.py::TestBranchPythonVirtualenvOperator",
     ],
diff --git a/dev/breeze/src/airflow_breeze/utils/selective_checks.py 
b/dev/breeze/src/airflow_breeze/utils/selective_checks.py
index a78cac8dcb..f5fc88385b 100644
--- a/dev/breeze/src/airflow_breeze/utils/selective_checks.py
+++ b/dev/breeze/src/airflow_breeze/utils/selective_checks.py
@@ -264,9 +264,11 @@ TEST_TYPE_MATCHES = HashableDict(
             r"^airflow/api/",
             r"^airflow/api_connexion/",
             r"^airflow/api_internal/",
+            r"^airflow/api_ui/",
             r"^tests/api/",
             r"^tests/api_connexion/",
             r"^tests/api_internal/",
+            r"^tests/api_ui/",
         ],
         SelectiveUnitTestTypes.CLI: [
             r"^airflow/cli/",
diff --git a/dev/breeze/tests/test_pytest_args_for_test_types.py 
b/dev/breeze/tests/test_pytest_args_for_test_types.py
index e1118873e3..e0edfa3f51 100644
--- a/dev/breeze/tests/test_pytest_args_for_test_types.py
+++ b/dev/breeze/tests/test_pytest_args_for_test_types.py
@@ -54,7 +54,7 @@ from airflow_breeze.utils.run_tests import 
convert_parallel_types_to_folders, co
         ),
         (
             "API",
-            ["tests/api", "tests/api_connexion", "tests/api_internal"],
+            ["tests/api", "tests/api_connexion", "tests/api_internal", 
"tests/api_ui"],
             False,
         ),
         (
@@ -237,7 +237,7 @@ def test_pytest_args_for_helm_test_types(helm_test_package: 
str, pytest_args: li
     [
         (
             "API",
-            ["tests/api", "tests/api_connexion", "tests/api_internal"],
+            ["tests/api", "tests/api_connexion", "tests/api_internal", 
"tests/api_ui"],
             False,
         ),
         (
@@ -253,6 +253,7 @@ def test_pytest_args_for_helm_test_types(helm_test_package: 
str, pytest_args: li
                 "tests/api",
                 "tests/api_connexion",
                 "tests/api_internal",
+                "tests/api_ui",
                 "tests/cli",
             ],
             False,
diff --git a/dev/breeze/tests/test_selective_checks.py 
b/dev/breeze/tests/test_selective_checks.py
index 9806a50e46..8093612d60 100644
--- a/dev/breeze/tests/test_selective_checks.py
+++ b/dev/breeze/tests/test_selective_checks.py
@@ -179,7 +179,32 @@ def assert_outputs_are_printed(expected_outputs: dict[str, 
str], stderr: str):
                     "needs-mypy": "true",
                     "mypy-folders": "['airflow']",
                 },
-                id="Only API tests and DOCS should run (no provider tests) 
when only internal_api changed",
+                id="Only API tests and DOCS should run (no provider tests) 
when only internal api changed",
+            )
+        ),
+        (
+            pytest.param(
+                ("airflow/api_ui/file.py",),
+                {
+                    "all-python-versions": "['3.8']",
+                    "all-python-versions-list-as-string": "3.8",
+                    "python-versions": "['3.8']",
+                    "python-versions-list-as-string": "3.8",
+                    "ci-image-build": "true",
+                    "prod-image-build": "false",
+                    "needs-helm-tests": "false",
+                    "run-tests": "true",
+                    "run-amazon-tests": "false",
+                    "docs-build": "true",
+                    "skip-pre-commits": 
"check-provider-yaml-valid,identity,lint-helm-chart,mypy-airflow,mypy-dev,"
+                    
"mypy-docs,mypy-providers,ts-compile-format-lint-ui,ts-compile-format-lint-www",
+                    "upgrade-to-newer-dependencies": "false",
+                    "parallel-test-types-list-as-string": "API Always",
+                    "separate-test-types-list-as-string": "API Always",
+                    "needs-mypy": "true",
+                    "mypy-folders": "['airflow']",
+                },
+                id="Only API tests and DOCS should run (no provider tests) 
when only ui api changed",
             )
         ),
         (
diff --git a/scripts/ci/pre_commit/check_tests_in_right_folders.py 
b/scripts/ci/pre_commit/check_tests_in_right_folders.py
index 17755bc986..5a7e2c4ec2 100755
--- a/scripts/ci/pre_commit/check_tests_in_right_folders.py
+++ b/scripts/ci/pre_commit/check_tests_in_right_folders.py
@@ -33,6 +33,7 @@ POSSIBLE_TEST_FOLDERS = [
     "api",
     "api_connexion",
     "api_internal",
+    "api_ui",
     "auth",
     "callbacks",
     "charts",
diff --git a/tests/api_ui/__init__.py b/tests/api_ui/__init__.py
new file mode 100644
index 0000000000..13a83393a9
--- /dev/null
+++ b/tests/api_ui/__init__.py
@@ -0,0 +1,16 @@
+# 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.
diff --git a/tests/api_ui/conftest.py b/tests/api_ui/conftest.py
new file mode 100644
index 0000000000..9f82802142
--- /dev/null
+++ b/tests/api_ui/conftest.py
@@ -0,0 +1,27 @@
+# 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
+
+import pytest
+from fastapi.testclient import TestClient
+
+from airflow.api_ui.app import create_app
+
+
[email protected]
+def test_client():
+    return TestClient(create_app())
diff --git a/tests/api_ui/views/__init__.py b/tests/api_ui/views/__init__.py
new file mode 100644
index 0000000000..13a83393a9
--- /dev/null
+++ b/tests/api_ui/views/__init__.py
@@ -0,0 +1,16 @@
+# 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.
diff --git a/tests/api_ui/views/test_datasets.py 
b/tests/api_ui/views/test_datasets.py
new file mode 100644
index 0000000000..12b22e4bbb
--- /dev/null
+++ b/tests/api_ui/views/test_datasets.py
@@ -0,0 +1,50 @@
+# 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
+
+import pytest
+
+from airflow.datasets import Dataset
+from airflow.operators.empty import EmptyOperator
+from tests.conftest import initial_db_init
+
+pytestmark = pytest.mark.db_test
+
+
[email protected](autouse=True)
+def cleanup():
+    """
+    Before each test re-init the database dropping and recreating the tables.
+    This will allow to reset indexes to be able to assert auto-incremented 
primary keys.
+    """
+    initial_db_init()
+
+
+def test_next_run_datasets(test_client, dag_maker):
+    with dag_maker(dag_id="upstream", 
schedule=[Dataset(uri="s3://bucket/key/1")], serialized=True):
+        EmptyOperator(task_id="task1")
+
+    dag_maker.create_dagrun()
+    dag_maker.dagbag.sync_to_db()
+
+    response = test_client.get("/ui/next_run_datasets/upstream")
+
+    assert response.status_code == 200
+    assert response.json() == {
+        "dataset_expression": {"all": ["s3://bucket/key/1"]},
+        "events": [{"id": 17, "uri": "s3://bucket/key/1", "lastUpdate": None}],
+    }

Reply via email to