diff --git a/moto/glue/models.py b/moto/glue/models.py index 16f24797c..2ca2a3315 100644 --- a/moto/glue/models.py +++ b/moto/glue/models.py @@ -58,6 +58,11 @@ class GlueBackend(BaseBackend): def get_databases(self): return [self.databases[key] for key in self.databases] if self.databases else [] + def delete_database(self, database_name): + if database_name not in self.databases: + raise DatabaseNotFoundException(database_name) + del self.databases[database_name] + def create_table(self, database_name, table_name, table_input): database = self.get_database(database_name) diff --git a/moto/glue/responses.py b/moto/glue/responses.py index b27e40778..6ae20f85e 100644 --- a/moto/glue/responses.py +++ b/moto/glue/responses.py @@ -35,6 +35,11 @@ class GlueResponse(BaseResponse): {"DatabaseList": [database.as_dict() for database in database_list]} ) + def delete_database(self): + name = self.parameters.get("Name") + self.glue_backend.delete_database(name) + return json.dumps({}) + def create_table(self): database_name = self.parameters.get("DatabaseName") table_input = self.parameters.get("TableInput") diff --git a/tests/test_glue/test_datacatalog.py b/tests/test_glue/test_datacatalog.py index 64628e1a5..189afd74e 100644 --- a/tests/test_glue/test_datacatalog.py +++ b/tests/test_glue/test_datacatalog.py @@ -90,6 +90,33 @@ def test_get_databases_several_items(): database_list[1]["Name"].should.equal(database_name_2) +@mock_glue +def test_delete_database(): + client = boto3.client("glue", region_name="us-east-1") + database_name_1, database_name_2 = "firstdatabase", "seconddatabase" + + helpers.create_database(client, database_name_1, {"Name": database_name_1}) + helpers.create_database(client, database_name_2, {"Name": database_name_2}) + + client.delete_database(Name=database_name_1) + + database_list = sorted( + client.get_databases()["DatabaseList"], key=lambda x: x["Name"] + ) + [db["Name"] for db in database_list].should.equal([database_name_2]) + + +@mock_glue +def test_delete_unknown_database(): + client = boto3.client("glue", region_name="us-east-1") + + with pytest.raises(ClientError) as exc: + client.delete_database(Name="x") + err = exc.value.response["Error"] + err["Code"].should.equal("EntityNotFoundException") + err["Message"].should.equal("Database x not found.") + + @mock_glue def test_create_table(): client = boto3.client("glue", region_name="us-east-1")