From 608de6b97ef04307559d79b2044899adfb9b2a93 Mon Sep 17 00:00:00 2001 From: Jarek Potiuk Date: Thu, 2 Jan 2025 14:27:23 +0100 Subject: [PATCH] Revert "Cleanup some (old) tasks UI tests (#45335)" (#45350) This reverts commit 8fcde8cef91f9a7b37ef6a903ebf273aa4ecbf18. --- tests/dags/test_default_views.py | 38 ++++++++++++++++++++++++ tests/www/views/test_views_tasks.py | 45 +++++++++++++++++++++-------- 2 files changed, 71 insertions(+), 12 deletions(-) create mode 100644 tests/dags/test_default_views.py diff --git a/tests/dags/test_default_views.py b/tests/dags/test_default_views.py new file mode 100644 index 0000000000000..3969151f44abd --- /dev/null +++ b/tests/dags/test_default_views.py @@ -0,0 +1,38 @@ +# +# 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 pendulum + +from airflow.models.dag import DAG + +args = {"owner": "airflow", "retries": 3, "start_date": pendulum.datetime(2022, 1, 1)} + +tree_dag = DAG( + dag_id="test_tree_view", + default_args=args, + schedule="0 0 * * *", + default_view="grid", +) + +graph_dag = DAG( + dag_id="test_graph_view", + default_args=args, + schedule="0 0 * * *", + default_view="graph", +) diff --git a/tests/www/views/test_views_tasks.py b/tests/www/views/test_views_tasks.py index 8289228b81dfe..11c155d3d6032 100644 --- a/tests/www/views/test_views_tasks.py +++ b/tests/www/views/test_views_tasks.py @@ -29,6 +29,8 @@ from airflow import settings from airflow.models.dag import DAG +from airflow.models.dagbag import DagBag +from airflow.models.serialized_dag import SerializedDagModel from airflow.models.taskinstance import TaskInstance from airflow.models.taskreschedule import TaskReschedule from airflow.models.xcom import XCom @@ -396,7 +398,7 @@ def test_rendered_k8s_without_k8s(admin_client): def test_tree_trigger_origin_tree_view(app, admin_client): triggered_by_kwargs = {"triggered_by": DagRunTriggeredByType.TEST} if AIRFLOW_V_3_0_PLUS else {} - app.dag_bag.get_dag("example_bash_operator").create_dagrun( + app.dag_bag.get_dag("test_tree_view").create_dagrun( run_type=DagRunType.SCHEDULED, logical_date=DEFAULT_DATE, data_interval=(DEFAULT_DATE, DEFAULT_DATE), @@ -405,16 +407,16 @@ def test_tree_trigger_origin_tree_view(app, admin_client): **triggered_by_kwargs, ) - url = "tree?dag_id=example_bash_operator" + url = "tree?dag_id=test_tree_view" resp = admin_client.get(url, follow_redirects=True) - params = {"origin": "/dags/example_bash_operator/grid"} - href = f"/dags/example_bash_operator/trigger?{html.escape(urllib.parse.urlencode(params))}" + params = {"origin": "/dags/test_tree_view/grid"} + href = f"/dags/test_tree_view/trigger?{html.escape(urllib.parse.urlencode(params))}" check_content_in_response(href, resp) def test_graph_trigger_origin_grid_view(app, admin_client): triggered_by_kwargs = {"triggered_by": DagRunTriggeredByType.TEST} if AIRFLOW_V_3_0_PLUS else {} - app.dag_bag.get_dag("example_bash_operator").create_dagrun( + app.dag_bag.get_dag("test_tree_view").create_dagrun( run_type=DagRunType.SCHEDULED, logical_date=DEFAULT_DATE, data_interval=(DEFAULT_DATE, DEFAULT_DATE), @@ -423,16 +425,16 @@ def test_graph_trigger_origin_grid_view(app, admin_client): **triggered_by_kwargs, ) - url = "/dags/example_bash_operator/graph" + url = "/dags/test_tree_view/graph" resp = admin_client.get(url, follow_redirects=True) - params = {"origin": "/dags/example_bash_operator/grid?tab=graph"} - href = f"/dags/example_bash_operator/trigger?{html.escape(urllib.parse.urlencode(params))}" + params = {"origin": "/dags/test_tree_view/grid?tab=graph"} + href = f"/dags/test_tree_view/trigger?{html.escape(urllib.parse.urlencode(params))}" check_content_in_response(href, resp) def test_gantt_trigger_origin_grid_view(app, admin_client): triggered_by_kwargs = {"triggered_by": DagRunTriggeredByType.TEST} if AIRFLOW_V_3_0_PLUS else {} - app.dag_bag.get_dag("example_bash_operator").create_dagrun( + app.dag_bag.get_dag("test_tree_view").create_dagrun( run_type=DagRunType.SCHEDULED, logical_date=DEFAULT_DATE, data_interval=(DEFAULT_DATE, DEFAULT_DATE), @@ -441,10 +443,10 @@ def test_gantt_trigger_origin_grid_view(app, admin_client): **triggered_by_kwargs, ) - url = "/dags/example_bash_operator/gantt" + url = "/dags/test_tree_view/gantt" resp = admin_client.get(url, follow_redirects=True) - params = {"origin": "/dags/example_bash_operator/grid?tab=gantt"} - href = f"/dags/example_bash_operator/trigger?{html.escape(urllib.parse.urlencode(params))}" + params = {"origin": "/dags/test_tree_view/grid?tab=gantt"} + href = f"/dags/test_tree_view/trigger?{html.escape(urllib.parse.urlencode(params))}" check_content_in_response(href, resp) @@ -497,6 +499,25 @@ def test_code(admin_client): check_content_in_response("example_bash_operator", resp) +def test_code_from_db(admin_client): + dag = DagBag(include_examples=True).get_dag("example_bash_operator") + SerializedDagModel.write_dag(dag) + url = "code?dag_id=example_bash_operator" + resp = admin_client.get(url, follow_redirects=True) + check_content_not_in_response("Failed to load DAG file Code", resp) + check_content_in_response("example_bash_operator", resp) + + +def test_code_from_db_all_example_dags(admin_client): + dagbag = DagBag(include_examples=True) + for dag in dagbag.dags.values(): + SerializedDagModel.write_dag(dag) + url = "code?dag_id=example_bash_operator" + resp = admin_client.get(url, follow_redirects=True) + check_content_not_in_response("Failed to load DAG file Code", resp) + check_content_in_response("example_bash_operator", resp) + + @pytest.mark.parametrize( "url, data, content", [