summaryrefslogtreecommitdiff
path: root/tests/db
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2018-08-01 11:14:52 -0700
committerDylan Baker <dylan@pnwbakers.com>2018-08-02 10:51:09 -0700
commit293bf7ad89c837d6a2ee9e08443c00703172d953 (patch)
tree8927a34a5b8aca0287e385f834457258cadfc8c4 /tests/db
parent834a658dfbe25707eebed34d5f5fdd10e1fddd60 (diff)
helper: replace email_as_* with email builtins
Python 3.3 added a new feature to the email module, policies (https://docs.python.org/3.5/library/email.policy.html). Policy objects allow precise control over how numerous features work when converting to and from str or bytes. With the `email.policy.SMTP` the behavior of email_as_bytes and email_as_string can be achieved using the builtin `.as_string()` and `.as_bytes()` methods, without custom code or the need to test it. Additionally these methods handle corner cases that we don't currently handle, such as multi-part messages with different encodings. Fixes #1257
Diffstat (limited to 'tests/db')
-rw-r--r--tests/db/utils_test.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/tests/db/utils_test.py b/tests/db/utils_test.py
index 23885067..7d50d888 100644
--- a/tests/db/utils_test.py
+++ b/tests/db/utils_test.py
@@ -8,6 +8,7 @@ import codecs
import email
import email.header
import email.mime.application
+import email.policy
import io
import os
import os.path
@@ -465,7 +466,7 @@ class TestMessageFromFile(TestCaseClassCleanup):
text = b'This is some text'
t = email.mime.text.MIMEText(text, 'plain', 'utf-8')
_, sig = crypto.detached_signature_for(
- helper.email_as_bytes(t), self.keys)
+ t.as_bytes(policy=email.policy.SMTP), self.keys)
s = email.mime.application.MIMEApplication(
sig, 'pgp-signature', email.encoders.encode_7or8bit)
m = email.mime.multipart.MIMEMultipart('signed', None, [t, s])
@@ -555,7 +556,7 @@ class TestMessageFromFile(TestCaseClassCleanup):
else:
text = b'This is some text'
t = email.mime.text.MIMEText(text, 'plain', 'utf-8')
- enc = crypto.encrypt(helper.email_as_bytes(t), self.keys)
+ enc = crypto.encrypt(t.as_bytes(policy=email.policy.SMTP), self.keys)
e = email.mime.application.MIMEApplication(
enc, 'octet-stream', email.encoders.encode_7or8bit)