mik-laj commented on a change in pull request #6777: [AIRFLOW-6223] BigQuery - 
improve hook tests [depends on AIRFLOW-6220]
URL: https://github.com/apache/airflow/pull/6777#discussion_r356634126
 
 

 ##########
 File path: tests/gcp/hooks/test_bigquery.py
 ##########
 @@ -432,16 +464,21 @@ def test_create_view_fails_on_exception(self):
             "useLegacySql": False
         }
 
-        mock_service = mock.Mock()
+        mock_service = mock_get_service.return_value
         method = mock_service.tables.return_value.insert
+        resp = type('', (object,), {"status": 500, "reason": "Query is 
required for views"})()
         method.return_value.execute.side_effect = HttpError(
-            resp={'status': '400'}, content=b'Query is required for views')
-        cursor = hook.BigQueryBaseCursor(mock_service, project_id)
-        with self.assertRaises(Exception):
+            resp=resp, content=b'Query is required for views')
+        mock_get_creds_and_proj_id.return_value = ("CREDENTIALS", project_id)
+        bq_hook = hook.BigQueryHook()
+        cursor = bq_hook.get_cursor()
+        with self.assertRaisesRegex(Exception, "HttpError 500 \"Query is 
required for views\""):
             cursor.create_empty_table(project_id, dataset_id, table_id,
                                       view=view)
 
-    def test_create_view(self):
+    
@mock.patch('airflow.gcp.hooks.base.CloudBaseHook._get_credentials_and_project_id')
 
 Review comment:
   ```suggestion
       
@mock.patch('airflow.gcp.hooks.base.CloudBaseHook._get_credentials_and_project_id',
 return_value=("CREDENTIALS", "PROJECT_ID",))
   ```
   For consistency

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to