Glue: UpdateDatabase (#5407)

This commit is contained in:
Robert Schmidtke 2022-08-24 11:24:05 +02:00 committed by GitHub
parent 37fa5f8bf4
commit 6abecdf856
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 59 additions and 3 deletions

View File

@ -2814,7 +2814,7 @@
## glue
<details>
<summary>16% implemented</summary>
<summary>17% implemented</summary>
- [ ] batch_create_partition
- [ ] batch_delete_connection
@ -2989,7 +2989,7 @@
- [ ] update_connection
- [ ] update_crawler
- [ ] update_crawler_schedule
- [ ] update_database
- [X] update_database
- [ ] update_dev_endpoint
- [ ] update_job
- [ ] update_ml_transform

View File

@ -215,7 +215,7 @@ glue
- [ ] update_connection
- [ ] update_crawler
- [ ] update_crawler_schedule
- [ ] update_database
- [X] update_database
- [ ] update_dev_endpoint
- [ ] update_job
- [ ] update_ml_transform

View File

@ -99,6 +99,12 @@ class GlueBackend(BaseBackend):
except KeyError:
raise DatabaseNotFoundException(database_name)
def update_database(self, database_name, database_input):
if database_name not in self.databases:
raise DatabaseNotFoundException(database_name)
self.databases[database_name].input = database_input
def get_databases(self):
return [self.databases[key] for key in self.databases] if self.databases else []

View File

@ -40,6 +40,14 @@ class GlueResponse(BaseResponse):
{"DatabaseList": [database.as_dict() for database in database_list]}
)
def update_database(self):
database_input = self.parameters.get("DatabaseInput")
database_name = self.parameters.get("Name")
if "CatalogId" in self.parameters:
database_input["CatalogId"] = self.parameters.get("CatalogId")
self.glue_backend.update_database(database_name, database_input)
return ""
def delete_database(self):
name = self.parameters.get("Name")
self.glue_backend.delete_database(name)

View File

@ -92,6 +92,48 @@ def test_get_databases_several_items():
database_list[1]["Name"].should.equal(database_name_2)
@mock_glue
def test_update_database():
client = boto3.client("glue", region_name="us-east-1")
database_name = "existingdatabase"
database_catalog_id = ACCOUNT_ID
helpers.create_database(
client, database_name, {"Name": database_name}, database_catalog_id
)
response = helpers.get_database(client, database_name)
database = response["Database"]
database.get("CatalogId").should.equal(database_catalog_id)
database.get("Description").should.be.none
database.get("LocationUri").should.be.none
database_input = {
"Name": database_name,
"Description": "desc",
"LocationUri": "s3://bucket/existingdatabase/",
}
client.update_database(
CatalogId=database_catalog_id, Name=database_name, DatabaseInput=database_input
)
response = helpers.get_database(client, database_name)
database = response["Database"]
database.get("CatalogId").should.equal(database_catalog_id)
database.get("Description").should.equal("desc")
database.get("LocationUri").should.equal("s3://bucket/existingdatabase/")
@mock_glue
def test_update_unknown_database():
client = boto3.client("glue", region_name="us-east-1")
with pytest.raises(ClientError) as exc:
client.update_database(Name="x", DatabaseInput={"Name": "x"})
err = exc.value.response["Error"]
err["Code"].should.equal("EntityNotFoundException")
err["Message"].should.equal("Database x not found.")
@mock_glue
def test_delete_database():
client = boto3.client("glue", region_name="us-east-1")