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 2022/01/02 09:38:41 UTC

[GitHub] [airflow] mik-laj commented on a change in pull request #19508: :bug: (BigQueryHook) fix compatibility with sqlalchemy engine

mik-laj commented on a change in pull request #19508:
URL: https://github.com/apache/airflow/pull/19508#discussion_r777187252



##########
File path: tests/providers/google/cloud/hooks/test_bigquery.py
##########
@@ -1837,3 +1840,38 @@ def test_create_external_table_description(self, mock_create):
 
         _, kwargs = mock_create.call_args
         assert kwargs['table_resource']['description'] is description
+
+
+class TestConnection(unittest.TestCase):
+    def setUp(self):
+        crypto._fernet = None
+        patcher = mock.patch('airflow.models.connection.mask_secret', autospec=True)
+        self.mask_secret = patcher.start()
+
+        self.addCleanup(patcher.stop)
+
+    def tearDown(self):
+        crypto._fernet = None
+    @mock.patch.dict(
+        'os.environ',
+        {
+            'AIRFLOW_CONN_TEST_URI': 'google-cloud-platform://?__extra__=%7B%22extra__google_cloud_platform__key_path%22%3A+%22%2Fopt%2FYOUR_FILE_PATH%2Fservice-account.json%22%2C+%22extra__google_cloud_platform__keyfile_dict%22%3A+%22%22%2C+%22extra__google_cloud_platform__num_retries%22%3A+5%2C+%22extra__google_cloud_platform__project%22%3A+%22YOUR_GCP_PROJECT%22%2C+%22extra__google_cloud_platform__scope%22%3A+%22https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform%22%7D',
+        },
+    )
+    def test_dbapi_get_uri(self):
+        conn = BaseHook.get_connection(conn_id='test_uri')
+        hook = conn.get_hook()
+        assert hook.get_uri().startswith('bigquery://')
+
+    @mock.patch.dict(
+        'os.environ',
+        {
+            'AIRFLOW_CONN_TEST_URI': 'google-cloud-platform://?__extra__=%7B%22extra__google_cloud_platform__key_path%22%3A+%22%2Fopt%2FYOUR_FILE_PATH%2Fservice-account.json%22%2C+%22extra__google_cloud_platform__keyfile_dict%22%3A+%22%22%2C+%22extra__google_cloud_platform__num_retries%22%3A+5%2C+%22extra__google_cloud_platform__project%22%3A+%22YOUR_GCP_PROJECT%22%2C+%22extra__google_cloud_platform__scope%22%3A+%22https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform%22%7D',
+        },
+    )
+    def test_dbapi_get_sqlalchemy_engine(self):
+        conn = BaseHook.get_connection(conn_id='test_uri')
+        hook = conn.get_hook()
+        engine = hook.get_sqlalchemy_engine()
+        assert isinstance(engine, sqlalchemy.engine.Engine)
+        assert 'postgres://username:password@ec2.compute.com:5432/the_database' == str(engine.url)

Review comment:
       ``ec2.compute.com`` Can you tell me a little more about it?




-- 
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-unsubscribe@airflow.apache.org

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