From ae2865d55968299130358d5b422b1869110fbff6 Mon Sep 17 00:00:00 2001 From: Brian Pandola Date: Sat, 13 Feb 2021 03:12:02 -0800 Subject: [PATCH] Minor RDS Clean up (#3682) * Fix `DBInstanceNotFound` error message Changed from `Database` to `DBInstance`, which is actually what comes back from AWS. * Remove duplicate test The removed test actually fails if run in isolation because `rds2` is not a valid boto3 client service. The reason this test never caused CI to fail is because it is redefined later in the test suite, effectively making it dead code that will never run. Duplicate test has been removed and the remaining test has been improved with more explicit asserts. --- moto/rds2/exceptions.py | 3 ++- tests/test_rds2/test_filters.py | 4 ++-- tests/test_rds2/test_rds2.py | 18 +++++++----------- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/moto/rds2/exceptions.py b/moto/rds2/exceptions.py index 0232f11c7..8866b9bfd 100644 --- a/moto/rds2/exceptions.py +++ b/moto/rds2/exceptions.py @@ -24,7 +24,8 @@ class RDSClientError(BadRequest): class DBInstanceNotFoundError(RDSClientError): def __init__(self, database_identifier): super(DBInstanceNotFoundError, self).__init__( - "DBInstanceNotFound", "Database {0} not found.".format(database_identifier) + "DBInstanceNotFound", + "DBInstance {0} not found.".format(database_identifier), ) diff --git a/tests/test_rds2/test_filters.py b/tests/test_rds2/test_filters.py index a59867d24..5f6668219 100644 --- a/tests/test_rds2/test_filters.py +++ b/tests/test_rds2/test_filters.py @@ -127,7 +127,7 @@ class TestDBInstanceFilters(object): ) ex.value.response["Error"]["Code"].should.equal("DBInstanceNotFound") ex.value.response["Error"]["Message"].should.equal( - "Database non-existent not found." + "DBInstance non-existent not found." ) def test_valid_db_instance_identifier_with_exclusive_filter(self): @@ -172,7 +172,7 @@ class TestDBInstanceFilters(object): ) ex.value.response["Error"]["Code"].should.equal("DBInstanceNotFound") ex.value.response["Error"]["Message"].should.equal( - "Database db-instance-0 not found." + "DBInstance db-instance-0 not found." ) diff --git a/tests/test_rds2/test_rds2.py b/tests/test_rds2/test_rds2.py index 524589c80..393a46163 100644 --- a/tests/test_rds2/test_rds2.py +++ b/tests/test_rds2/test_rds2.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals from botocore.exceptions import ClientError import boto3 +import pytest import sure # noqa from moto import mock_ec2, mock_kms, mock_rds2 from moto.core import ACCOUNT_ID @@ -471,14 +472,6 @@ def test_delete_database(): snapshots[0].get("Engine").should.equal("postgres") -@mock_rds2 -def test_delete_non_existent_database(): - conn = boto3.client("rds2", region_name="us-west-2") - conn.delete_db_instance.when.called_with( - DBInstanceIdentifier="not-a-db" - ).should.throw(ClientError) - - @mock_rds2 def test_create_db_snapshots(): conn = boto3.client("rds", region_name="us-west-2") @@ -793,9 +786,12 @@ def test_modify_non_existent_option_group(): @mock_rds2 def test_delete_non_existent_database(): conn = boto3.client("rds", region_name="us-west-2") - conn.delete_db_instance.when.called_with( - DBInstanceIdentifier="not-a-db" - ).should.throw(ClientError) + with pytest.raises(ClientError) as ex: + conn.delete_db_instance(DBInstanceIdentifier="non-existent") + ex.value.response["Error"]["Code"].should.equal("DBInstanceNotFound") + ex.value.response["Error"]["Message"].should.equal( + "DBInstance non-existent not found." + ) @mock_rds2