You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2021/07/21 11:35:52 UTC
[airflow] branch main updated: Fix bool conversion Verify parameter
in Tableau Hook (#17125)
This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new ef3c75d Fix bool conversion Verify parameter in Tableau Hook (#17125)
ef3c75d is described below
commit ef3c75df17d87b292f8c06b250a41633aaccbdc0
Author: Michele Zanchi <mi...@gmail.com>
AuthorDate: Wed Jul 21 13:35:33 2021 +0200
Fix bool conversion Verify parameter in Tableau Hook (#17125)
---
airflow/providers/tableau/hooks/tableau.py | 11 +++++-----
tests/providers/tableau/hooks/test_tableau.py | 29 +++++++++++++++++++++++++++
2 files changed, 35 insertions(+), 5 deletions(-)
diff --git a/airflow/providers/tableau/hooks/tableau.py b/airflow/providers/tableau/hooks/tableau.py
index 87aad58..d9193f7 100644
--- a/airflow/providers/tableau/hooks/tableau.py
+++ b/airflow/providers/tableau/hooks/tableau.py
@@ -65,11 +65,12 @@ class TableauHook(BaseHook):
self.conn = self.get_connection(self.tableau_conn_id)
self.site_id = site_id or self.conn.extra_dejson.get('site_id', '')
self.server = Server(self.conn.host)
- verify = self.conn.extra_dejson.get('verify', 'True')
- try:
- verify = bool(strtobool(verify))
- except ValueError:
- pass
+ verify = self.conn.extra_dejson.get('verify', True)
+ if isinstance(verify, str):
+ try:
+ verify = bool(strtobool(verify))
+ except ValueError:
+ pass
self.server.add_http_options(
options_dict={'verify': verify, 'cert': self.conn.extra_dejson.get('cert', None)}
)
diff --git a/tests/providers/tableau/hooks/test_tableau.py b/tests/providers/tableau/hooks/test_tableau.py
index f49d770..292321f 100644
--- a/tests/providers/tableau/hooks/test_tableau.py
+++ b/tests/providers/tableau/hooks/test_tableau.py
@@ -74,6 +74,16 @@ class TestTableauHook(unittest.TestCase):
)
db.merge_conn(
models.Connection(
+ conn_id='tableau_test_ssl_bool_param_connection',
+ conn_type='tableau',
+ host='tableau',
+ login='user',
+ password='password',
+ extra='{"verify": false}',
+ )
+ )
+ db.merge_conn(
+ models.Connection(
conn_id='tableau_test_ssl_connection_default',
conn_type='tableau',
host='tableau',
@@ -179,6 +189,25 @@ class TestTableauHook(unittest.TestCase):
@patch('airflow.providers.tableau.hooks.tableau.TableauAuth')
@patch('airflow.providers.tableau.hooks.tableau.Server')
+ def test_get_conn_ssl_bool_param(self, mock_server, mock_tableau_auth):
+ """
+ Test get conn with SSL Verify parameter as bool
+ """
+ with TableauHook(tableau_conn_id='tableau_test_ssl_bool_param_connection') as tableau_hook:
+ mock_server.assert_called_once_with(tableau_hook.conn.host)
+ mock_server.return_value.add_http_options.assert_called_once_with(
+ options_dict={'verify': False, 'cert': None}
+ )
+ mock_tableau_auth.assert_called_once_with(
+ username=tableau_hook.conn.login,
+ password=tableau_hook.conn.password,
+ site_id='',
+ )
+ mock_server.return_value.auth.sign_in.assert_called_once_with(mock_tableau_auth.return_value)
+ mock_server.return_value.auth.sign_out.assert_called_once_with()
+
+ @patch('airflow.providers.tableau.hooks.tableau.TableauAuth')
+ @patch('airflow.providers.tableau.hooks.tableau.Server')
@patch('airflow.providers.tableau.hooks.tableau.Pager', return_value=[1, 2, 3])
def test_get_all(self, mock_pager, mock_server, mock_tableau_auth):
"""