From c6b048695befa0e4530140dbc934283d7f8eaf29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20D=C4=85bek?= <373530+szemek@users.noreply.github.com> Date: Fri, 21 Apr 2023 14:12:16 +0200 Subject: [PATCH] [Glue] Implement batch_get_jobs (#6241) --- moto/glue/models.py | 7 +++++++ moto/glue/responses.py | 11 +++++++++++ tests/test_glue/test_glue.py | 11 +++++++++++ 3 files changed, 29 insertions(+) diff --git a/moto/glue/models.py b/moto/glue/models.py index fb4508c68438..d8be8286b544 100644 --- a/moto/glue/models.py +++ b/moto/glue/models.py @@ -863,6 +863,13 @@ def batch_get_crawlers(self, crawler_names: List[str]) -> List[Dict[str, Any]]: crawlers.append(crawler.as_dict()) return crawlers + def batch_get_jobs(self, job_names: List[str]) -> List[Dict[str, Any]]: + jobs = [] + for job_name in job_names: + if job_name in self.jobs: + jobs.append(self.jobs[job_name].as_dict()) + return jobs + class FakeDatabase(BaseModel): def __init__(self, database_name: str, database_input: Dict[str, Any]): diff --git a/moto/glue/responses.py b/moto/glue/responses.py index 5b7eee45b88b..7b4e7c951785 100644 --- a/moto/glue/responses.py +++ b/moto/glue/responses.py @@ -524,5 +524,16 @@ def batch_get_crawlers(self) -> str: } ) + def batch_get_jobs(self) -> str: + job_names = self._get_param("JobNames") + jobs = self.glue_backend.batch_get_jobs(job_names) + jobs_not_found = list(set(job_names) - set(map(lambda job: job["Name"], jobs))) + return json.dumps( + { + "Jobs": jobs, + "JobsNotFound": jobs_not_found, + } + ) + def get_partition_indexes(self) -> str: return json.dumps({"PartitionIndexDescriptorList": []}) diff --git a/tests/test_glue/test_glue.py b/tests/test_glue/test_glue.py index 03d7a54e8d37..83ed0a97db5c 100644 --- a/tests/test_glue/test_glue.py +++ b/tests/test_glue/test_glue.py @@ -233,6 +233,17 @@ def test_list_jobs_next_token_logic_does_not_create_infinite_loop(): assert not next_token +@mock_glue +def test_batch_get_jobs(): + client = create_glue_client() + job_name = create_test_job(client) + + response = client.batch_get_jobs(JobNames=[job_name, "job-not-found"]) + + assert len(response["Jobs"]) == 1 + assert len(response["JobsNotFound"]) == 1 + + def create_glue_client(): return boto3.client("glue", region_name="us-east-1")