1 # Patchwork - automated patch tracking system
2 # Copyright (C) 2008 Jeremy Kerr <jk@ozlabs.org>
4 # This file is part of the Patchwork package.
6 # Patchwork is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # Patchwork is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with Patchwork; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 from email.mime.text import MIMEText
23 from email.mime.multipart import MIMEMultipart
24 from patchwork.models import Project
26 test_mail_dir = 'patchwork/tests/mail'
27 test_patch_dir = 'patchwork/tests/patches'
29 class PatchTest(unittest.TestCase):
30 default_sender = 'Test Author <test@exmaple.com>'
31 default_subject = 'Test Subject'
32 project = Project(linkname = 'test-project')
34 def create_email(self, content, subject = None, sender = None,
37 subject = self.default_subject
39 sender = self.default_sender
43 body = MIMEText(content, _subtype = 'plain')
46 msg = MIMEText(content)
48 msg['Subject'] = subject
50 msg['List-Id'] = self.project.linkname
54 def read_patch(self, filename):
55 return file(os.path.join(test_patch_dir, filename)).read()
58 from patchwork.bin.parsemail import find_content
60 class InlinePatchTest(PatchTest):
61 patch_filename = '0001-add-line.patch'
62 test_comment = 'Test for attached patch'
65 self.orig_patch = self.read_patch(self.patch_filename)
66 email = self.create_email(self.test_comment + '\n' + self.orig_patch)
67 (self.patch, self.comment) = find_content(self.project, email)
69 def testPatchPresence(self):
70 self.assertTrue(self.patch is not None)
72 def testPatchContent(self):
73 self.assertEquals(self.patch.content, self.orig_patch)
75 def testCommentPresence(self):
76 self.assertTrue(self.comment is not None)
78 def testCommentContent(self):
79 self.assertEquals(self.comment.content, self.test_comment)
82 class AttachmentPatchTest(InlinePatchTest):
83 patch_filename = '0001-add-line.patch'
84 test_comment = 'Test for attached patch'
87 self.orig_patch = self.read_patch(self.patch_filename)
88 email = self.create_email(self.test_comment, multipart = True)
89 attachment = MIMEText(self.orig_patch, _subtype = 'x-patch')
90 email.attach(attachment)
91 (self.patch, self.comment) = find_content(self.project, email)
94 class SignatureCommentTest(InlinePatchTest):
95 patch_filename = '0001-add-line.patch'
96 test_comment = 'Test comment\nmore comment'
99 self.orig_patch = self.read_patch(self.patch_filename)
100 email = self.create_email( \
101 self.test_comment + '\n' + \
102 '-- \nsig\n' + self.orig_patch)
103 (self.patch, self.comment) = find_content(self.project, email)