summaryrefslogtreecommitdiffstats
path: root/apps/patchwork
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2008-09-19 18:10:52 +1000
committerJeremy Kerr <jk@ozlabs.org>2008-09-19 18:10:52 +1000
commitb537242352ca645916c807ea71a3094758d6b9d8 (patch)
tree7b7f09700cfb154865d6ade22271a749d190cc8f /apps/patchwork
parent9b7216bc0bd74b30796cdb64ce8b39a6110c9157 (diff)
downloadpatchwork-b537242352ca645916c807ea71a3094758d6b9d8.tar.bz2
patchwork-b537242352ca645916c807ea71a3094758d6b9d8.tar.xz
[test] Add patchwork testing infrastructure
Add a small set of initial tests for the patch parsing code. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'apps/patchwork')
-rw-r--r--apps/patchwork/tests/__init__.py33
-rw-r--r--apps/patchwork/tests/patches/0001-add-line.patch7
-rw-r--r--apps/patchwork/tests/patchparser.py91
3 files changed, 131 insertions, 0 deletions
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 <jk@ozlabs.org>
+#
+# 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 <jk@ozlabs.org>
+#
+# 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 <test@exmaple.com>'
+ 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)