From: Jeremy Kerr Date: Fri, 19 Sep 2008 08:10:52 +0000 (+1000) Subject: [test] Add patchwork testing infrastructure X-Git-Url: http://git.ozlabs.org/?p=patchwork;a=commitdiff_plain;h=b537242352ca645916c807ea71a3094758d6b9d8 [test] Add patchwork testing infrastructure Add a small set of initial tests for the patch parsing code. Signed-off-by: Jeremy Kerr --- diff --git a/apps/patchwork/tests/__init__.py b/apps/patchwork/tests/__init__.py new file mode 100644 index 0000000..42413a1 --- /dev/null +++ b/apps/patchwork/tests/__init__.py @@ -0,0 +1,33 @@ +# Patchwork - automated patch tracking system +# Copyright (C) 2008 Jeremy Kerr +# +# This file is part of the Patchwork package. +# +# Patchwork is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# Patchwork is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Patchwork; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +import unittest +from patchwork.tests import patchparser + +modules = [patchparser] + +def suite(): + suite = unittest.TestSuite() + loader = unittest.TestLoader() + + for module in modules: + tests = loader.loadTestsFromModule(module) + suite.addTests(tests) + + return suite diff --git a/apps/patchwork/tests/patches/0001-add-line.patch b/apps/patchwork/tests/patches/0001-add-line.patch new file mode 100644 index 0000000..c6cb9f1 --- /dev/null +++ b/apps/patchwork/tests/patches/0001-add-line.patch @@ -0,0 +1,7 @@ +diff --git a/meep.text b/meep.text +index 3d75d48..a57f4dd 100644 +--- a/meep.text ++++ b/meep.text +@@ -1,1 +1,2 @@ + meep ++meep diff --git a/apps/patchwork/tests/patchparser.py b/apps/patchwork/tests/patchparser.py new file mode 100644 index 0000000..19b7aea --- /dev/null +++ b/apps/patchwork/tests/patchparser.py @@ -0,0 +1,91 @@ +# Patchwork - automated patch tracking system +# Copyright (C) 2008 Jeremy Kerr +# +# This file is part of the Patchwork package. +# +# Patchwork is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# Patchwork is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Patchwork; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +import unittest +import os +from email.mime.text import MIMEText +from email.mime.multipart import MIMEMultipart +from patchwork.models import Project + +test_mail_dir = 'patchwork/tests/mail' +test_patch_dir = 'patchwork/tests/patches' + +class PatchTest(unittest.TestCase): + default_sender = 'Test Author ' + default_subject = 'Test Subject' + project = Project(linkname = 'test-project') + + def create_email(self, content, subject = None, sender = None, + multipart = False): + if subject is None: + subject = self.default_subject + if sender is None: + sender = self.default_sender + + if multipart: + msg = MIMEMultipart() + body = MIMEText(content, _subtype = 'plain') + msg.attach(body) + else: + msg = MIMEText(content) + + msg['Subject'] = subject + msg['From'] = sender + msg['List-Id'] = self.project.linkname + + return msg + + def read_patch(self, filename): + return file(os.path.join(test_patch_dir, filename)).read() + + +from patchwork.bin.parsemail import find_content + +class InlinePatchTest(PatchTest): + patch_filename = '0001-add-line.patch' + test_comment = 'Test for attached patch' + + def setUp(self): + self.orig_patch = self.read_patch(self.patch_filename) + email = self.create_email(self.test_comment + '\n' + self.orig_patch) + (self.patch, self.comment) = find_content(self.project, email) + + def testPatchPresence(self): + self.assertTrue(self.patch is not None) + + def testPatchContent(self): + self.assertEquals(self.patch.content, self.orig_patch) + + def testCommentPresence(self): + self.assertTrue(self.comment is not None) + + def testCommentContent(self): + self.assertEquals(self.comment.content, self.test_comment) + + +class AttachmentPatchTest(InlinePatchTest): + patch_filename = '0001-add-line.patch' + test_comment = 'Test for attached patch' + + def setUp(self): + self.orig_patch = self.read_patch(self.patch_filename) + email = self.create_email(self.test_comment, multipart = True) + attachment = MIMEText(self.orig_patch, _subtype = 'x-patch') + email.attach(attachment) + (self.patch, self.comment) = find_content(self.project, email)