from awscli.testutils import BaseAWSCommandParamsTest
class TestSendEmail(BaseAWSCommandParamsTest):
prefix = 'ses send-email'
def test_plain_text(self):
args = (' --subject This_is_a_test --from [email protected]'
' --to [email protected] --text This_is_the_message')
args_list = (self.prefix + args).split()
result = {
'Source': '[email protected]',
'Destination': {'ToAddresses': ['[email protected]']},
'Message': {'Body': {'Text': {'Data': 'This_is_the_message'}},
'Subject': {'Data': 'This_is_a_test'}}}
self.assert_params_for_cmd(args_list, result)
def test_plain_text_multiple_to(self):
args = (' --subject This_is_a_test --from [email protected]'
' --to [email protected] [email protected] --text This_is_the_message')
args_list = (self.prefix + args).split()
result = {'Source': '[email protected]',
'Destination': {
'ToAddresses': ['[email protected]', '[email protected]']},
'Message': {
'Body': {'Text': {'Data': 'This_is_the_message'}},
'Subject': {'Data': 'This_is_a_test'}}}
self.assert_params_for_cmd(args_list, result)
def test_plain_text_multiple_cc(self):
args = (' --subject This_is_a_test --from [email protected]'
' --to [email protected] [email protected] --text This_is_the_message'
' --cc [email protected] [email protected]')
args_list = (self.prefix + args).split()
result = {'Source': '[email protected]',
'Destination': {
'CcAddresses': ['[email protected]', '[email protected]'],
'ToAddresses': ['[email protected]', '[email protected]']},
'Message': {
'Body': {'Text': {'Data': 'This_is_the_message'}},
'Subject': {'Data': 'This_is_a_test'}}}
self.assert_params_for_cmd(args_list, result)
def test_plain_text_multiple_bcc(self):
args = (' --subject This_is_a_test --from [email protected]'
' --to [email protected] [email protected] --text This_is_the_message'
' --cc [email protected] [email protected]'
' --bcc [email protected] [email protected]')
args_list = (self.prefix + args).split()
result = {
'Source': '[email protected]',
'Destination': {'BccAddresses': ['[email protected]', '[email protected]'],
'CcAddresses': ['[email protected]', '[email protected]'],
'ToAddresses': ['[email protected]', '[email protected]']},
'Message': {
'Body': {'Text': {'Data': 'This_is_the_message'}},
'Subject': {'Data': 'This_is_a_test'}}}
self.assert_params_for_cmd(args_list, result)
def test_html_text(self):
args = (' --subject This_is_a_test --from [email protected]'
' --to [email protected] --html This_is_the_html_message')
args_list = (self.prefix + args).split()
result = {
'Source': '[email protected]',
'Destination': {'ToAddresses': ['[email protected]']},
'Message': {'Subject': {'Data': 'This_is_a_test'},
'Body': {
'Html': {'Data': 'This_is_the_html_message'}}}}
self.assert_params_for_cmd(args_list, result)
def test_html_both(self):
args = (' --subject This_is_a_test --from [email protected]'
' --to [email protected] --html This_is_the_html_message'
' --text This_is_the_text_message')
args_list = (self.prefix + args).split()
result = {
'Source': '[email protected]',
'Destination': {'ToAddresses': ['[email protected]']},
'Message': {
'Subject': {'Data': 'This_is_a_test'},
'Body': {
'Text': {'Data': 'This_is_the_text_message'},
'Html': {'Data': 'This_is_the_html_message'}}}}
self.assert_params_for_cmd(args_list, result)
def test_using_json(self):
args = (' --message {"Subject":{"Data":"This_is_a_test"},'
'"Body":{"Text":{"Data":"This_is_the_message"}}}'
' --from [email protected]'
' --destination {"ToAddresses":["[email protected]"]}')
args_list = (self.prefix + args).split()
result = {'Destination': {'ToAddresses': ['[email protected]']},
'Message': {
'Subject': {
'Data': 'This_is_a_test'},
'Body': {
'Text': {'Data': 'This_is_the_message'}}},
'Source': '[email protected]'}
self.assert_params_for_cmd(args_list, result)
def test_both_destination_and_to(self):
args = (' --message {"Subject":{"Data":"This_is_a_test"},'
'"Body":{"Text":{"Data":"This_is_the_message"}}}'
' --from [email protected]'
' --destination {"ToAddresses":["[email protected]"]}'
' --to [email protected]')
args_list = (self.prefix + args).split()
self.run_cmd(args_list, expected_rc=255)
def test_both_message_and_text(self):
args = (' --message {"Subject":{"Data":"This_is_a_test"},'
'"Body":{"Text":{"Data":"This_is_the_message"}}}'
' --from [email protected]'
' --destination {"ToAddresses":["[email protected]"]}'
' --text This_is_another_body')
args_list = (self.prefix + args).split()
self.run_cmd(args_list, expected_rc=255)