Skip to content

Commit

Permalink
Cleanup some (old) tasks UI tests (apache#45335)
Browse files Browse the repository at this point in the history
These tests don't need to use a dedicated DAG, plus this is the only use
of DAGs from the tests dag dir, which means we can later switch to only
parsing the example DAGs.

This also removes a couple leftover DAG code related tests that aren't
needed anymore - all DAG code comes from the db, and we parse/store
example DAGs all over the place, so no extra value with these tests.

Why am I touching old UI stuff? My parsing changes for DAG bundles
breaks a bunch of these tests, and we aren't quite ready to remove the
old UI...
  • Loading branch information
jedcunningham authored Jan 2, 2025
1 parent 1f0bd6d commit 8fcde8c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 71 deletions.
38 changes: 0 additions & 38 deletions tests/dags/test_default_views.py

This file was deleted.

45 changes: 12 additions & 33 deletions tests/www/views/test_views_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@

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 @@ -398,7 +396,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("test_tree_view").create_dagrun(
app.dag_bag.get_dag("example_bash_operator").create_dagrun(
run_type=DagRunType.SCHEDULED,
logical_date=DEFAULT_DATE,
data_interval=(DEFAULT_DATE, DEFAULT_DATE),
Expand All @@ -407,16 +405,16 @@ def test_tree_trigger_origin_tree_view(app, admin_client):
**triggered_by_kwargs,
)

url = "tree?dag_id=test_tree_view"
url = "tree?dag_id=example_bash_operator"
resp = admin_client.get(url, follow_redirects=True)
params = {"origin": "/dags/test_tree_view/grid"}
href = f"/dags/test_tree_view/trigger?{html.escape(urllib.parse.urlencode(params))}"
params = {"origin": "/dags/example_bash_operator/grid"}
href = f"/dags/example_bash_operator/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("test_tree_view").create_dagrun(
app.dag_bag.get_dag("example_bash_operator").create_dagrun(
run_type=DagRunType.SCHEDULED,
logical_date=DEFAULT_DATE,
data_interval=(DEFAULT_DATE, DEFAULT_DATE),
Expand All @@ -425,16 +423,16 @@ def test_graph_trigger_origin_grid_view(app, admin_client):
**triggered_by_kwargs,
)

url = "/dags/test_tree_view/graph"
url = "/dags/example_bash_operator/graph"
resp = admin_client.get(url, follow_redirects=True)
params = {"origin": "/dags/test_tree_view/grid?tab=graph"}
href = f"/dags/test_tree_view/trigger?{html.escape(urllib.parse.urlencode(params))}"
params = {"origin": "/dags/example_bash_operator/grid?tab=graph"}
href = f"/dags/example_bash_operator/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("test_tree_view").create_dagrun(
app.dag_bag.get_dag("example_bash_operator").create_dagrun(
run_type=DagRunType.SCHEDULED,
logical_date=DEFAULT_DATE,
data_interval=(DEFAULT_DATE, DEFAULT_DATE),
Expand All @@ -443,10 +441,10 @@ def test_gantt_trigger_origin_grid_view(app, admin_client):
**triggered_by_kwargs,
)

url = "/dags/test_tree_view/gantt"
url = "/dags/example_bash_operator/gantt"
resp = admin_client.get(url, follow_redirects=True)
params = {"origin": "/dags/test_tree_view/grid?tab=gantt"}
href = f"/dags/test_tree_view/trigger?{html.escape(urllib.parse.urlencode(params))}"
params = {"origin": "/dags/example_bash_operator/grid?tab=gantt"}
href = f"/dags/example_bash_operator/trigger?{html.escape(urllib.parse.urlencode(params))}"
check_content_in_response(href, resp)


Expand Down Expand Up @@ -499,25 +497,6 @@ 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 8fcde8c

Please sign in to comment.