summaryrefslogtreecommitdiff
path: root/src/mailman/testing/helpers.py
diff options
context:
space:
mode:
authorBarry Warsaw2011-05-01 12:44:23 -0400
committerBarry Warsaw2011-05-01 12:44:23 -0400
commitcab8aea12c63fe4bcf8930e9b2f53012d2a74ee8 (patch)
treeb348573e40c969c3ae1f24387c1a6ebbf78c5d35 /src/mailman/testing/helpers.py
parenta90ca4ce77d99460ffd36a366cea0162869df783 (diff)
downloadmailman-cab8aea12c63fe4bcf8930e9b2f53012d2a74ee8.tar.gz
mailman-cab8aea12c63fe4bcf8930e9b2f53012d2a74ee8.tar.zst
mailman-cab8aea12c63fe4bcf8930e9b2f53012d2a74ee8.zip
Diffstat (limited to 'src/mailman/testing/helpers.py')
-rw-r--r--src/mailman/testing/helpers.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/mailman/testing/helpers.py b/src/mailman/testing/helpers.py
index b5df649e0..74e00b501 100644
--- a/src/mailman/testing/helpers.py
+++ b/src/mailman/testing/helpers.py
@@ -45,6 +45,7 @@ import threading
from base64 import b64encode
from contextlib import contextmanager
+from email import message_from_string
from httplib2 import Http
from urllib import urlencode
from urllib2 import HTTPError
@@ -53,6 +54,7 @@ from zope.component import getUtility
from mailman.bin.master import Loop as Master
from mailman.config import config
+from mailman.email.message import Message
from mailman.interfaces.member import MemberRole
from mailman.interfaces.messages import IMessageStore
from mailman.interfaces.usermanager import IUserManager
@@ -360,3 +362,22 @@ def reset_the_world():
# Reset the global style manager.
config.style_manager.populate()
+
+
+def specialized_message_from_string(unicode_text):
+ """Parse text into a message object.
+
+ This is specialized in the sense that an instance of Mailman's own Message
+ object is returned, and this message object has an attribute
+ `original_size` which is the pre-calculated size in bytes of the message's
+ text representation.
+
+ Also, the text must be ASCII-only unicode.
+ """
+ # This mimic what Switchboard.dequeue() does when parsing a message from
+ # text into a Message instance.
+ text = unicode_text.encode('ascii')
+ original_size = len(text)
+ message = message_from_string(text, Message)
+ message.original_size = original_size
+ return message