From: Damien Lespiau Date: Thu, 5 Jun 2014 00:27:08 +0000 (+0100) Subject: tests: Make sure all emails have a valid msgid X-Git-Tag: v1.1.0~112 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2b76cce1d03ebfc12ff45fdc482e58652c8b378f;p=thirdparty%2Fpatchwork.git tests: Make sure all emails have a valid msgid 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 Acked-by: Stephen Finucane --- diff --git a/patchwork/tests/test_patchparser.py b/patchwork/tests/test_patchparser.py index a49bf9b8..2b8f9d2f 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 @@ -141,7 +142,8 @@ class SenderEncodingTest(TestCase): from_header = 'example user ' 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) @@ -183,7 +185,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 @@ -206,7 +209,11 @@ class SenderCorrelationTest(TestCase): non_existing_sender = 'Non-existing Sender ' 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) @@ -259,6 +266,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 15ca3aa0..4f4906b5 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