Skip to content

Commit

Permalink
Revert "Cleanup some (old) tasks UI tests (apache#45335)" (apache#45350)
Browse files Browse the repository at this point in the history
This reverts commit 8fcde8c.
  • Loading branch information
potiuk authored Jan 2, 2025
1 parent f7da5e4 commit 608de6b
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 12 deletions.
38 changes: 38 additions & 0 deletions tests/dags/test_default_views.py
Original file line number Diff line number Diff line change
@@ -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",
)
45 changes: 33 additions & 12 deletions tests/www/views/test_views_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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)


Expand Down Expand Up @@ -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",
[
Expand Down

0 comments on commit 608de6b

Please sign in to comment.