tests: check decoded email payload (#36515)
This commit is contained in:
parent
2877790b24
commit
a923e056ea
|
@ -2837,7 +2837,7 @@ def test_form_table_field_submit(pub, emails):
|
||||||
resp = resp.follow()
|
resp = resp.follow()
|
||||||
assert 'The form has been recorded' in resp.text
|
assert 'The form has been recorded' in resp.text
|
||||||
# check rst2html didn't fail
|
# check rst2html didn't fail
|
||||||
assert 'ee' in emails.emails['New form (test)']['msg'].get_payload()[1].get_payload()
|
assert b'ee' in emails.emails['New form (test)']['msg'].get_payload()[1].get_payload(decode=True)
|
||||||
|
|
||||||
def test_form_table_rows_field_submit(pub, emails):
|
def test_form_table_rows_field_submit(pub, emails):
|
||||||
formdef = create_formdef()
|
formdef = create_formdef()
|
||||||
|
@ -2903,7 +2903,7 @@ def test_form_table_rows_field_submit(pub, emails):
|
||||||
resp = resp.form.submit('submit')
|
resp = resp.form.submit('submit')
|
||||||
resp = resp.follow()
|
resp = resp.follow()
|
||||||
assert 'The form has been recorded' in resp.text
|
assert 'The form has been recorded' in resp.text
|
||||||
assert 'ee' in emails.emails['New form (test)']['msg'].get_payload()[1].get_payload()
|
assert b'ee' in emails.emails['New form (test)']['msg'].get_payload()[1].get_payload(decode=True)
|
||||||
|
|
||||||
def test_form_new_table_rows_field_draft_recall(pub):
|
def test_form_new_table_rows_field_draft_recall(pub):
|
||||||
formdef = create_formdef()
|
formdef = create_formdef()
|
||||||
|
@ -5908,7 +5908,7 @@ def test_email_actions(pub, emails):
|
||||||
assert '/actions/' in action_url
|
assert '/actions/' in action_url
|
||||||
if docutils:
|
if docutils:
|
||||||
assert len(email_data['payloads']) == 2
|
assert len(email_data['payloads']) == 2
|
||||||
assert action_url in email_data['payloads'][1]
|
assert action_url in force_text(email_data['payloads'][1])
|
||||||
|
|
||||||
app = get_app(pub)
|
app = get_app(pub)
|
||||||
resp = app.get(action_url)
|
resp = app.get(action_url)
|
||||||
|
|
|
@ -283,7 +283,7 @@ def test_email_signature_plain(emails):
|
||||||
send_email('test', mail_body='Hello', email_rcpt='test@localhost', want_html=False)
|
send_email('test', mail_body='Hello', email_rcpt='test@localhost', want_html=False)
|
||||||
assert emails.count() == 1
|
assert emails.count() == 1
|
||||||
assert not emails.emails['test']['msg'].is_multipart()
|
assert not emails.emails['test']['msg'].is_multipart()
|
||||||
assert 'Footer\nText' in emails.emails['test']['msg'].get_payload()
|
assert b'Footer\nText' in emails.emails['test']['msg'].get_payload(decode=True)
|
||||||
|
|
||||||
def test_email_from(emails):
|
def test_email_from(emails):
|
||||||
pub = create_temporary_pub()
|
pub = create_temporary_pub()
|
||||||
|
@ -303,7 +303,7 @@ def test_email_from(emails):
|
||||||
send_email('test', mail_body='Hello', email_rcpt='test@localhost', want_html=False)
|
send_email('test', mail_body='Hello', email_rcpt='test@localhost', want_html=False)
|
||||||
assert emails.count() == 1
|
assert emails.count() == 1
|
||||||
assert emails.emails['test']['from'] == 'foo@localhost'
|
assert emails.emails['test']['from'] == 'foo@localhost'
|
||||||
assert emails.emails['test']['msg']['From'] == '=?utf-8?q?HELLO?= <foo@localhost>'
|
assert emails.emails['test']['msg']['From'] in ('=?utf-8?q?HELLO?= <foo@localhost>', 'HELLO <foo@localhost>')
|
||||||
|
|
||||||
@pytest.mark.skipif('docutils is None')
|
@pytest.mark.skipif('docutils is None')
|
||||||
def test_email_signature_rst(emails):
|
def test_email_signature_rst(emails):
|
||||||
|
@ -315,8 +315,8 @@ def test_email_signature_rst(emails):
|
||||||
assert emails.emails['test']['msg'].get_content_subtype() == 'alternative'
|
assert emails.emails['test']['msg'].get_content_subtype() == 'alternative'
|
||||||
assert emails.emails['test']['msg'].get_payload()[0].get_content_type() == 'text/plain'
|
assert emails.emails['test']['msg'].get_payload()[0].get_content_type() == 'text/plain'
|
||||||
assert emails.emails['test']['msg'].get_payload()[1].get_content_type() == 'text/html'
|
assert emails.emails['test']['msg'].get_payload()[1].get_content_type() == 'text/html'
|
||||||
assert 'Footer\nText' in emails.emails['test']['msg'].get_payload()[0].get_payload()
|
assert b'Footer\nText' in emails.emails['test']['msg'].get_payload()[0].get_payload(decode=True)
|
||||||
assert '>Footer<' in emails.emails['test']['msg'].get_payload()[1].get_payload()
|
assert b'>Footer<' in emails.emails['test']['msg'].get_payload()[1].get_payload(decode=True)
|
||||||
|
|
||||||
@pytest.mark.skipif('docutils is None')
|
@pytest.mark.skipif('docutils is None')
|
||||||
def test_email_signature_rst_pipes(emails):
|
def test_email_signature_rst_pipes(emails):
|
||||||
|
@ -328,8 +328,8 @@ def test_email_signature_rst_pipes(emails):
|
||||||
assert emails.emails['test']['msg'].get_content_subtype() == 'alternative'
|
assert emails.emails['test']['msg'].get_content_subtype() == 'alternative'
|
||||||
assert emails.emails['test']['msg'].get_payload()[0].get_content_type() == 'text/plain'
|
assert emails.emails['test']['msg'].get_payload()[0].get_content_type() == 'text/plain'
|
||||||
assert emails.emails['test']['msg'].get_payload()[1].get_content_type() == 'text/html'
|
assert emails.emails['test']['msg'].get_payload()[1].get_content_type() == 'text/html'
|
||||||
assert 'Footer\nText' in emails.emails['test']['msg'].get_payload()[0].get_payload()
|
assert b'Footer\nText' in emails.emails['test']['msg'].get_payload()[0].get_payload(decode=True)
|
||||||
assert '>Footer<' in emails.emails['test']['msg'].get_payload()[1].get_payload()
|
assert b'>Footer<' in emails.emails['test']['msg'].get_payload()[1].get_payload(decode=True)
|
||||||
|
|
||||||
def test_email_plain_with_attachments(emails):
|
def test_email_plain_with_attachments(emails):
|
||||||
pub = create_temporary_pub()
|
pub = create_temporary_pub()
|
||||||
|
@ -360,7 +360,7 @@ def test_email_plain_with_attachments(emails):
|
||||||
assert emails.emails['txt']['msg'].get_content_subtype() == 'mixed'
|
assert emails.emails['txt']['msg'].get_content_subtype() == 'mixed'
|
||||||
assert emails.emails['txt']['msg'].get_payload()[0].get_content_type() == 'text/plain'
|
assert emails.emails['txt']['msg'].get_payload()[0].get_content_type() == 'text/plain'
|
||||||
assert emails.emails['txt']['msg'].get_payload()[1].get_content_type() == 'text/plain'
|
assert emails.emails['txt']['msg'].get_payload()[1].get_content_type() == 'text/plain'
|
||||||
assert emails.emails['txt']['msg'].get_payload()[1].get_payload() == 'foo-text-bar'
|
assert emails.emails['txt']['msg'].get_payload()[1].get_payload(decode=True) == b'foo-text-bar'
|
||||||
|
|
||||||
send_email('jpgodt', mail_body='Hello',
|
send_email('jpgodt', mail_body='Hello',
|
||||||
email_rcpt='test@localhost', want_html=False,
|
email_rcpt='test@localhost', want_html=False,
|
||||||
|
@ -382,7 +382,7 @@ def test_email_plain_with_attachments(emails):
|
||||||
assert emails.emails['unknown']['msg'].get_content_subtype() == 'mixed'
|
assert emails.emails['unknown']['msg'].get_content_subtype() == 'mixed'
|
||||||
assert emails.emails['unknown']['msg'].get_payload()[0].get_content_type() == 'text/plain'
|
assert emails.emails['unknown']['msg'].get_payload()[0].get_content_type() == 'text/plain'
|
||||||
assert emails.emails['unknown']['msg'].get_payload()[1].get_content_type() == 'x-foo/x-bar'
|
assert emails.emails['unknown']['msg'].get_payload()[1].get_content_type() == 'x-foo/x-bar'
|
||||||
assert emails.emails['unknown']['msg'].get_payload()[1].get_payload() == base64.b64encode('barfoo')
|
assert emails.emails['unknown']['msg'].get_payload()[1].get_payload(decode=False).strip() == 'YmFyZm9v'
|
||||||
|
|
||||||
send_email('test-bad-attachment', mail_body='Hello',
|
send_email('test-bad-attachment', mail_body='Hello',
|
||||||
email_rcpt='test@localhost', want_html=False,
|
email_rcpt='test@localhost', want_html=False,
|
||||||
|
@ -452,12 +452,12 @@ M. Francis Kuntz
|
||||||
assert emails.emails['test']['msg'].get_content_subtype() == 'alternative'
|
assert emails.emails['test']['msg'].get_content_subtype() == 'alternative'
|
||||||
assert emails.emails['test']['msg'].get_payload()[0].get_content_type() == 'text/plain'
|
assert emails.emails['test']['msg'].get_payload()[0].get_content_type() == 'text/plain'
|
||||||
assert emails.emails['test']['msg'].get_payload()[1].get_content_type() == 'text/html'
|
assert emails.emails['test']['msg'].get_payload()[1].get_content_type() == 'text/html'
|
||||||
text = emails.emails['test']['msg'].get_payload()[0].get_payload()
|
text = emails.emails['test']['msg'].get_payload()[0].get_payload(decode=True)
|
||||||
html = emails.emails['test']['msg'].get_payload()[1].get_payload()
|
html = emails.emails['test']['msg'].get_payload()[1].get_payload(decode=True)
|
||||||
assert html.count('<ol') == 1
|
assert html.count(b'<ol') == 1
|
||||||
assert not '<ul' in html
|
assert not b'<ul' in html
|
||||||
assert 'arabic simple' in html
|
assert b'arabic simple' in html
|
||||||
assert 'M. Francis Kuntz' in html
|
assert b'M. Francis Kuntz' in html
|
||||||
|
|
||||||
def test_dict_from_prefix():
|
def test_dict_from_prefix():
|
||||||
d = evalutils.dict_from_prefix('var1', {})
|
d = evalutils.dict_from_prefix('var1', {})
|
||||||
|
|
|
@ -8,6 +8,8 @@ import zipfile
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
|
||||||
|
from django.utils import six
|
||||||
|
from django.utils.encoding import force_bytes
|
||||||
from django.utils.six import BytesIO, StringIO
|
from django.utils.six import BytesIO, StringIO
|
||||||
from django.utils.six.moves.urllib import parse as urlparse
|
from django.utils.six.moves.urllib import parse as urlparse
|
||||||
|
|
||||||
|
@ -1368,7 +1370,10 @@ def test_email_attachments(pub, emails):
|
||||||
assert emails.emails['foobar']['msg'].get_payload()[0].get_content_type() == 'text/html'
|
assert emails.emails['foobar']['msg'].get_payload()[0].get_content_type() == 'text/html'
|
||||||
assert emails.emails['foobar']['msg'].get_payload()[1].get_content_type() == 'image/jpeg'
|
assert emails.emails['foobar']['msg'].get_payload()[1].get_content_type() == 'image/jpeg'
|
||||||
assert emails.emails['foobar']['msg'].get_payload()[2].get_content_type() == 'text/plain'
|
assert emails.emails['foobar']['msg'].get_payload()[2].get_content_type() == 'text/plain'
|
||||||
assert emails.emails['foobar']['msg'].get_payload()[2].get_payload() == 'blah'
|
if six.PY2:
|
||||||
|
assert emails.emails['foobar']['msg'].get_payload()[2].get_payload() == 'blah'
|
||||||
|
else:
|
||||||
|
assert base64.decodestring(force_bytes(emails.emails['foobar']['msg'].get_payload()[2].get_payload())) == b'blah'
|
||||||
assert len(emails.emails['foobar']['msg'].get_payload()) == 3
|
assert len(emails.emails['foobar']['msg'].get_payload()) == 3
|
||||||
|
|
||||||
emails.empty()
|
emails.empty()
|
||||||
|
|
Loading…
Reference in New Issue