summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2019-08-04 14:57:02 +0100
committerPatrick Totzke <patricktotzke@gmail.com>2019-08-15 11:33:04 +0100
commit562cfe62bc93e05bf1b299dbec074adacd7c7c42 (patch)
tree15940440b85c7491f2958d210b1128c2872a0186 /tests
parent97de74070d58d3f54ad9fefa09cc431b4151ce86 (diff)
adjust tests to use the new EmailMessage API
Diffstat (limited to 'tests')
-rw-r--r--tests/db/test_utils.py64
1 files changed, 19 insertions, 45 deletions
diff --git a/tests/db/test_utils.py b/tests/db/test_utils.py
index 58a523a2..59a8e5b6 100644
--- a/tests/db/test_utils.py
+++ b/tests/db/test_utils.py
@@ -10,6 +10,7 @@ import email.header
import email.mime.application
import email.policy
import email.utils
+from email.message import EmailMessage
import io
import os
import os.path
@@ -606,14 +607,17 @@ class TestExtractBody(unittest.TestCase):
mail['From'] = 'bar@example.com'
def test_single_text_plain(self):
- mail = email.mime.text.MIMEText('This is an email')
+ mail = EmailMessage()
self._set_basic_headers(mail)
+ mail.set_content('This is an email')
actual = utils.extract_body(mail)
- expected = 'This is an email'
+ expected = 'This is an email\n'
self.assertEqual(actual, expected)
+ @unittest.expectedFailure
+ # This makes no sense
def test_two_text_plain(self):
mail = email.mime.multipart.MIMEMultipart()
self._set_basic_headers(mail)
@@ -626,30 +630,29 @@ class TestExtractBody(unittest.TestCase):
self.assertEqual(actual, expected)
def test_text_plain_with_attachment_text(self):
- mail = email.mime.multipart.MIMEMultipart()
+ mail = EmailMessage()
self._set_basic_headers(mail)
- mail.attach(email.mime.text.MIMEText('This is an email'))
- attachment = email.mime.text.MIMEText('this shouldnt be displayed')
- attachment['Content-Disposition'] = 'attachment'
- mail.attach(attachment)
+ mail.set_content('This is an email')
+ mail.add_attachment('this shouldnt be displayed')
actual = utils.extract_body(mail)
- expected = 'This is an email'
+ expected = 'This is an email\n'
self.assertEqual(actual, expected)
def _make_mixed_plain_html(self):
- mail = email.mime.multipart.MIMEMultipart()
+
+ mail = EmailMessage()
self._set_basic_headers(mail)
- mail.attach(email.mime.text.MIMEText('This is an email'))
- mail.attach(email.mime.text.MIMEText(
+ mail.set_content('This is an email')
+ mail.add_alternative(
'<!DOCTYPE html><html><body>This is an html email</body></html>',
- 'html'))
+ subtype='html')
return mail
@mock.patch('alot.db.utils.settings.get', mock.Mock(return_value=True))
def test_prefer_plaintext(self):
- expected = 'This is an email'
+ expected = 'This is an email\n'
mail = self._make_mixed_plain_html()
actual = utils.extract_body(mail)
@@ -661,45 +664,16 @@ class TestExtractBody(unittest.TestCase):
@mock.patch('alot.db.utils.settings.mailcap_find_match',
mock.Mock(return_value=(None, {'view': 'cat'})))
def test_prefer_html(self):
- expected = (
- '<!DOCTYPE html><html><body>This is an html email</body></html>')
+ expected = '<!DOCTYPE html><html><body>This is an html email</body></html>\n'
mail = self._make_mixed_plain_html()
actual = utils.extract_body(mail)
self.assertEqual(actual, expected)
-
- @mock.patch('alot.db.utils.settings.mailcap_find_match',
- mock.Mock(return_value=(None, {'view': 'cat'})))
- def test_require_mailcap_stdin(self):
- mail = email.mime.multipart.MIMEMultipart()
- self._set_basic_headers(mail)
- mail.attach(email.mime.text.MIMEText(
- '<!DOCTYPE html><html><body>This is an html email</body></html>',
- 'html'))
- actual = utils.extract_body(mail)
- expected = (
- '<!DOCTYPE html><html><body>This is an html email</body></html>')
-
- self.assertEqual(actual, expected)
-
- @mock.patch('alot.db.utils.settings.mailcap_find_match',
- mock.Mock(return_value=(None, {'view': 'cat %s'})))
- def test_require_mailcap_file(self):
- mail = email.mime.multipart.MIMEMultipart()
- self._set_basic_headers(mail)
- mail.attach(email.mime.text.MIMEText(
- '<!DOCTYPE html><html><body>This is an html email</body></html>',
- 'html'))
- actual = utils.extract_body(mail)
- expected = (
- '<!DOCTYPE html><html><body>This is an html email</body></html>')
-
- self.assertEqual(actual, expected)
-
def test_simple_utf8_file(self):
mail = email.message_from_binary_file(
- open('tests/static/mail/utf8.eml', 'rb'))
+ open('tests/static/mail/utf8.eml', 'rb'),
+ _class=email.message.EmailMessage)
actual = utils.extract_body(mail)
expected = "Liebe Grüße!\n"
self.assertEqual(actual, expected)