Add get_databases method to glue moto client. Update IMPLEMENTATION_COVERAGE.md with methods that were covered previously

This commit is contained in:
MarcosBernal 2020-04-21 20:10:39 +02:00
parent 12ac1cbae2
commit 753a39ed0d
4 changed files with 37 additions and 9 deletions

View File

@ -3351,11 +3351,11 @@
- [ ] update_listener - [ ] update_listener
## glue ## glue
4% implemented 14/123 = 11% implemented
- [ ] batch_create_partition - [X] batch_create_partition
- [ ] batch_delete_connection - [ ] batch_delete_connection
- [ ] batch_delete_partition - [X] batch_delete_partition
- [ ] batch_delete_table - [X] batch_delete_table
- [ ] batch_delete_table_version - [ ] batch_delete_table_version
- [ ] batch_get_crawlers - [ ] batch_get_crawlers
- [ ] batch_get_dev_endpoints - [ ] batch_get_dev_endpoints
@ -3372,7 +3372,7 @@
- [ ] create_dev_endpoint - [ ] create_dev_endpoint
- [ ] create_job - [ ] create_job
- [ ] create_ml_transform - [ ] create_ml_transform
- [ ] create_partition - [X] create_partition
- [ ] create_script - [ ] create_script
- [ ] create_security_configuration - [ ] create_security_configuration
- [X] create_table - [X] create_table
@ -3404,7 +3404,7 @@
- [ ] get_crawlers - [ ] get_crawlers
- [ ] get_data_catalog_encryption_settings - [ ] get_data_catalog_encryption_settings
- [X] get_database - [X] get_database
- [ ] get_databases - [X] get_databases
- [ ] get_dataflow_graph - [ ] get_dataflow_graph
- [ ] get_dev_endpoint - [ ] get_dev_endpoint
- [ ] get_dev_endpoints - [ ] get_dev_endpoints
@ -3418,7 +3418,7 @@
- [ ] get_ml_task_runs - [ ] get_ml_task_runs
- [ ] get_ml_transform - [ ] get_ml_transform
- [ ] get_ml_transforms - [ ] get_ml_transforms
- [ ] get_partition - [X] get_partition
- [ ] get_partitions - [ ] get_partitions
- [ ] get_plan - [ ] get_plan
- [ ] get_resource_policy - [ ] get_resource_policy
@ -3470,8 +3470,8 @@
- [ ] update_dev_endpoint - [ ] update_dev_endpoint
- [ ] update_job - [ ] update_job
- [ ] update_ml_transform - [ ] update_ml_transform
- [ ] update_partition - [X] update_partition
- [ ] update_table - [X] update_table
- [ ] update_trigger - [ ] update_trigger
- [ ] update_user_defined_function - [ ] update_user_defined_function
- [ ] update_workflow - [ ] update_workflow

View File

@ -34,6 +34,9 @@ class GlueBackend(BaseBackend):
except KeyError: except KeyError:
raise DatabaseNotFoundException(database_name) raise DatabaseNotFoundException(database_name)
def get_databases(self):
return [self.databases[key] for key in self.databases] if self.databases else []
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

@ -30,6 +30,10 @@ class GlueResponse(BaseResponse):
database = self.glue_backend.get_database(database_name) database = self.glue_backend.get_database(database_name)
return json.dumps({"Database": {"Name": database.name}}) return json.dumps({"Database": {"Name": database.name}})
def get_databases(self):
database_list = self.glue_backend.get_databases()
return json.dumps({"DatabaseList": [{"Name": database.name} for database in database_list]})
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

@ -52,6 +52,27 @@ def test_get_database_not_exits():
) )
@mock_glue
def test_get_databases_empty():
client = boto3.client("glue", region_name="us-east-1")
response = client.get_databases()
response["DatabaseList"].should.have.length_of(0)
@mock_glue
def test_get_databases_several_items():
client = boto3.client("glue", region_name="us-east-1")
database_name_1, database_name_2 = "firstdatabase", "seconddatabase"
helpers.create_database(client, database_name_1)
helpers.create_database(client, database_name_2)
database_list = sorted(client.get_databases()["DatabaseList"], key=lambda x: x["Name"])
database_list.should.have.length_of(2)
database_list[0].should.equal({"Name": database_name_1})
database_list[1].should.equal({"Name": database_name_2})
@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")