You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2019/12/20 14:58:32 UTC

[GitHub] [airflow] nuclearpinguin commented on a change in pull request #6865: [AIRFLOW-6314] BigQuery - improve BigQueryHook test

nuclearpinguin commented on a change in pull request #6865: [AIRFLOW-6314] BigQuery - improve BigQueryHook test
URL: https://github.com/apache/airflow/pull/6865#discussion_r360408169
 
 

 ##########
 File path: tests/gcp/hooks/test_bigquery.py
 ##########
 @@ -56,21 +55,108 @@ def test_bigquery_client_creation(
         )
         self.assertEqual(mock_bigquery_connection.return_value, result)
 
+    @mock.patch(
+        'airflow.gcp.hooks.base.CloudBaseHook._get_credentials_and_project_id',
+        return_value=("CREDENTIALS", "PROJECT_ID",)
+    )
+    @mock.patch("airflow.gcp.hooks.base.CloudBaseHook.__init__")
+    def test_bigquery_bigquery_conn_id_deprecation_warning(
+        self, mock_base_hook_init, mock_get_creds_and_proj_id
+    ):
+        bigquery_conn_id = "bigquery conn id"
+        warning_message = "The bigquery_conn_id parameter has been deprecated. " \
+                          "You should pass the gcp_conn_id parameter."
+        with self.assertWarns(DeprecationWarning) as warn:
+            hook.BigQueryHook(bigquery_conn_id=bigquery_conn_id)
+            mock_base_hook_init.assert_called_once_with(delegate_to=None, gcp_conn_id='bigquery conn id')
+        self.assertEqual(warning_message, str(warn.warning))
 
-class TestPandasGbqCredentials(unittest.TestCase):
     @mock.patch(
         'airflow.gcp.hooks.base.CloudBaseHook._get_credentials_and_project_id',
         return_value=("CREDENTIALS", "PROJECT_ID",)
     )
-    @mock.patch('airflow.gcp.hooks.bigquery.read_gbq')
-    def test_credentials_provided(self, mock_read_gbq, mock_get_creds_and_proj_id):
-        self.instance = hook.BigQueryHook()  # pylint: disable=attribute-defined-outside-init
+    def test_bigquery_insert_rows_not_implemented(self, mock_get_creds_and_proj_id):
+        bq_hook = hook.BigQueryHook()
+        with self.assertRaises(NotImplementedError):
+            bq_hook.insert_rows(table="table", rows=[1, 2])
 
-        self.instance.get_pandas_df('select 1')
+    @mock.patch(
+        'airflow.gcp.hooks.base.CloudBaseHook._get_credentials_and_project_id',
+        return_value=("CREDENTIALS", "PROJECT_ID",)
+    )
+    @mock.patch("airflow.gcp.hooks.bigquery.BigQueryHook.get_service")
+    def test_bigquery_table_exists_true(self, mock_get_service, mock_get_creds_and_proj_id):
+        project_id = 'bq-project'
+        dataset_id = 'bq_dataset'
+        table_id = 'bq_table_view'
 
 Review comment:
   Maybe it's worth to convert those variables to constants? This will reduce boilerplate code ;)

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


With regards,
Apache Git Services