[PATCH 05/15] tests: Make sure all emails have a valid msgid

Damien Lespiau damien.lespiau at intel.com
Fri Oct 9 21:39:52 AEDT 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.

v2: Rebase on top upstream

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 fe1fd2a..ab02759 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
@@ -153,7 +154,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)
@@ -195,7 +197,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
@@ -218,7 +221,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)
@@ -271,6 +278,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 15ca3aa..4f4906b 100644
--- a/patchwork/tests/utils.py
+++ b/patchwork/tests/utils.py
@@ -26,6 +26,8 @@ from django.forms.fields import EmailField
 from email import message_from_file
 from email.mime.text import MIMEText
 from email.mime.multipart import MIMEMultipart
+from email.utils import make_msgid
+
 
 # helper functions for tests
 _test_mail_dir  = os.path.join(os.path.dirname(__file__), 'mail')
@@ -102,6 +104,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
@@ -125,6 +129,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