diff --git a/moto/ses/exceptions.py b/moto/ses/exceptions.py index 1b539f4ea..4c1e489cd 100644 --- a/moto/ses/exceptions.py +++ b/moto/ses/exceptions.py @@ -15,6 +15,13 @@ class ConfigurationSetDoesNotExist(RESTError): super().__init__("ConfigurationSetDoesNotExist", message) +class ConfigurationSetAlreadyExists(RESTError): + code = 400 + + def __init__(self, message): + super().__init__("ConfigurationSetAlreadyExists", message) + + class EventDestinationAlreadyExists(RESTError): code = 400 diff --git a/moto/ses/models.py b/moto/ses/models.py index 52cbfe9ec..532bf3b5a 100644 --- a/moto/ses/models.py +++ b/moto/ses/models.py @@ -25,6 +25,7 @@ from .exceptions import ( RuleSetDoesNotExist, RuleAlreadyExists, MissingRenderingAttributeException, + ConfigurationSetAlreadyExists, ) from .utils import get_random_message_id, is_valid_address from .feedback import COMMON_MAIL, BOUNCE, COMPLAINT, DELIVERY @@ -358,9 +359,20 @@ class SESBackend(BaseBackend): return {} def create_configuration_set(self, configuration_set_name): + if configuration_set_name in self.config_set: + raise ConfigurationSetAlreadyExists( + f"Configuration set <{configuration_set_name}> already exists" + ) self.config_set[configuration_set_name] = 1 return {} + def get_configuration_set(self, configuration_set_name): + if configuration_set_name not in self.config_set: + raise ConfigurationSetDoesNotExist( + f"Configuration set <{configuration_set_name}> does not exist" + ) + return {} + def create_configuration_set_event_destination( self, configuration_set_name, event_destination ): diff --git a/moto/ses/responses.py b/moto/ses/responses.py index e2cf56742..d4c16f0e7 100644 --- a/moto/ses/responses.py +++ b/moto/ses/responses.py @@ -194,6 +194,12 @@ class EmailResponse(BaseResponse): template = self.response_template(CREATE_CONFIGURATION_SET) return template.render() + def describe_configuration_set(self): + configuration_set_name = self.querystring.get("ConfigurationSetName")[0] + self.backend.get_configuration_set(configuration_set_name) + template = self.response_template(DESCRIBE_CONFIGURATION_SET) + return template.render(name=configuration_set_name) + def create_configuration_set_event_destination(self): configuration_set_name = self._get_param("ConfigurationSetName") @@ -533,6 +539,17 @@ CREATE_CONFIGURATION_SET = """ + + + {{ name }} + + + + 8e410745-c1bd-4450-82e0-f968cf2105f2 + +""" + CREATE_CONFIGURATION_SET_EVENT_DESTINATION = """ diff --git a/tests/test_ses/test_ses_boto3.py b/tests/test_ses/test_ses_boto3.py index 2db46c7a6..4994d643a 100644 --- a/tests/test_ses/test_ses_boto3.py +++ b/tests/test_ses/test_ses_boto3.py @@ -502,6 +502,10 @@ def test_create_configuration_set(): conn = boto3.client("ses", region_name="us-east-1") conn.create_configuration_set(ConfigurationSet=dict({"Name": "test"})) + with pytest.raises(ClientError) as ex: + conn.create_configuration_set(ConfigurationSet=dict({"Name": "test"})) + ex.value.response["Error"]["Code"].should.equal("ConfigurationSetAlreadyExists") + conn.create_configuration_set_event_destination( ConfigurationSetName="test", EventDestination={ @@ -545,6 +549,25 @@ def test_create_configuration_set(): ex.value.response["Error"]["Code"].should.equal("EventDestinationAlreadyExists") +@mock_ses +def test_describe_configuration_set(): + conn = boto3.client("ses", region_name="us-east-1") + + name = "test" + conn.create_configuration_set(ConfigurationSet=dict({"Name": name})) + + with pytest.raises(ClientError) as ex: + conn.describe_configuration_set( + ConfigurationSetName="failtest", + ) + ex.value.response["Error"]["Code"].should.equal("ConfigurationSetDoesNotExist") + + config_set = conn.describe_configuration_set( + ConfigurationSetName=name, + ) + config_set["ConfigurationSet"]["Name"].should.equal(name) + + @mock_ses def test_create_receipt_rule_set(): conn = boto3.client("ses", region_name="us-east-1")