summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2008-09-20 14:11:49 +1000
committerJeremy Kerr <jk@ozlabs.org>2008-09-20 14:11:49 +1000
commit969d359e9c2f3eb5ee4741208ef17639d5e1b180 (patch)
treef04fa50a4622d54dc07bcec09cae8a47969dba25
parentb261b3cff0c7f4aacb6c9bda5f5491d340b1af17 (diff)
downloadpatchwork-969d359e9c2f3eb5ee4741208ef17639d5e1b180.tar.bz2
patchwork-969d359e9c2f3eb5ee4741208ef17639d5e1b180.tar.xz
[test] Move helper functions into tests/utils.py
So that we can use them for other tests Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
-rw-r--r--apps/patchwork/tests/patchparser.py52
-rw-r--r--apps/patchwork/tests/utils.py71
2 files changed, 83 insertions, 40 deletions
diff --git a/apps/patchwork/tests/patchparser.py b/apps/patchwork/tests/patchparser.py
index 6d315f0..649da0a 100644
--- a/apps/patchwork/tests/patchparser.py
+++ b/apps/patchwork/tests/patchparser.py
@@ -21,46 +21,18 @@ import unittest
import os
from email import message_from_string
from patchwork.models import Project, Person
+from patchwork.tests.utils import read_patch, create_email, defaults
try:
from email.mime.text import MIMEText
- from email.mime.multipart import MIMEMultipart
except ImportError:
# Python 2.4 compatibility
from email.MIMEText import MIMEText
- from email.MIMEMultipart import MIMEMultipart
-
-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()
-
+ default_sender = defaults.sender
+ default_subject = defaults.subject
+ project = defaults.project
from patchwork.bin.parsemail import find_content, find_author
@@ -69,8 +41,8 @@ class InlinePatchTest(PatchTest):
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.orig_patch = read_patch(self.patch_filename)
+ email = create_email(self.test_comment + '\n' + self.orig_patch)
(self.patch, self.comment) = find_content(self.project, email)
def testPatchPresence(self):
@@ -91,8 +63,8 @@ class AttachmentPatchTest(InlinePatchTest):
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)
+ self.orig_patch = read_patch(self.patch_filename)
+ email = 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)
@@ -103,8 +75,8 @@ class SignatureCommentTest(InlinePatchTest):
test_comment = 'Test comment\nmore comment'
def setUp(self):
- self.orig_patch = self.read_patch(self.patch_filename)
- email = self.create_email( \
+ self.orig_patch = read_patch(self.patch_filename)
+ email = create_email( \
self.test_comment + '\n' + \
'-- \nsig\n' + self.orig_patch)
(self.patch, self.comment) = find_content(self.project, email)
@@ -115,8 +87,8 @@ class ListFooterTest(InlinePatchTest):
test_comment = 'Test comment\nmore comment'
def setUp(self):
- self.orig_patch = self.read_patch(self.patch_filename)
- email = self.create_email( \
+ self.orig_patch = read_patch(self.patch_filename)
+ email = create_email( \
self.test_comment + '\n' + \
'_______________________________________________\n' + \
'Linuxppc-dev mailing list\n' + \
diff --git a/apps/patchwork/tests/utils.py b/apps/patchwork/tests/utils.py
new file mode 100644
index 0000000..c7be6ab
--- /dev/null
+++ b/apps/patchwork/tests/utils.py
@@ -0,0 +1,71 @@
+# 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 os
+from patchwork.models import Project
+try:
+ from email.mime.text import MIMEText
+ from email.mime.multipart import MIMEMultipart
+except ImportError:
+ # Python 2.4 compatibility
+ from email.MIMEText import MIMEText
+ from email.MIMEMultipart import MIMEMultipart
+
+# helper functions for tests
+_test_mail_dir = 'patchwork/tests/mail'
+_test_patch_dir = 'patchwork/tests/patches'
+
+class defaults(object):
+ project = Project(linkname = 'test-project', name = 'Test Project')
+
+ patch_author = 'Patch Author <patch-author@example.com>'
+
+ comment_author = 'Comment Author <comment-author@example.com>'
+
+ sender = 'Test Author <test-author@example.com>'
+
+ subject = 'Test Subject'
+
+ patch_name = 'Test Patch'
+
+
+def read_patch(filename):
+ return file(os.path.join(_test_patch_dir, filename)).read()
+
+def create_email(content, subject = None, sender = None, multipart = False,
+ project = None):
+ if subject is None:
+ subject = defaults.subject
+ if sender is None:
+ sender = defaults.sender
+ if project is None:
+ project = defaults.project
+
+ 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'] = project.linkname
+
+ return msg