X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=apps%2Fpatchwork%2Ftests%2Fpatchparser.py;h=953b94cfca8f23701541d8f46a85de29bd99e4a0;hb=e1a8a7db780c8250cfe36aa374d6f633653b6a08;hp=0fad67b2eecf7c6875a30cd7e6d3948fe4135bb3;hpb=74425beba0dc641509c5268571ea5328ac8185ec;p=patchwork diff --git a/apps/patchwork/tests/patchparser.py b/apps/patchwork/tests/patchparser.py index 0fad67b..953b94c 100644 --- a/apps/patchwork/tests/patchparser.py +++ b/apps/patchwork/tests/patchparser.py @@ -21,7 +21,7 @@ import unittest import os from email import message_from_string from patchwork.models import Project, Person, Patch, Comment -from patchwork.tests.utils import read_patch, create_email, defaults +from patchwork.tests.utils import read_patch, read_mail, create_email, defaults try: from email.mime.text import MIMEText @@ -34,7 +34,8 @@ class PatchTest(unittest.TestCase): default_subject = defaults.subject project = defaults.project -from patchwork.bin.parsemail import find_content, find_author, parse_mail +from patchwork.bin.parsemail import find_content, find_author, find_project, \ + parse_mail class InlinePatchTest(PatchTest): patch_filename = '0001-add-line.patch' @@ -172,6 +173,29 @@ class SenderUTF8QPSplitEncodingTest(SenderEncodingTest): class SenderUTF8B64EncodingTest(SenderUTF8QPEncodingTest): from_header = '=?utf-8?B?w6l4YW1wbGUgdXNlcg==?= ' +class SubjectEncodingTest(PatchTest): + sender = 'example user ' + subject = 'test subject' + subject_header = 'test subject' + + def setUp(self): + mail = 'From: %s\n' % self.sender + \ + 'Subject: %s\n\n' % self.subject_header + \ + 'test\n\n' + defaults.patch + self.projects = defaults.project + self.email = message_from_string(mail) + + def testSubjectEncoding(self): + (patch, comment) = find_content(self.project, self.email) + self.assertEquals(patch.name, self.subject) + +class SubjectUTF8QPEncodingTest(SubjectEncodingTest): + subject = u'test s\xfcbject' + subject_header = '=?utf-8?q?test=20s=c3=bcbject?=' + +class SubjectUTF8QPMultipleEncodingTest(SubjectEncodingTest): + subject = u'test s\xfcbject' + subject_header = 'test =?utf-8?q?s=c3=bcbject?=' class SenderCorrelationTest(unittest.TestCase): existing_sender = 'Existing Sender ' @@ -275,3 +299,64 @@ class MultipleProjectPatchCommentTest(MultipleProjectPatchTest): # and the one we parsed in setUp() self.assertEquals(Comment.objects.filter(patch = patch).count(), 2) +class ListIdHeaderTest(unittest.TestCase): + """ Test that we parse List-Id headers from mails correctly """ + def setUp(self): + self.project = Project(linkname = 'test-project-1', name = 'Project 1', + listid = '1.example.com', listemail='1@example.com') + self.project.save() + + def testNoListId(self): + email = MIMEText('') + project = find_project(email) + self.assertEquals(project, None) + + def testBlankListId(self): + email = MIMEText('') + email['List-Id'] = '' + project = find_project(email) + self.assertEquals(project, None) + + def testWhitespaceListId(self): + email = MIMEText('') + email['List-Id'] = ' ' + project = find_project(email) + self.assertEquals(project, None) + + def testSubstringListId(self): + email = MIMEText('') + email['List-Id'] = 'example.com' + project = find_project(email) + self.assertEquals(project, None) + + def testShortListId(self): + """ Some mailing lists have List-Id headers in short formats, where it + is only the list ID itself (without enclosing angle-brackets). """ + email = MIMEText('') + email['List-Id'] = self.project.listid + project = find_project(email) + self.assertEquals(project, self.project) + + def testLongListId(self): + email = MIMEText('') + email['List-Id'] = 'Test text <%s>' % self.project.listid + project = find_project(email) + self.assertEquals(project, self.project) + + def tearDown(self): + self.project.delete() + + +class GitPullTest(PatchTest): + mail_file = '0001-git-pull-request.mbox' + + def testGitPullRequest(self): + mail = read_mail(self.mail_file, project = self.project) + (patch, comment) = find_content(self.project, mail) + self.assertTrue(patch is not None) + self.assertTrue(patch.pull_url is not None) + self.assertTrue(patch.content is None) + self.assertTrue(comment is not None) + +class GitPullWrappedTest(GitPullTest): + mail_file = '0002-git-pull-request-wrapped.mbox'