Repository: getmoto/moto
Pull request #5896 (2023-02-01 22:43:49)

[Glue] Implement batch_get_crawlers
Hello,
while working with moto I got `NotImplementedError: The batch_get_crawlers action has not been implemented`, so I decided to implement the missing method 😉 
If you have any suggestions how to improve my code - please let me know!


codecov[bot]: # [Codecov](https://codecov.io/gh/getmoto/moto/pull/5896?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report
> Merging [#5896](https://codecov.io/gh/getmoto/moto/pull/5896?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (c83d7c1) into [master](https://codecov.io/gh/getmoto/moto/commit/75059fd4cf4894bb5c8b1e59e352753dd7d150a6?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (75059fd) will **increase** coverage by `0.00%`.
> The diff coverage is `100.00%`.

```diff
@@           Coverage Diff           @@
##           master    #5896   +/-   ##
=======================================
  Coverage   96.21%   96.21%           
=======================================
  Files         759      759           
  Lines       74768    74779   +11     
=======================================
+ Hits        71937    71951   +14     
+ Misses       2831     2828    -3     
```

| Flag | Coverage Δ | |
|---|---|---|
| servertests | `36.93% <9.09%> (-0.01%)` | :arrow_down: |
| unittests | `96.15% <100.00%> (+<0.01%)` | :arrow_up: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/getmoto/moto/pull/5896?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | Coverage Δ | |
|---|---|---|
| [moto/glue/models.py](https://codecov.io/gh/getmoto/moto/pull/5896?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-bW90by9nbHVlL21vZGVscy5weQ==) | `97.13% <100.00%> (+0.03%)` | :arrow_up: |
| [moto/glue/responses.py](https://codecov.io/gh/getmoto/moto/pull/5896?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-bW90by9nbHVlL3Jlc3BvbnNlcy5weQ==) | `99.68% <100.00%> (+<0.01%)` | :arrow_up: |
| [moto/batch/models.py](https://codecov.io/gh/getmoto/moto/pull/5896?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-bW90by9iYXRjaC9tb2RlbHMucHk=) | `91.61% <0.00%> (+0.35%)` | :arrow_up: |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None)


Patch:
diff --git a/moto/glue/models.py b/moto/glue/models.py
index 26cfbbc0e..6b27c85df 100644
--- a/moto/glue/models.py
+++ b/moto/glue/models.py
@@ -738,6 +738,13 @@ class GlueBackend(BaseBackend):
                 )
         return errors_output
 
+    def batch_get_crawlers(self, crawler_names):
+        crawlers = []
+        for crawler in self.get_crawlers():
+            if crawler.as_dict()["Name"] in crawler_names:
+                crawlers.append(crawler.as_dict())
+        return crawlers
+
 
 class FakeDatabase(BaseModel):
     def __init__(self, database_name, database_input):
diff --git a/moto/glue/responses.py b/moto/glue/responses.py
index 486e0bee7..361848a3b 100644
--- a/moto/glue/responses.py
+++ b/moto/glue/responses.py
@@ -498,3 +498,16 @@ class GlueResponse(BaseResponse):
         description = self._get_param("Description")
         schema = self.glue_backend.update_schema(schema_id, compatibility, description)
         return json.dumps(schema)
+
+    def batch_get_crawlers(self):
+        crawler_names = self._get_param("CrawlerNames")
+        crawlers = self.glue_backend.batch_get_crawlers(crawler_names)
+        crawlers_not_found = list(
+            set(crawler_names) - set(map(lambda crawler: crawler["Name"], crawlers))
+        )
+        return json.dumps(
+            {
+                "Crawlers": crawlers,
+                "CrawlersNotFound": crawlers_not_found,
+            }
+        )


Test patch:
diff --git a/tests/test_glue/test_glue.py b/tests/test_glue/test_glue.py
index 5e3fcbfce..507b7affc 100644
--- a/tests/test_glue/test_glue.py
+++ b/tests/test_glue/test_glue.py
@@ -401,3 +401,16 @@ def test_untag_glue_crawler():
     resp = client.get_tags(ResourceArn=resource_arn)
 
     resp.should.have.key("Tags").equals({"key1": "value1", "key3": "value3"})
+
+
+@mock_glue
+def test_batch_get_crawlers():
+    client = create_glue_client()
+    crawler_name = create_test_crawler(client)
+
+    response = client.batch_get_crawlers(
+        CrawlerNames=[crawler_name, "crawler-not-found"]
+    )
+
+    response["Crawlers"].should.have.length_of(1)
+    response["CrawlersNotFound"].should.have.length_of(1)