diff --git a/IMPLEMENTATION_COVERAGE.md b/IMPLEMENTATION_COVERAGE.md index e19c4f95a..8ba12654b 100644 --- a/IMPLEMENTATION_COVERAGE.md +++ b/IMPLEMENTATION_COVERAGE.md @@ -2814,7 +2814,7 @@ ## glue
-16% implemented +17% implemented - [ ] 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 diff --git a/docs/docs/services/glue.rst b/docs/docs/services/glue.rst index d8c76eb34..a2c7ae521 100644 --- a/docs/docs/services/glue.rst +++ b/docs/docs/services/glue.rst @@ -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 diff --git a/moto/glue/models.py b/moto/glue/models.py index 30559565e..ccf9691a4 100644 --- a/moto/glue/models.py +++ b/moto/glue/models.py @@ -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 [] diff --git a/moto/glue/responses.py b/moto/glue/responses.py index 3fa5e8f66..81bb7ca15 100644 --- a/moto/glue/responses.py +++ b/moto/glue/responses.py @@ -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) diff --git a/tests/test_glue/test_datacatalog.py b/tests/test_glue/test_datacatalog.py index 0be66d903..4f32af14c 100644 --- a/tests/test_glue/test_datacatalog.py +++ b/tests/test_glue/test_datacatalog.py @@ -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")