15
15
from aiosmtplib import send
16
16
17
17
18
+ @pytest .mark .parametrize (
19
+ "message" , ["message" , "compat32_message" , "mime_message" ], indirect = True
20
+ )
18
21
async def test_send (
19
22
hostname : str ,
20
23
smtpd_server_port : int ,
21
- message : email .message .Message ,
24
+ message : Union [ email .message .EmailMessage , email . message . Message ] ,
22
25
received_messages : list [email .message .EmailMessage ],
23
26
client_tls_context : ssl .SSLContext ,
24
27
) -> None :
25
- errors , response = await send (
28
+ errors , _ = await send (
26
29
message ,
27
30
hostname = hostname ,
28
31
port = smtpd_server_port ,
@@ -33,37 +36,17 @@ async def test_send(
33
36
assert len (received_messages ) == 1
34
37
35
38
36
- async def test_send_with_str (
39
+ @pytest .mark .parametrize ("message" , ["message_str" , "message_bytes" ], indirect = True )
40
+ async def test_send_with_raw_message (
37
41
hostname : str ,
38
42
smtpd_server_port : int ,
39
43
recipient_str : str ,
40
44
sender_str : str ,
41
- message_str : str ,
45
+ message : Union [ str , bytes ] ,
42
46
received_messages : list [email .message .EmailMessage ],
43
47
) -> None :
44
- errors , response = await send (
45
- message_str ,
46
- hostname = hostname ,
47
- port = smtpd_server_port ,
48
- sender = sender_str ,
49
- recipients = [recipient_str ],
50
- start_tls = False ,
51
- )
52
-
53
- assert not errors
54
- assert len (received_messages ) == 1
55
-
56
-
57
- async def test_send_with_bytes (
58
- hostname : str ,
59
- smtpd_server_port : int ,
60
- recipient_str : str ,
61
- sender_str : str ,
62
- message_str : str ,
63
- received_messages : list [email .message .EmailMessage ],
64
- ) -> None :
65
- errors , response = await send (
66
- bytes (message_str , "ascii" ),
48
+ errors , _ = await send (
49
+ message ,
67
50
hostname = hostname ,
68
51
port = smtpd_server_port ,
69
52
sender = sender_str ,
@@ -80,10 +63,9 @@ async def test_send_without_sender(
80
63
smtpd_server_port : int ,
81
64
recipient_str : str ,
82
65
message_str : str ,
83
- received_messages : list [email .message .EmailMessage ],
84
66
) -> None :
85
67
with pytest .raises (ValueError ):
86
- errors , response = await send (
68
+ await send (
87
69
message_str ,
88
70
hostname = hostname ,
89
71
port = smtpd_server_port ,
@@ -98,10 +80,9 @@ async def test_send_without_recipients(
98
80
smtpd_server_port : int ,
99
81
sender_str : str ,
100
82
message_str : str ,
101
- received_messages : list [email .message .EmailMessage ],
102
83
) -> None :
103
84
with pytest .raises (ValueError ):
104
- errors , response = await send (
85
+ await send (
105
86
message_str ,
106
87
hostname = hostname ,
107
88
port = smtpd_server_port ,
@@ -115,11 +96,11 @@ async def test_send_with_start_tls(
115
96
hostname : str ,
116
97
smtpd_server_port : int ,
117
98
client_tls_context : ssl .SSLContext ,
118
- message : email .message .Message ,
99
+ message : email .message .EmailMessage ,
119
100
received_messages : list [email .message .EmailMessage ],
120
101
received_commands : list [tuple [str , tuple [Any , ...]]],
121
102
) -> None :
122
- errors , response = await send (
103
+ errors , _ = await send (
123
104
message ,
124
105
hostname = hostname ,
125
106
port = smtpd_server_port ,
@@ -135,14 +116,14 @@ async def test_send_with_start_tls(
135
116
async def test_send_with_login (
136
117
hostname : str ,
137
118
smtpd_server_port : int ,
138
- message : email .message .Message ,
119
+ message : email .message .EmailMessage ,
139
120
received_messages : list [email .message .EmailMessage ],
140
121
received_commands : list [tuple [str , tuple [Any , ...]]],
141
122
auth_username : str ,
142
123
auth_password : str ,
143
124
client_tls_context : ssl .SSLContext ,
144
125
) -> None :
145
- errors , response = await send (
126
+ errors , _ = await send (
146
127
message ,
147
128
hostname = hostname ,
148
129
port = smtpd_server_port ,
@@ -160,14 +141,14 @@ async def test_send_with_login(
160
141
async def test_send_via_socket (
161
142
hostname : str ,
162
143
smtpd_server_port : int ,
163
- mime_message : email .message .EmailMessage ,
144
+ message : email .message .EmailMessage ,
164
145
received_messages : list [email .message .EmailMessage ],
165
146
) -> None :
166
147
with socket .socket (socket .AF_INET , socket .SOCK_STREAM ) as sock :
167
148
sock .connect ((hostname , smtpd_server_port ))
168
149
169
150
errors , _ = await send (
170
- mime_message ,
151
+ message ,
171
152
hostname = None ,
172
153
port = None ,
173
154
sock = sock ,
@@ -183,14 +164,14 @@ async def test_send_via_socket_tls_and_hostname(
183
164
hostname : str ,
184
165
client_tls_context : ssl .SSLContext ,
185
166
smtpd_server_port : int ,
186
- mime_message : email .message .EmailMessage ,
167
+ message : email .message .EmailMessage ,
187
168
received_messages : list [email .message .EmailMessage ],
188
169
) -> None :
189
170
with socket .socket (socket .AF_INET , socket .SOCK_STREAM ) as sock :
190
171
sock .connect ((hostname , smtpd_server_port ))
191
172
192
173
errors , _ = await send (
193
- mime_message ,
174
+ message ,
194
175
hostname = hostname ,
195
176
port = None ,
196
177
sock = sock ,
@@ -211,11 +192,11 @@ async def test_send_via_socket_path(
211
192
smtpd_server_socket_path : asyncio .AbstractServer ,
212
193
socket_path : pathlib .Path ,
213
194
socket_path_type : Union [type [str ], type [pathlib .Path ], type [bytes ]],
214
- mime_message : email .message .EmailMessage ,
195
+ message : email .message .EmailMessage ,
215
196
received_messages : list [email .message .EmailMessage ],
216
197
) -> None :
217
198
errors , _ = await send (
218
- mime_message ,
199
+ message ,
219
200
hostname = None ,
220
201
port = None ,
221
202
socket_path = socket_path_type (socket_path ),
@@ -232,11 +213,11 @@ async def test_send_via_socket_path_with_tls(
232
213
socket_path : pathlib .Path ,
233
214
hostname : str ,
234
215
client_tls_context : ssl .SSLContext ,
235
- mime_message : email .message .EmailMessage ,
216
+ message : email .message .EmailMessage ,
236
217
received_messages : list [email .message .EmailMessage ],
237
218
) -> None :
238
219
errors , _ = await send (
239
- mime_message ,
220
+ message ,
240
221
hostname = hostname ,
241
222
port = None ,
242
223
socket_path = socket_path ,
0 commit comments