From 77f9f02865a6fe0ceb0b408bab3bbaef5c32438a Mon Sep 17 00:00:00 2001 From: Kevin George Date: Sun, 21 Jan 2024 02:14:43 -0500 Subject: [PATCH] add test for delete job (#36933) --- .../providers/google/cloud/hooks/test_cloud_run.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/providers/google/cloud/hooks/test_cloud_run.py b/tests/providers/google/cloud/hooks/test_cloud_run.py index 0a1436075e0aa..04a683ada5241 100644 --- a/tests/providers/google/cloud/hooks/test_cloud_run.py +++ b/tests/providers/google/cloud/hooks/test_cloud_run.py @@ -22,6 +22,7 @@ import pytest from google.cloud.run_v2 import ( CreateJobRequest, + DeleteJobRequest, GetJobRequest, Job, ListJobsRequest, @@ -70,7 +71,7 @@ def test_update_job(self, mock_batch_service_client, cloud_run_hook): region = "region1" project_id = "projectid" job = Job() - job.name = job.name = f"projects/{project_id}/locations/{region}/jobs/{job_name}" + job.name = f"projects/{project_id}/locations/{region}/jobs/{job_name}" update_request = UpdateJobRequest() update_request.job = job @@ -247,6 +248,17 @@ def test_list_jobs_with_limit_less_than_zero(self, mock_batch_service_client, cl with pytest.raises(expected_exception=AirflowException): cloud_run_hook.list_jobs(region=region, project_id=project_id, limit=limit) + @mock.patch("airflow.providers.google.cloud.hooks.cloud_run.JobsClient") + def test_delete_job(self, mock_batch_service_client, cloud_run_hook): + job_name = "job1" + region = "region1" + project_id = "projectid" + + delete_request = DeleteJobRequest(name=f"projects/{project_id}/locations/{region}/jobs/{job_name}") + + cloud_run_hook.delete_job(job_name=job_name, region=region, project_id=project_id) + cloud_run_hook._client.delete_job.assert_called_once_with(delete_request) + def _mock_pager(self, number_of_jobs): mock_pager = [] for i in range(number_of_jobs):