feat: add describe_receipt_rule method to ses mock (#4458)

This commit is contained in:
Sherman Hui 2021-10-24 12:35:54 -07:00 committed by GitHub
parent fee16cb388
commit 1d21cec000
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 209 additions and 28 deletions

View File

@ -590,7 +590,7 @@
## cognito-idp
<details>
<summary>49% implemented</summary>
<summary>50% implemented</summary>
- [ ] add_custom_attributes
- [X] admin_add_user_to_group
@ -688,7 +688,7 @@
- [X] update_identity_provider
- [ ] update_resource_server
- [ ] update_user_attributes
- [ ] update_user_pool
- [X] update_user_pool
- [X] update_user_pool_client
- [X] update_user_pool_domain
- [X] verify_software_token
@ -1340,8 +1340,6 @@
- [ ] get_transit_gateway_prefix_list_references
- [ ] get_transit_gateway_route_table_associations
- [ ] get_transit_gateway_route_table_propagations
- [ ] get_vpn_connection_device_sample_configuration
- [ ] get_vpn_connection_device_types
- [ ] import_client_vpn_client_certificate_revocation_list
- [ ] import_image
- [ ] import_instance
@ -1463,7 +1461,7 @@
## ecr
<details>
<summary>74% implemented</summary>
<summary>76% implemented</summary>
- [ ] batch_check_layer_availability
- [X] batch_delete_image
@ -1474,7 +1472,6 @@
- [X] delete_registry_policy
- [X] delete_repository
- [X] delete_repository_policy
- [ ] describe_image_replication_status
- [X] describe_image_scan_findings
- [X] describe_images
- [X] describe_registry
@ -1504,13 +1501,13 @@
## ecs
<details>
<summary>67% implemented</summary>
<summary>73% implemented</summary>
- [ ] create_capacity_provider
- [X] create_cluster
- [X] create_service
- [X] create_task_set
- [ ] delete_account_setting
- [X] delete_account_setting
- [X] delete_attributes
- [ ] delete_capacity_provider
- [X] delete_cluster
@ -1527,7 +1524,7 @@
- [X] describe_tasks
- [ ] discover_poll_endpoint
- [ ] execute_command
- [ ] list_account_settings
- [X] list_account_settings
- [X] list_attributes
- [X] list_clusters
- [X] list_container_instances
@ -1536,7 +1533,7 @@
- [X] list_task_definition_families
- [X] list_task_definitions
- [X] list_tasks
- [ ] put_account_setting
- [X] put_account_setting
- [ ] put_account_setting_default
- [X] put_attributes
- [ ] put_cluster_capacity_providers
@ -1595,7 +1592,7 @@
## eks
<details>
<summary>35% implemented</summary>
<summary>37% implemented</summary>
- [ ] associate_encryption_config
- [ ] associate_identity_provider_config
@ -1607,7 +1604,6 @@
- [X] delete_cluster
- [X] delete_fargate_profile
- [X] delete_nodegroup
- [ ] deregister_cluster
- [ ] describe_addon
- [ ] describe_addon_versions
- [X] describe_cluster
@ -1623,7 +1619,6 @@
- [X] list_nodegroups
- [ ] list_tags_for_resource
- [ ] list_updates
- [ ] register_cluster
- [ ] tag_resource
- [ ] untag_resource
- [ ] update_addon
@ -2521,7 +2516,6 @@
- [X] list_topic_rules
- [ ] list_v2_logging_levels
- [ ] list_violation_events
- [ ] put_verification_state_on_violation
- [ ] register_ca_certificate
- [X] register_certificate
- [X] register_certificate_without_ca
@ -3711,7 +3705,6 @@
- [ ] create_presigned_notebook_instance_url
- [ ] create_processing_job
- [ ] create_project
- [ ] create_studio_lifecycle_config
- [X] create_training_job
- [ ] create_transform_job
- [ ] create_trial
@ -3750,7 +3743,6 @@
- [X] delete_notebook_instance_lifecycle_config
- [ ] delete_pipeline
- [ ] delete_project
- [ ] delete_studio_lifecycle_config
- [ ] delete_tags
- [ ] delete_trial
- [ ] delete_trial_component
@ -3796,7 +3788,6 @@
- [ ] describe_pipeline_execution
- [ ] describe_processing_job
- [ ] describe_project
- [ ] describe_studio_lifecycle_config
- [ ] describe_subscribed_workteam
- [X] describe_training_job
- [ ] describe_transform_job
@ -3855,7 +3846,6 @@
- [ ] list_pipelines
- [ ] list_processing_jobs
- [ ] list_projects
- [ ] list_studio_lifecycle_configs
- [ ] list_subscribed_workteams
- [ ] list_tags
- [X] list_training_jobs
@ -3869,7 +3859,6 @@
- [ ] put_model_package_group_policy
- [ ] register_devices
- [ ] render_ui_template
- [ ] retry_pipeline_execution
- [ ] search
- [ ] send_pipeline_execution_step_failure
- [ ] send_pipeline_execution_step_success
@ -3943,7 +3932,7 @@
## ses
<details>
<summary>25% implemented</summary>
<summary>29% implemented</summary>
- [ ] clone_receipt_rule_set
- [X] create_configuration_set
@ -3967,13 +3956,13 @@
- [ ] delete_verified_email_address
- [ ] describe_active_receipt_rule_set
- [ ] describe_configuration_set
- [ ] describe_receipt_rule
- [X] describe_receipt_rule
- [ ] describe_receipt_rule_set
- [ ] get_account_sending_enabled
- [ ] get_custom_verification_email_template
- [ ] get_identity_dkim_attributes
- [ ] get_identity_mail_from_domain_attributes
- [ ] get_identity_notification_attributes
- [X] get_identity_notification_attributes
- [ ] get_identity_policies
- [ ] get_identity_verification_attributes
- [X] get_send_quota
@ -3998,7 +3987,7 @@
- [X] send_templated_email
- [ ] set_active_receipt_rule_set
- [ ] set_identity_dkim_enabled
- [ ] set_identity_feedback_forwarding_enabled
- [X] set_identity_feedback_forwarding_enabled
- [ ] set_identity_headers_in_notifications_enabled
- [ ] set_identity_mail_from_domain
- [X] set_identity_notification_topic
@ -4336,6 +4325,27 @@
- [ ] untag_resource
</details>
## timestream-write
<details>
<summary>80% implemented</summary>
- [X] create_database
- [X] create_table
- [X] delete_database
- [X] delete_table
- [X] describe_database
- [X] describe_endpoints
- [X] describe_table
- [X] list_databases
- [X] list_tables
- [ ] list_tags_for_resource
- [ ] tag_resource
- [ ] untag_resource
- [X] update_database
- [X] update_table
- [X] write_records
</details>
## transcribe
<details>
<summary>41% implemented</summary>
@ -4536,7 +4546,6 @@
- iotwireless
- ivs
- kafka
- kafkaconnect
- kendra
- kinesis-video-media
- kinesis-video-signaling
@ -4575,7 +4584,6 @@
- network-firewall
- networkmanager
- nimble
- opensearch
- opsworkscm
- outposts
- personalize
@ -4630,7 +4638,6 @@
- synthetics
- textract
- timestream-query
- timestream-write
- transfer
- translate
- waf

View File

@ -88,6 +88,13 @@ class RuleSetDoesNotExist(RESTError):
super(RuleSetDoesNotExist, self).__init__("RuleSetDoesNotExist", message)
class RuleDoesNotExist(RESTError):
code = 400
def __init__(self, message):
super(RuleDoesNotExist, self).__init__("RuleDoesNotExist", message)
class MissingRenderingAttributeException(RESTError):
code = 400

View File

@ -18,6 +18,7 @@ from .exceptions import (
InvalidParameterValue,
InvalidRenderingParameterException,
TemplateDoesNotExist,
RuleDoesNotExist,
RuleSetNameAlreadyExists,
RuleSetDoesNotExist,
RuleAlreadyExists,
@ -413,7 +414,7 @@ class SESBackend(BaseBackend):
def create_receipt_rule_set(self, rule_set_name):
if self.receipt_rule_set.get(rule_set_name) is not None:
raise RuleSetNameAlreadyExists("Duplicate receipt rule set Name.")
raise RuleSetNameAlreadyExists("Duplicate Receipt Rule Set Name.")
self.receipt_rule_set[rule_set_name] = []
def create_receipt_rule(self, rule_set_name, rule):
@ -425,5 +426,17 @@ class SESBackend(BaseBackend):
rule_set.append(rule)
self.receipt_rule_set[rule_set_name] = rule_set
def describe_receipt_rule(self, rule_set_name, rule_name):
rule_set = self.receipt_rule_set.get(rule_set_name)
if rule_set is None:
raise RuleSetDoesNotExist("Invalid Rule Set Name.")
for receipt_rule in rule_set:
if receipt_rule["name"] == rule_name:
return receipt_rule
else:
raise RuleDoesNotExist("Invalid Rule Name.")
ses_backend = SESBackend()

View File

@ -234,11 +234,25 @@ class EmailResponse(BaseResponse):
def create_receipt_rule(self):
rule_set_name = self._get_param("RuleSetName")
rule = self._get_dict_param("Rule")
rule = self._get_dict_param("Rule.")
ses_backend.create_receipt_rule(rule_set_name, rule)
template = self.response_template(CREATE_RECEIPT_RULE)
return template.render()
def describe_receipt_rule(self):
rule_set_name = self._get_param("RuleSetName")
rule_name = self._get_param("RuleName")
receipt_rule = ses_backend.describe_receipt_rule(rule_set_name, rule_name)
rule = {}
for k, v in receipt_rule.items():
self._parse_param(k, v, rule)
template = self.response_template(DESCRIBE_RECEIPT_RULE)
return template.render(rule=rule)
VERIFY_EMAIL_IDENTITY = """<VerifyEmailIdentityResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
<VerifyEmailIdentityResult/>
@ -492,3 +506,46 @@ CREATE_RECEIPT_RULE = """<CreateReceiptRuleResponse xmlns="http://ses.amazonaws.
<RequestId>15e0ef1a-9bf2-11e1-9279-01ab88cf109a</RequestId>
</ResponseMetadata>
</CreateReceiptRuleResponse>"""
DESCRIBE_RECEIPT_RULE = """<DescribeReceiptRuleResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
<DescribeReceiptRuleResult>
<Rule>
<Recipients>
{% for recipient in rule["recipients"] %}
<member>{{recipient}}</member>
{% endfor %}
</Recipients>
<Name>{{rule["name"]}}</Name>
<Actions>
{% for action in rule["actions"] %}
<member>
{% if action["_s3_action"] %}
<S3Action>
<BucketName>{{action["_s3_action"]["_bucket_name"]}}</BucketName>
<KmsKeyArn>{{action["_s3_action"]["_kms_key_arn"]}}</KmsKeyArn>
<ObjectKeyPrefix>{{action["_s3_action"]["_object_key_prefix"]}}</ObjectKeyPrefix>
<TopicArn>{{action["_s3_action"]["_topic_arn"]}}</TopicArn>
</S3Action>
{% endif %}
{% if action["_bounce_action"] %}
<BounceAction>
<TopicArn>{{action["_bounce_action"]["_topic_arn"]}}</TopicArn>
<SmtpReplyCode>{{action["_bounce_action"]["_smtp_reply_code"]}}</SmtpReplyCode>
<StatusCode>{{action["_bounce_action"]["_status_code"]}}</StatusCode>
<Message>{{action["_bounce_action"]["_message"]}}</Message>
<Sender>{{action["_bounce_action"]["_sender"]}}</Sender>
</BounceAction>
{% endif %}
</member>
{% endfor %}
</Actions>
<TlsPolicy>{{rule["tls_policy"]}}</TlsPolicy>
<ScanEnabled>{{rule["scan_enabled"]}}</ScanEnabled>
<Enabled>{{rule["enabled"]}}</Enabled>
</Rule>
</DescribeReceiptRuleResult>
<ResponseMetadata>
<RequestId>15e0ef1a-9bf2-11e1-9279-01ab88cf109a</RequestId>
</ResponseMetadata>
</DescribeReceiptRuleResponse>
"""

View File

@ -481,6 +481,103 @@ def test_create_receipt_rule():
ex.value.response["Error"]["Code"].should.equal("RuleSetDoesNotExist")
@mock_ses
def test_describe_receipt_rule():
conn = boto3.client("ses", region_name="us-east-1")
rule_set_name = "testRuleSet"
conn.create_receipt_rule_set(RuleSetName=rule_set_name)
rule_name = "testRule"
conn.create_receipt_rule(
RuleSetName=rule_set_name,
Rule={
"Name": rule_name,
"Enabled": False,
"TlsPolicy": "Optional",
"Recipients": ["test@email.com", "test2@email.com"],
"Actions": [
{
"S3Action": {
"TopicArn": "string",
"BucketName": "testBucketName",
"ObjectKeyPrefix": "testObjectKeyPrefix",
"KmsKeyArn": "string",
},
"BounceAction": {
"TopicArn": "string",
"SmtpReplyCode": "string",
"StatusCode": "string",
"Message": "string",
"Sender": "string",
},
}
],
"ScanEnabled": False,
},
)
receipt_rule_response = conn.describe_receipt_rule(
RuleSetName=rule_set_name, RuleName=rule_name
)
receipt_rule_response["Rule"]["Name"].should.equal(rule_name)
receipt_rule_response["Rule"]["Enabled"].should.equal(False)
receipt_rule_response["Rule"]["TlsPolicy"].should.equal("Optional")
len(receipt_rule_response["Rule"]["Recipients"]).should.equal(2)
receipt_rule_response["Rule"]["Recipients"][0].should.equal("test@email.com")
len(receipt_rule_response["Rule"]["Actions"]).should.equal(1)
receipt_rule_response["Rule"]["Actions"][0].should.have.key("S3Action")
receipt_rule_response["Rule"]["Actions"][0]["S3Action"].should.have.key(
"TopicArn"
).being.equal("string")
receipt_rule_response["Rule"]["Actions"][0]["S3Action"].should.have.key(
"BucketName"
).being.equal("testBucketName")
receipt_rule_response["Rule"]["Actions"][0]["S3Action"].should.have.key(
"ObjectKeyPrefix"
).being.equal("testObjectKeyPrefix")
receipt_rule_response["Rule"]["Actions"][0]["S3Action"].should.have.key(
"KmsKeyArn"
).being.equal("string")
receipt_rule_response["Rule"]["Actions"][0].should.have.key("BounceAction")
receipt_rule_response["Rule"]["Actions"][0]["BounceAction"].should.have.key(
"TopicArn"
).being.equal("string")
receipt_rule_response["Rule"]["Actions"][0]["BounceAction"].should.have.key(
"SmtpReplyCode"
).being.equal("string")
receipt_rule_response["Rule"]["Actions"][0]["BounceAction"].should.have.key(
"StatusCode"
).being.equal("string")
receipt_rule_response["Rule"]["Actions"][0]["BounceAction"].should.have.key(
"Message"
).being.equal("string")
receipt_rule_response["Rule"]["Actions"][0]["BounceAction"].should.have.key(
"Sender"
).being.equal("string")
receipt_rule_response["Rule"]["ScanEnabled"].should.equal(False)
with pytest.raises(ClientError) as error:
conn.describe_receipt_rule(RuleSetName="invalidRuleSetName", RuleName=rule_name)
error.value.response["Error"]["Code"].should.equal("RuleSetDoesNotExist")
with pytest.raises(ClientError) as error:
conn.describe_receipt_rule(
RuleSetName=rule_set_name, RuleName="invalidRuleName"
)
error.value.response["Error"]["Code"].should.equal("RuleDoesNotExist")
@mock_ses
def test_create_ses_template():
conn = boto3.client("ses", region_name="us-east-1")