-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathtest_send.py
More file actions
65 lines (51 loc) · 2.35 KB
/
Copy pathtest_send.py
File metadata and controls
65 lines (51 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# coding: utf-8
from __future__ import unicode_literals
import time
import random
import pytest
import emails
import emails.loader
from emails.backend.smtp import SMTPBackend
from .helpers import common_email_data
from emails.testsuite.smtp_servers import get_servers
def get_letters():
# Test email with attachment
URL = 'http://lavr.github.io/python-emails/tests/campaignmonitor-samples/sample-template/images/gallery.png'
data = common_email_data(subject='Single attachment', attachments=[emails.store.LazyHTTPFile(uri=URL), ])
yield emails.html(**data), None
# Email with render
yield emails.html(**common_email_data(subject='Render with name=John')), {'name': u'John'}
# Email with several inline images
url = 'http://lavr.github.io/python-emails/tests/campaignmonitor-samples/sample-template/template-widgets.html'
data = common_email_data(subject='Sample html with inline images')
del data['html']
yield emails.loader.from_url(url=url, message_params=data, images_inline=True), None
# Email with utf-8 "to"
yield emails.Message(**common_email_data(mail_to="anaïs@lavr.me", subject="UTF-8 To")), None
def test_send_letters():
for m, render in get_letters():
for tag, server in get_servers():
server.patch_message(m)
print(tag, server.params)
response = m.send(smtp=server.params, render=render, smtp_mail_options=['smtputf8'])
assert response.success
# server.sleep()
@pytest.mark.e2e
def test_send_simple():
message = emails.html(**common_email_data(subject='Simple e2e test'))
for tag, server in get_servers():
server.patch_message(message)
response = message.send(smtp=server.params)
assert response.success
@pytest.mark.e2e
def test_send_with_context_manager():
for _, server in get_servers():
b = SMTPBackend(**server.params)
with b as backend:
for n in range(2):
data = common_email_data(subject='context manager {0}'.format(n))
message = emails.html(**data)
message = server.patch_message(message)
response = message.send(smtp=backend)
assert response.success or response.status_code in (421, 451), 'error sending to {0}'.format(server.params) # gmail not always like test emails
assert b._client is None