summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLucas Hoffmann <l-m-h@web.de>2017-08-21 23:18:14 +0200
committerLucas Hoffmann <l-m-h@web.de>2017-08-21 23:23:41 +0200
commit6ee21b330d369cc91a9ba99eb2ee010e9e19e624 (patch)
tree5e2e6c7eff8ac0dcc99126f91775bb81b31552c0 /tests
parent762b7dc1a60dc322876c6b5fa8769037c483eba0 (diff)
Add failing test for alot.helper.email_as_string()
Since email_as_string uses io.BytesIO it can not handle the unicode header names that might result from a envelope.construct_mail().
Diffstat (limited to 'tests')
-rw-r--r--tests/helper_test.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/helper_test.py b/tests/helper_test.py
index b0e799ca..4cfe704d 100644
--- a/tests/helper_test.py
+++ b/tests/helper_test.py
@@ -20,6 +20,7 @@
from __future__ import absolute_import
import datetime
+import email
import errno
import random
import unittest
@@ -379,3 +380,26 @@ class TestCallCmd(unittest.TestCase):
self.assertEqual(out, u'')
self.assertEqual(err, u'foobar')
self.assertEqual(code, 42)
+
+
+class TestEmailAsString(unittest.TestCase):
+
+ def test_empty_message(self):
+ message = email.message.Message()
+ actual = helper.email_as_string(message)
+ expected = '\r\n'
+ self.assertEqual(actual, expected)
+
+ @unittest.expectedFailure
+ def test_empty_message_with_unicode_header(self):
+ """Test if unicode header keys can be used in an email that is
+ converted to string with email_as_string()."""
+ # This is what alot.db.envelope.Envelope.construct_mail() currently
+ # does: It constructs a message object and then copies all headers from
+ # the envelope to the message object. Some header names are stored as
+ # unicode in the envelope.
+ message = email.message.Message()
+ message[u'X-Unicode-Header'] = 'dummy value'
+ actual = helper.email_as_string(message)
+ expected = 'X-Unicode-Header: dummy value\r\n\r\n'
+ self.assertEqual(actual, expected)