Glue - delete_database() (#4631)

This commit is contained in:
Bert Blommers 2021-11-24 12:21:45 -01:00 committed by GitHub
parent 5fa932c3cb
commit 71f831dae6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 0 deletions

View File

@ -58,6 +58,11 @@ class GlueBackend(BaseBackend):
def get_databases(self): def get_databases(self):
return [self.databases[key] for key in self.databases] if self.databases else [] 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): def create_table(self, database_name, table_name, table_input):
database = self.get_database(database_name) database = self.get_database(database_name)

View File

@ -35,6 +35,11 @@ class GlueResponse(BaseResponse):
{"DatabaseList": [database.as_dict() for database in database_list]} {"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): def create_table(self):
database_name = self.parameters.get("DatabaseName") database_name = self.parameters.get("DatabaseName")
table_input = self.parameters.get("TableInput") table_input = self.parameters.get("TableInput")

View File

@ -90,6 +90,33 @@ def test_get_databases_several_items():
database_list[1]["Name"].should.equal(database_name_2) 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 @mock_glue
def test_create_table(): def test_create_table():
client = boto3.client("glue", region_name="us-east-1") client = boto3.client("glue", region_name="us-east-1")