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


##########
airflow/api_fastapi/views/public/dag_run.py:
##########
@@ -0,0 +1,46 @@
+# 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 fastapi import Depends, HTTPException
+from sqlalchemy import select
+from sqlalchemy.orm import Session
+from typing_extensions import Annotated
+
+from airflow.api_fastapi.db.common import get_session
+from airflow.api_fastapi.openapi.exceptions import 
create_openapi_http_exception_doc
+from airflow.api_fastapi.serializers.dag_run import DAGRunResponse
+from airflow.api_fastapi.views.router import AirflowRouter
+from airflow.models import DagRun
+
+dag_run_router = AirflowRouter(tags=["DagRun"])

Review Comment:
   To avoid having to copy/past this part on all `@router`
   
   ```suggestion
   dag_run_router = AirflowRouter(tags=["DagRun"], 
prefix="/dags/{dag_id}/dagRuns")
   ```



##########
tests/api_fastapi/views/public/test_dag_run.py:
##########
@@ -0,0 +1,130 @@
+# 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 datetime import datetime, timezone
+
+import pytest
+
+from airflow.operators.empty import EmptyOperator
+from airflow.utils.session import provide_session
+from airflow.utils.state import DagRunState
+from airflow.utils.types import DagRunTriggeredByType, DagRunType
+from tests.test_utils.db import clear_db_dags, clear_db_runs, 
clear_db_serialized_dags
+
+pytestmark = pytest.mark.db_test
+
+DAG1_ID = "test_dag1"
+DAG2_ID = "test_dag2"
+DAG1_RUN1_ID = "dag_run_1"
+DAG1_RUN2_ID = "dag_run_2"
+DAG2_RUN1_ID = "dag_run_3"
+DAG2_RUN2_ID = "dag_run_4"
+DAG1_RUN1_STATE = DagRunState.SUCCESS
+DAG1_RUN2_STATE = DagRunState.FAILED
+DAG2_RUN1_STATE = DagRunState.SUCCESS
+DAG2_RUN2_STATE = DagRunState.SUCCESS
+DAG1_RUN1_RUN_TYPE = DagRunType.MANUAL
+DAG1_RUN2_RUN_TYPE = DagRunType.SCHEDULED
+DAG2_RUN1_RUN_TYPE = DagRunType.BACKFILL_JOB
+DAG2_RUN2_RUN_TYPE = DagRunType.DATASET_TRIGGERED
+DAG1_RUN1_TRIGGERED_BY = DagRunTriggeredByType.UI
+DAG1_RUN2_TRIGGERED_BY = DagRunTriggeredByType.DATASET
+DAG2_RUN1_TRIGGERED_BY = DagRunTriggeredByType.CLI
+DAG2_RUN2_TRIGGERED_BY = DagRunTriggeredByType.REST_API
+START_DATE = datetime(2024, 6, 15, 0, 0, tzinfo=timezone.utc)
+EXECUTION_DATE = datetime(2024, 6, 16, 0, 0, tzinfo=timezone.utc)
+DAG1_NOTE = "test_note"
+
+
+@pytest.fixture(autouse=True)
+@provide_session
+def setup(dag_maker, session=None):
+    clear_db_runs()
+    clear_db_dags()
+    clear_db_serialized_dags()
+
+    with dag_maker(
+        DAG1_ID,
+        schedule="@daily",
+        start_date=START_DATE,
+    ):
+        EmptyOperator(task_id="task_1")
+    dag1 = dag_maker.create_dagrun(
+        run_id=DAG1_RUN1_ID,
+        state=DAG1_RUN1_STATE,
+        run_type=DAG1_RUN1_RUN_TYPE,
+        triggered_by=DAG1_RUN1_TRIGGERED_BY,
+    )
+    dag1.note = (DAG1_NOTE, 1)
+
+    dag_maker.create_dagrun(
+        run_id=DAG1_RUN2_ID,
+        state=DAG1_RUN2_STATE,
+        run_type=DAG1_RUN2_RUN_TYPE,
+        triggered_by=DAG1_RUN2_TRIGGERED_BY,
+        execution_date=EXECUTION_DATE,
+    )
+
+    with dag_maker(
+        DAG2_ID,
+        schedule=None,
+        start_date=START_DATE,
+    ):
+        EmptyOperator(task_id="task_2")
+    dag_maker.create_dagrun(
+        run_id=DAG2_RUN1_ID,
+        state=DAG2_RUN1_STATE,
+        run_type=DAG2_RUN1_RUN_TYPE,
+        triggered_by=DAG2_RUN1_TRIGGERED_BY,
+        execution_date=EXECUTION_DATE,
+    )
+    dag_maker.create_dagrun(
+        run_id=DAG2_RUN2_ID,
+        state=DAG2_RUN2_STATE,
+        run_type=DAG2_RUN2_RUN_TYPE,
+        triggered_by=DAG2_RUN2_TRIGGERED_BY,
+        execution_date=EXECUTION_DATE,
+    )
+
+    dag_maker.dagbag.sync_to_db()
+    dag_maker.dag_model
+    dag_maker.dag_model.has_task_concurrency_limits = True
+    session.merge(dag_maker.dag_model)
+    session.commit()
+
+
+@pytest.mark.parametrize(
+    "dag_id, run_id, state, run_type, triggered_by, dag_run_note",
+    [
+        (DAG1_ID, DAG1_RUN1_ID, DAG1_RUN1_STATE, DAG1_RUN1_RUN_TYPE, 
DAG1_RUN1_TRIGGERED_BY, DAG1_NOTE),
+        (DAG1_ID, DAG1_RUN2_ID, DAG1_RUN2_STATE, DAG1_RUN2_RUN_TYPE, 
DAG1_RUN2_TRIGGERED_BY, None),
+        (DAG2_ID, DAG2_RUN1_ID, DAG2_RUN1_STATE, DAG2_RUN1_RUN_TYPE, 
DAG2_RUN1_TRIGGERED_BY, None),
+        (DAG2_ID, DAG2_RUN2_ID, DAG2_RUN2_STATE, DAG2_RUN2_RUN_TYPE, 
DAG2_RUN2_TRIGGERED_BY, None),
+    ],
+)
+def test_get_dag_run(test_client, dag_id, run_id, state, run_type, 
triggered_by, dag_run_note):

Review Comment:
   Maybe opt for `class oriented` tests. For instance you can take a look to 
`connections` tests.
   
   I will update `dags`, because this is more consistant with `class oriented` 
airflow tests. (most of them are written like this).
   
   Also you can add a test case for 404. 



-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to