ciancolo commented on a change in pull request #17034:
URL: https://github.com/apache/airflow/pull/17034#discussion_r673101605
##########
File path: tests/providers/tableau/hooks/test_tableau.py
##########
@@ -189,3 +191,91 @@ def test_get_all(self, mock_pager, mock_server,
mock_tableau_auth):
assert jobs == mock_pager.return_value
mock_pager.assert_called_once_with(mock_server.return_value.jobs.get)
+
+ @parameterized.expand(
+ [
+ (0, TableauJobFinishCode.SUCCESS),
+ (1, TableauJobFinishCode.ERROR),
+ (2, TableauJobFinishCode.CANCELED),
+ ]
+ )
+ @patch('airflow.providers.tableau.hooks.tableau.Server')
+ def test_get_job_status(self, finish_code, expected_status,
mock_tableau_server):
+ """
+ Test get job status
+ """
+ mock_tableau_server.jobs.get_by_id.return_value.finish_code =
finish_code
+ with TableauHook(tableau_conn_id='tableau_test_password') as
tableau_hook:
+ tableau_hook.server = mock_tableau_server
+ jobs_status = tableau_hook.get_job_status(job_id='j1')
+ assert jobs_status == expected_status
+
+ @patch('airflow.providers.tableau.hooks.tableau.Server')
+ def test_wait_for_state(self, mock_tableau_server):
+ """
+ Test wait_for_state
+ """
+ # Test SUCCESS Positive
+ with TableauHook(tableau_conn_id='tableau_test_password') as
tableau_hook:
+ tableau_hook.get_job_status = MagicMock(
+ name='get_job_status',
+ side_effect=[TableauJobFinishCode.PENDING,
TableauJobFinishCode.SUCCESS],
+ )
+ assert tableau_hook.wait_for_state(
+ job_id='j1', target_state=TableauJobFinishCode.SUCCESS,
check_interval=1
+ )
+
+ # Test SUCCESS Negative
+ with TableauHook(tableau_conn_id='tableau_test_password') as
tableau_hook:
+ tableau_hook.get_job_status = MagicMock(
+ name='get_job_status',
+ side_effect=[
+ TableauJobFinishCode.PENDING,
+ TableauJobFinishCode.PENDING,
+ TableauJobFinishCode.ERROR,
+ ],
+ )
+ assert not tableau_hook.wait_for_state(
+ job_id='j1', target_state=TableauJobFinishCode.SUCCESS,
check_interval=1
+ )
+
+ # Test ERROR Positive
+ with TableauHook(tableau_conn_id='tableau_test_password') as
tableau_hook:
+ tableau_hook.get_job_status = MagicMock(
+ name='get_job_status',
+ side_effect=[
+ TableauJobFinishCode.PENDING,
+ TableauJobFinishCode.PENDING,
+ TableauJobFinishCode.ERROR,
+ ],
+ )
+ assert tableau_hook.wait_for_state(
+ job_id='j1', target_state=TableauJobFinishCode.ERROR,
check_interval=1
+ )
+
+ # Test CANCELLED Positive
+ with TableauHook(tableau_conn_id='tableau_test_password') as
tableau_hook:
+ tableau_hook.get_job_status = MagicMock(
+ name='get_job_status',
+ side_effect=[
+ TableauJobFinishCode.PENDING,
+ TableauJobFinishCode.PENDING,
Review comment:
Yeah, because I wanted to replicate more realistic cases with multiple
PENDING states and one different state. If you think, they are not necessary
and the tests are more clear without them, I will remove them.
--
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]