RDS - Fix KeyError on describe_db_clusters for non-existent cluster (#5321)

This commit is contained in:
Lukasz Demolin 2022-07-26 21:19:10 +02:00 committed by GitHub
parent 004c971a27
commit 42b11bbe14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -1801,6 +1801,8 @@ class RDSBackend(BaseBackend):
def describe_db_clusters(self, cluster_identifier):
if cluster_identifier:
if cluster_identifier not in self.clusters:
raise DBClusterNotFoundError(cluster_identifier)
return [self.clusters[cluster_identifier]]
return self.clusters.values()

View File

@ -15,6 +15,19 @@ def test_describe_db_cluster_initial():
resp.should.have.key("DBClusters").should.have.length_of(0)
@mock_rds
def test_describe_db_cluster_fails_for_non_existent_cluster():
client = boto3.client("rds", region_name="eu-north-1")
resp = client.describe_db_clusters()
resp.should.have.key("DBClusters").should.have.length_of(0)
with pytest.raises(ClientError) as ex:
client.describe_db_clusters(DBClusterIdentifier="cluster-id")
err = ex.value.response["Error"]
err["Code"].should.equal("DBClusterNotFoundFault")
err["Message"].should.equal("DBCluster cluster-id not found.")
@mock_rds
def test_create_db_cluster_needs_master_username():
client = boto3.client("rds", region_name="eu-north-1")