|
22 | 22 |
|
23 | 23 | from airflow.providers.common.compat.sdk import AirflowException |
24 | 24 | from airflow.providers.tableau.sensors.tableau import ( |
| 25 | + TableauJobFailedException, |
25 | 26 | TableauJobFinishCode, |
26 | 27 | TableauJobStatusSensor, |
27 | 28 | ) |
@@ -68,3 +69,35 @@ def test_poke_failed(self, mock_tableau_hook, finish_code): |
68 | 69 | with pytest.raises(AirflowException): |
69 | 70 | sensor.poke({}) |
70 | 71 | mock_tableau_hook.get_job_status.assert_called_once_with(job_id=sensor.job_id) |
| 72 | + |
| 73 | + @patch("airflow.providers.tableau.sensors.tableau.TableauHook") |
| 74 | + def test_poke_succeeds_on_last_try(self, mock_tableau_hook_class): |
| 75 | + mock_tableau_hook = Mock() |
| 76 | + mock_tableau_hook.get_job_status.side_effect = [ |
| 77 | + TableauJobFinishCode.ERROR, |
| 78 | + TableauJobFinishCode.CANCELED, |
| 79 | + TableauJobFinishCode.SUCCESS, |
| 80 | + ] |
| 81 | + mock_tableau_hook_class.return_value.__enter__.return_value = mock_tableau_hook |
| 82 | + sensor = TableauJobStatusSensor(**self.kwargs, max_status_retries=2) |
| 83 | + |
| 84 | + assert not sensor.poke({}) |
| 85 | + assert not sensor.poke({}) |
| 86 | + assert sensor.poke({}) |
| 87 | + assert mock_tableau_hook.get_job_status.call_count == 3 |
| 88 | + |
| 89 | + @patch("airflow.providers.tableau.sensors.tableau.TableauHook") |
| 90 | + def test_poke_failed_on_last_try(self, mock_tableau_hook_class): |
| 91 | + mock_tableau_hook = Mock() |
| 92 | + mock_tableau_hook.get_job_status.side_effect = [ |
| 93 | + TableauJobFinishCode.ERROR, |
| 94 | + TableauJobFinishCode.CANCELED, |
| 95 | + TableauJobFinishCode.ERROR, |
| 96 | + ] |
| 97 | + mock_tableau_hook_class.return_value.__enter__.return_value = mock_tableau_hook |
| 98 | + sensor = TableauJobStatusSensor(**self.kwargs, max_status_retries=2, poke_interval=10.0) |
| 99 | + assert not sensor.poke({}) |
| 100 | + assert not sensor.poke({}) |
| 101 | + with pytest.raises(TableauJobFailedException, match="The Tableau Refresh Workbook Job failed!"): |
| 102 | + sensor.poke({}) |
| 103 | + assert mock_tableau_hook.get_job_status.call_count == 3 |
0 commit comments