Skip to content

Commit

Permalink
Fix bool conversion Verify parameter in Tableau Hook (#17125)
Browse files Browse the repository at this point in the history
  • Loading branch information
ciancolo committed Jul 21, 2021
1 parent 96fd413 commit ef3c75d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
11 changes: 6 additions & 5 deletions airflow/providers/tableau/hooks/tableau.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ def __init__(self, site_id: Optional[str] = None, tableau_conn_id: str = default
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)}
)
Expand Down
29 changes: 29 additions & 0 deletions tests/providers/tableau/hooks/test_tableau.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ def setUp(self):
extra='{"verify": "False"}',
)
)
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',
Expand Down Expand Up @@ -177,6 +187,25 @@ def test_get_conn_ssl_disabled(self, mock_server, mock_tableau_auth):
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')
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])
Expand Down

0 comments on commit ef3c75d

Please sign in to comment.