summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/db/test_envelope.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/tests/db/test_envelope.py b/tests/db/test_envelope.py
index 86e481bf..0d46ba43 100644
--- a/tests/db/test_envelope.py
+++ b/tests/db/test_envelope.py
@@ -14,7 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-import email.parser
+import email
import email.policy
import os
import tempfile
@@ -27,21 +27,25 @@ SETTINGS = {
'user_agent': 'agent',
}
-
class TestEnvelope(unittest.TestCase):
+ def _compare_content(self, first, second):
+ c1 = first.get_content().replace('\r\n', '\n')
+ c2 = second.get_content().replace('\r\n', '\n')
+ self.assertEqual(c1, c2)
+
def assertEmailEqual(self, first, second):
with self.subTest('body'):
self.assertEqual(first.is_multipart(), second.is_multipart())
if not first.is_multipart():
- self.assertEqual(first.get_payload(), second.get_payload())
+ self._compare_content(first, second)
else:
for f, s in zip(first.walk(), second.walk()):
if f.is_multipart() or s.is_multipart():
self.assertEqual(first.is_multipart(),
second.is_multipart())
else:
- self.assertEqual(f.get_payload(), s.get_payload())
+ self._compare_content(f, s)
with self.subTest('headers'):
self.assertListEqual(first.values(), second.values())
@@ -52,9 +56,9 @@ class TestEnvelope(unittest.TestCase):
self.assertEqual(e['Subject'], 'sm\xf8rebr\xf8d')
def _test_mail(self, envelope):
- mail = envelope.construct_mail()
- raw = mail.as_string(policy=email.policy.SMTP)
- actual = email.parser.Parser().parsestr(raw)
+ mail = envelope.construct_mail()
+ raw = mail.as_bytes()
+ actual = email.message_from_bytes(raw, policy = mail.policy)
self.assertEmailEqual(mail, actual)
@mock.patch('alot.db.envelope.settings', SETTINGS)