airflow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [airflow] ephraimbuddy commented on a change in pull request #9475: Add extra links endpoint
Date Mon, 22 Jun 2020 18:59:44 GMT

ephraimbuddy commented on a change in pull request #9475:
URL: https://github.com/apache/airflow/pull/9475#discussion_r443764076



##########
File path: tests/api_connexion/endpoints/test_extra_link_endpoint.py
##########
@@ -15,24 +15,198 @@
 # specific language governing permissions and limitations
 # under the License.
 import unittest
+from unittest import mock
+from urllib.parse import quote
 
-import pytest
+from parameterized import parameterized
+from test_utils.mock_plugins import mock_plugin_manager
 
+from airflow import DAG
+from airflow.models.baseoperator import BaseOperatorLink
+from airflow.models.dagrun import DagRun
+from airflow.models.xcom import XCom
+from airflow.plugins_manager import AirflowPlugin
+from airflow.providers.google.cloud.operators.bigquery import BigQueryExecuteQueryOperator
+from airflow.utils.dates import days_ago
+from airflow.utils.session import provide_session
+from airflow.utils.timezone import datetime
+from airflow.utils.types import DagRunType
 from airflow.www import app
+from tests.test_utils.db import clear_db_runs, clear_db_xcom
 
 
 class TestGetExtraLinks(unittest.TestCase):
     @classmethod
     def setUpClass(cls) -> None:
         super().setUpClass()
-        cls.app = app.create_app(testing=True)  # type:ignore
+        with mock.patch.dict('os.environ', SKIP_DAGS_PARSING='True'):
+            cls.app = app.create_app(testing=True)  # type:ignore
+
+    @provide_session
+    def setUp(self, session) -> None:
+        self.now = datetime(2020, 1, 1)
+
+        clear_db_runs()
+        clear_db_xcom()
+
+        self.dag = self._create_dag()
+        self.app.dag_bag.dags = {self.dag.dag_id: self.dag}  # type: ignore  # pylint: disable=no-member
+        self.app.dag_bag.sync_to_db()   # type: ignore  # pylint: disable=no-member
+
+        dr = DagRun(
+            dag_id=self.dag.dag_id,
+            run_id="TEST_DAG_RUN_ID",
+            execution_date=self.now,
+            run_type=DagRunType.MANUAL.value,
+        )
+        session.add(dr)
+        session.commit()
 
-    def setUp(self) -> None:
         self.client = self.app.test_client()  # type:ignore
 
-    @pytest.mark.skip(reason="Not implemented yet")
+    def tearDown(self) -> None:
+        super().tearDown()
+        clear_db_runs()
+        clear_db_xcom()
+
+    @staticmethod
+    def _create_dag():
+        with DAG(dag_id="TEST_DAG_ID", default_args=dict(start_date=days_ago(2),)) as dag:
+            BigQueryExecuteQueryOperator(task_id="TEST_SINGLE_QUERY", sql="SELECT 1")
+            BigQueryExecuteQueryOperator(task_id="TEST_MULTIPLE_QUERY", sql=["SELECT 1",
"SELECT 2"])

Review comment:
       ```suggestion
               BigQueryInsertJobOperator(task_id="TEST_SINGLE_QUERY", sql="SELECT 1")
               BigQueryInsertJobOperator(task_id="TEST_MULTIPLE_QUERY", sql=["SELECT 1", "SELECT
2"])
   ```
   This operator `BigQueryExecuteQueryOperator` is deprecated




----------------------------------------------------------------
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.

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



Mime
View raw message