SES: Implement DescribeConfigurationSet (#5378)

This commit is contained in:
Viren Nadkarni 2022-08-12 22:03:35 +05:30 committed by GitHub
parent c40c6895ce
commit f91ffcffb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 59 additions and 0 deletions

View File

@ -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

View File

@ -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
):

View File

@ -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 = """<CreateConfigurationSetResponse xmlns="http://ses.
</ResponseMetadata>
</CreateConfigurationSetResponse>"""
DESCRIBE_CONFIGURATION_SET = """<DescribeConfigurationSetResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
<DescribeConfigurationSetResult>
<ConfigurationSet>
<Name>{{ name }}</Name>
</ConfigurationSet>
</DescribeConfigurationSetResult>
<ResponseMetadata>
<RequestId>8e410745-c1bd-4450-82e0-f968cf2105f2</RequestId>
</ResponseMetadata>
</DescribeConfigurationSetResponse>"""
CREATE_CONFIGURATION_SET_EVENT_DESTINATION = """<CreateConfigurationSetEventDestinationResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
<CreateConfigurationSetEventDestinationResult/>
<ResponseMetadata>

View File

@ -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")