Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/functional/ses/test_send_email.py
1567 views
1
#!/usr/bin/env python
2
# Copyright 2013-2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License"). You
5
# may not use this file except in compliance with the License. A copy of
6
# the License is located at
7
#
8
# http://aws.amazon.com/apache2.0/
9
#
10
# or in the "license" file accompanying this file. This file is
11
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
12
# ANY KIND, either express or implied. See the License for the specific
13
# language governing permissions and limitations under the License.
14
from awscli.testutils import BaseAWSCommandParamsTest
15
16
17
class TestSendEmail(BaseAWSCommandParamsTest):
18
19
prefix = 'ses send-email'
20
21
def test_plain_text(self):
22
args = (' --subject This_is_a_test --from [email protected]'
23
' --to [email protected] --text This_is_the_message')
24
args_list = (self.prefix + args).split()
25
result = {
26
'Source': '[email protected]',
27
'Destination': {'ToAddresses': ['[email protected]']},
28
'Message': {'Body': {'Text': {'Data': 'This_is_the_message'}},
29
'Subject': {'Data': 'This_is_a_test'}}}
30
self.assert_params_for_cmd(args_list, result)
31
32
def test_plain_text_multiple_to(self):
33
args = (' --subject This_is_a_test --from [email protected]'
34
' --to [email protected] [email protected] --text This_is_the_message')
35
args_list = (self.prefix + args).split()
36
result = {'Source': '[email protected]',
37
'Destination': {
38
'ToAddresses': ['[email protected]', '[email protected]']},
39
'Message': {
40
'Body': {'Text': {'Data': 'This_is_the_message'}},
41
'Subject': {'Data': 'This_is_a_test'}}}
42
43
self.assert_params_for_cmd(args_list, result)
44
45
def test_plain_text_multiple_cc(self):
46
args = (' --subject This_is_a_test --from [email protected]'
47
' --to [email protected] [email protected] --text This_is_the_message'
48
' --cc [email protected] [email protected]')
49
args_list = (self.prefix + args).split()
50
result = {'Source': '[email protected]',
51
'Destination': {
52
'CcAddresses': ['[email protected]', '[email protected]'],
53
'ToAddresses': ['[email protected]', '[email protected]']},
54
'Message': {
55
'Body': {'Text': {'Data': 'This_is_the_message'}},
56
'Subject': {'Data': 'This_is_a_test'}}}
57
58
self.assert_params_for_cmd(args_list, result)
59
60
def test_plain_text_multiple_bcc(self):
61
args = (' --subject This_is_a_test --from [email protected]'
62
' --to [email protected] [email protected] --text This_is_the_message'
63
' --cc [email protected] [email protected]'
64
' --bcc [email protected] [email protected]')
65
args_list = (self.prefix + args).split()
66
67
result = {
68
'Source': '[email protected]',
69
'Destination': {'BccAddresses': ['[email protected]', '[email protected]'],
70
'CcAddresses': ['[email protected]', '[email protected]'],
71
'ToAddresses': ['[email protected]', '[email protected]']},
72
'Message': {
73
'Body': {'Text': {'Data': 'This_is_the_message'}},
74
'Subject': {'Data': 'This_is_a_test'}}}
75
76
self.assert_params_for_cmd(args_list, result)
77
78
def test_html_text(self):
79
args = (' --subject This_is_a_test --from [email protected]'
80
' --to [email protected] --html This_is_the_html_message')
81
args_list = (self.prefix + args).split()
82
result = {
83
'Source': '[email protected]',
84
'Destination': {'ToAddresses': ['[email protected]']},
85
'Message': {'Subject': {'Data': 'This_is_a_test'},
86
'Body': {
87
'Html': {'Data': 'This_is_the_html_message'}}}}
88
89
self.assert_params_for_cmd(args_list, result)
90
91
def test_html_both(self):
92
args = (' --subject This_is_a_test --from [email protected]'
93
' --to [email protected] --html This_is_the_html_message'
94
' --text This_is_the_text_message')
95
args_list = (self.prefix + args).split()
96
result = {
97
'Source': '[email protected]',
98
'Destination': {'ToAddresses': ['[email protected]']},
99
'Message': {
100
'Subject': {'Data': 'This_is_a_test'},
101
'Body': {
102
'Text': {'Data': 'This_is_the_text_message'},
103
'Html': {'Data': 'This_is_the_html_message'}}}}
104
self.assert_params_for_cmd(args_list, result)
105
106
def test_using_json(self):
107
args = (' --message {"Subject":{"Data":"This_is_a_test"},'
108
'"Body":{"Text":{"Data":"This_is_the_message"}}}'
109
' --from [email protected]'
110
' --destination {"ToAddresses":["[email protected]"]}')
111
args_list = (self.prefix + args).split()
112
result = {'Destination': {'ToAddresses': ['[email protected]']},
113
'Message': {
114
'Subject': {
115
'Data': 'This_is_a_test'},
116
'Body': {
117
'Text': {'Data': 'This_is_the_message'}}},
118
'Source': '[email protected]'}
119
120
self.assert_params_for_cmd(args_list, result)
121
122
def test_both_destination_and_to(self):
123
args = (' --message {"Subject":{"Data":"This_is_a_test"},'
124
'"Body":{"Text":{"Data":"This_is_the_message"}}}'
125
' --from [email protected]'
126
' --destination {"ToAddresses":["[email protected]"]}'
127
' --to [email protected]')
128
args_list = (self.prefix + args).split()
129
self.run_cmd(args_list, expected_rc=255)
130
131
def test_both_message_and_text(self):
132
args = (' --message {"Subject":{"Data":"This_is_a_test"},'
133
'"Body":{"Text":{"Data":"This_is_the_message"}}}'
134
' --from [email protected]'
135
' --destination {"ToAddresses":["[email protected]"]}'
136
' --text This_is_another_body')
137
args_list = (self.prefix + args).split()
138
self.run_cmd(args_list, expected_rc=255)
139
140