[PATCH 08/51] tests: Make sure all emails have a valid msgid
Damien Lespiau
damien.lespiau at intel.com
Sat Sep 12 01:54:41 AEST 2015
Messages ids will be used by the Series code as the way to uniquely
identify series. We must ensure every single email that goes through the
parser has a valid msgid to not fail once we parse series.
Signed-off-by: Damien Lespiau <damien.lespiau at intel.com>
---
patchwork/tests/test_patchparser.py | 14 +++++++++++---
patchwork/tests/utils.py | 5 +++++
2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/patchwork/tests/test_patchparser.py b/patchwork/tests/test_patchparser.py
index 09737d4..afe8ae4 100644
--- a/patchwork/tests/test_patchparser.py
+++ b/patchwork/tests/test_patchparser.py
@@ -19,6 +19,7 @@
import os
from email import message_from_string
+from email.utils import make_msgid
from django.test import TestCase
from patchwork.models import Project, Person, Patch, Comment, State, \
get_default_initial_patch_state
@@ -157,7 +158,8 @@ class SenderEncodingTest(TestCase):
from_header = 'example user <user at example.com>'
def setUp(self):
- mail = 'From: %s\n' % self.from_header + \
+ mail = 'Message-Id: %s\n' % make_msgid() + \
+ 'From: %s\n' % self.from_header + \
'Subject: test\n\n' + \
'test'
self.email = message_from_string(mail)
@@ -199,7 +201,8 @@ class SubjectEncodingTest(PatchTest):
subject_header = 'test subject'
def setUp(self):
- mail = 'From: %s\n' % self.sender + \
+ mail = 'Message-Id: %s\n' % make_msgid() + \
+ 'From: %s\n' % self.sender + \
'Subject: %s\n\n' % self.subject_header + \
'test\n\n' + defaults.patch
self.projects = defaults.project
@@ -222,7 +225,11 @@ class SenderCorrelationTest(TestCase):
non_existing_sender = 'Non-existing Sender <nonexisting at example.com>'
def mail(self, sender):
- return message_from_string('From: %s\nSubject: Test\n\ntest\n' % sender)
+ mail = 'Message-Id: %s\n' % make_msgid() + \
+ 'From: %s\n' % sender + \
+ 'Subject: Tests\n\n'\
+ 'test\n'
+ return message_from_string(mail)
def setUp(self):
self.existing_sender_mail = self.mail(self.existing_sender)
@@ -275,6 +282,7 @@ class MultipleProjectPatchTest(TestCase):
patch = read_patch(self.patch_filename)
email = create_email(self.test_comment + '\n' + patch)
+ del email['Message-Id']
email['Message-Id'] = self.msgid
del email['List-ID']
diff --git a/patchwork/tests/utils.py b/patchwork/tests/utils.py
index 782ed36..f7ea9c7 100644
--- a/patchwork/tests/utils.py
+++ b/patchwork/tests/utils.py
@@ -24,6 +24,8 @@ from django.contrib.auth.models import User
from django.forms.fields import EmailField
from email import message_from_file
+from email.utils import make_msgid
+
try:
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
@@ -107,6 +109,8 @@ def read_patch(filename, encoding = None):
def read_mail(filename, project = None):
file_path = os.path.join(_test_mail_dir, filename)
mail = message_from_file(open(file_path))
+ if 'Message-Id' not in mail:
+ mail['Message-Id'] = make_msgid()
if project is not None:
mail['List-Id'] = project.listid
return mail
@@ -130,6 +134,7 @@ def create_email(content, subject = None, sender = None, multipart = False,
else:
msg = MIMEText(content, _charset = content_encoding)
+ msg['Message-Id'] = make_msgid()
msg['Subject'] = subject
msg['From'] = sender
msg['List-Id'] = project.listid
--
2.1.0
More information about the Patchwork
mailing list