david30907d commented on a change in pull request #19508:
URL: https://github.com/apache/airflow/pull/19508#discussion_r795121357
##########
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:[email protected]:5432/the_database' ==
str(engine.url)
Review comment:
oh I just copied this URI from this file, I thought it's the correct URI
for testing 😅
https://github.com/apache/airflow/blob/f8a6cbb3ac6bfb9a3c89c8a49d76a78e78af0430/tests/models/test_connection.py#L585
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]