|
64 | 64 | ),
|
65 | 65 | }
|
66 | 66 | }
|
| 67 | +JOB_RUN_ERROR_RESPONSE = { |
| 68 | + "data": [ |
| 69 | + { |
| 70 | + "id": RUN_ID, |
| 71 | + "href": EXPECTED_JOB_RUN_OP_EXTRA_LINK.format( |
| 72 | + account_id=ACCOUNT_ID, project_id=PROJECT_ID, run_id=RUN_ID |
| 73 | + ), |
| 74 | + "status": DbtCloudJobRunStatus.ERROR.value, |
| 75 | + } |
| 76 | + ] |
| 77 | +} |
67 | 78 |
|
68 | 79 |
|
69 | 80 | def mock_response_json(response: dict):
|
@@ -421,6 +432,73 @@ def test_execute_retry_from_failure(self, mock_run_job, conn_id, account_id):
|
421 | 432 | additional_run_config=self.config["additional_run_config"],
|
422 | 433 | )
|
423 | 434 |
|
| 435 | + @patch.object(DbtCloudHook, "_run_and_get_response") |
| 436 | + @pytest.mark.parametrize( |
| 437 | + "conn_id, account_id", |
| 438 | + [(ACCOUNT_ID_CONN, None), (NO_ACCOUNT_ID_CONN, ACCOUNT_ID)], |
| 439 | + ids=["default_account", "explicit_account"], |
| 440 | + ) |
| 441 | + def test_execute_retry_from_failure_run(self, mock_run_req, conn_id, account_id): |
| 442 | + operator = DbtCloudRunJobOperator( |
| 443 | + task_id=TASK_ID, |
| 444 | + dbt_cloud_conn_id=conn_id, |
| 445 | + account_id=account_id, |
| 446 | + trigger_reason=None, |
| 447 | + dag=self.dag, |
| 448 | + retry_from_failure=True, |
| 449 | + **self.config, |
| 450 | + ) |
| 451 | + self.mock_context["ti"].try_number = 1 |
| 452 | + |
| 453 | + assert operator.dbt_cloud_conn_id == conn_id |
| 454 | + assert operator.job_id == self.config["job_id"] |
| 455 | + assert operator.account_id == account_id |
| 456 | + assert operator.check_interval == self.config["check_interval"] |
| 457 | + assert operator.timeout == self.config["timeout"] |
| 458 | + assert operator.retry_from_failure |
| 459 | + assert operator.steps_override == self.config["steps_override"] |
| 460 | + assert operator.schema_override == self.config["schema_override"] |
| 461 | + assert operator.additional_run_config == self.config["additional_run_config"] |
| 462 | + |
| 463 | + operator.execute(context=self.mock_context) |
| 464 | + |
| 465 | + mock_run_req.assert_called() |
| 466 | + |
| 467 | + @patch.object( |
| 468 | + DbtCloudHook, "_run_and_get_response", return_value=mock_response_json(JOB_RUN_ERROR_RESPONSE) |
| 469 | + ) |
| 470 | + @patch.object(DbtCloudHook, "retry_failed_job_run") |
| 471 | + @pytest.mark.parametrize( |
| 472 | + "conn_id, account_id", |
| 473 | + [(ACCOUNT_ID_CONN, None), (NO_ACCOUNT_ID_CONN, ACCOUNT_ID)], |
| 474 | + ids=["default_account", "explicit_account"], |
| 475 | + ) |
| 476 | + def test_execute_retry_from_failure_rerun(self, mock_run_req, mock_rerun_req, conn_id, account_id): |
| 477 | + operator = DbtCloudRunJobOperator( |
| 478 | + task_id=TASK_ID, |
| 479 | + dbt_cloud_conn_id=conn_id, |
| 480 | + account_id=account_id, |
| 481 | + trigger_reason=None, |
| 482 | + dag=self.dag, |
| 483 | + retry_from_failure=True, |
| 484 | + **self.config, |
| 485 | + ) |
| 486 | + self.mock_context["ti"].try_number = 2 |
| 487 | + |
| 488 | + assert operator.dbt_cloud_conn_id == conn_id |
| 489 | + assert operator.job_id == self.config["job_id"] |
| 490 | + assert operator.account_id == account_id |
| 491 | + assert operator.check_interval == self.config["check_interval"] |
| 492 | + assert operator.timeout == self.config["timeout"] |
| 493 | + assert operator.retry_from_failure |
| 494 | + assert operator.steps_override == self.config["steps_override"] |
| 495 | + assert operator.schema_override == self.config["schema_override"] |
| 496 | + assert operator.additional_run_config == self.config["additional_run_config"] |
| 497 | + |
| 498 | + operator.execute(context=self.mock_context) |
| 499 | + |
| 500 | + mock_rerun_req.assert_called_once() |
| 501 | + |
424 | 502 | @patch.object(DbtCloudHook, "trigger_job_run")
|
425 | 503 | @pytest.mark.parametrize(
|
426 | 504 | "conn_id, account_id",
|
|
0 commit comments