feluelle commented on a change in pull request #7903:
URL: https://github.com/apache/airflow/pull/7903#discussion_r452870681



##########
File path: airflow/providers/odbc/hooks/odbc.py
##########
@@ -69,20 +69,20 @@ def __init__(
         self._connect_kwargs = connect_kwargs
 
     @property
-    def connection(self):
+    def connection_(self):

Review comment:
       ```suggestion
       def connection(self):
   ```
   You can overwrite it.

##########
File path: airflow/providers/odbc/hooks/odbc.py
##########
@@ -69,20 +69,20 @@ def __init__(
         self._connect_kwargs = connect_kwargs
 
     @property
-    def connection(self):
+    def connection_(self):
         """
         ``airflow.Connection`` object with connection id ``odbc_conn_id``
         """
         if not self._connection:
-            self._connection = self.get_connection(getattr(self, 
self.conn_name_attr))
+            self._connection = self.connection

Review comment:
       ```suggestion
               self._connection = super().connection
   ```

##########
File path: airflow/providers/snowflake/hooks/snowflake.py
##########
@@ -120,14 +120,15 @@ def _get_aws_credentials(self):
 
         intended to be used by external import and export statements
         """
-        if self.snowflake_conn_id:  # pylint: disable=no-member
-            connection_object = self.get_connection(self.snowflake_conn_id)  # 
pylint: disable=no-member
-            if 'aws_secret_access_key' in connection_object.extra_dejson:
-                aws_access_key_id = connection_object.extra_dejson.get(
-                    'aws_access_key_id')
-                aws_secret_access_key = connection_object.extra_dejson.get(
-                    'aws_secret_access_key')
-        return aws_access_key_id, aws_secret_access_key
+        connection_object = self.connection
+        if 'aws_secret_access_key' in connection_object.extra_dejson:
+            aws_access_key_id = connection_object.extra_dejson.get(
+                'aws_access_key_id')
+            aws_secret_access_key = connection_object.extra_dejson.get(
+                'aws_secret_access_key')
+            return aws_access_key_id, aws_secret_access_key
+        else:
+            return None, None

Review comment:
       This is unrelated.

##########
File path: tests/providers/mysql/hooks/test_mysql.py
##########
@@ -181,8 +182,8 @@ def setUp(self):
         )
 
         self.db_hook = MySqlHook()
-        self.db_hook.get_connection = mock.Mock()
-        self.db_hook.get_connection.return_value = self.connection
+        self.db_hook._connection = mock.Mock()
+        self.db_hook._connection = self.connection

Review comment:
       ```suggestion
           self.db_hook.connection = mock.Mock(return_value=self.connection)
   ```

##########
File path: tests/providers/mysql/hooks/test_mysql.py
##########
@@ -52,8 +52,8 @@ def setUp(self):
         )
 
         self.db_hook = MySqlHook()
-        self.db_hook.get_connection = mock.Mock()
-        self.db_hook.get_connection.return_value = self.connection
+        self.db_hook._connection = mock.Mock()
+        self.db_hook._connection = self.connection

Review comment:
       ```suggestion
           self.db_hook.connection = mock.Mock(return_value=self.connection)
   ```

##########
File path: tests/providers/odbc/hooks/test_odbc.py
##########
@@ -17,35 +17,41 @@
 # specific language governing permissions and limitations
 # under the License.
 #
-import json
+import unittest
 from unittest import mock
 from urllib.parse import quote_plus, urlparse
 
 import pyodbc
+from parameterized import parameterized
 
 from airflow.models import Connection
 from airflow.providers.odbc.hooks.odbc import OdbcHook
 
 
-class TestOdbcHook:
-    def get_hook(self=None, hook_params=None, conn_params=None):
-        hook_params = hook_params or {}
-        conn_params = conn_params or {}
-        connection = Connection(
-            **{
-                **dict(login='login', password='password', host='host', 
schema='schema', port=1234),
-                **conn_params,
-            }
-        )
+class TestOdbcHook(unittest.TestCase):
+
+    def setUp(self):
+        super().setUp()
+
+        self.conn = conn = mock.MagicMock()
+        self.conn.login = 'login'
+        self.conn.password = 'password'
+        self.conn.host = 'host'
+        self.conn.schema = 'schema'
+        self.conn.port = 1234

Review comment:
       Please use the `Connection` class to init a connection like in the other 
cases.
   
   For example:
   ```python
   self.conn = mock.Mock(return_value=Connection(...))
   ```




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


Reply via email to