split_re = re.compile('[,\s]+')
def split_prefixes(prefix):
- """ Turn a prefix string into a list of prefix tokens
-
- >>> split_prefixes('PATCH')
- ['PATCH']
- >>> split_prefixes('PATCH,RFC')
- ['PATCH', 'RFC']
- >>> split_prefixes('')
- []
- >>> split_prefixes('PATCH,')
- ['PATCH']
- >>> split_prefixes('PATCH ')
- ['PATCH']
- >>> split_prefixes('PATCH,RFC')
- ['PATCH', 'RFC']
- >>> split_prefixes('PATCH 1/2')
- ['PATCH', '1/2']
- """
+ """ Turn a prefix string into a list of prefix tokens """
+
matches = split_re.split(prefix)
return [ s for s in matches if s != '' ]
Removes Re: and Fwd: strings, as well as [PATCH]-style prefixes. By
default, only [PATCH] is removed, and we keep any other bracketed data
in the subject. If drop_prefixes is provided, remove those too,
- comparing case-insensitively.
-
- >>> clean_subject('meep')
- 'meep'
- >>> clean_subject('Re: meep')
- 'meep'
- >>> clean_subject('[PATCH] meep')
- 'meep'
- >>> clean_subject('[PATCH] meep \\n meep')
- 'meep meep'
- >>> clean_subject('[PATCH RFC] meep')
- '[RFC] meep'
- >>> clean_subject('[PATCH,RFC] meep')
- '[RFC] meep'
- >>> clean_subject('[PATCH,1/2] meep')
- '[1/2] meep'
- >>> clean_subject('[PATCH RFC 1/2] meep')
- '[RFC,1/2] meep'
- >>> clean_subject('[PATCH] [RFC] meep')
- '[RFC] meep'
- >>> clean_subject('[PATCH] [RFC,1/2] meep')
- '[RFC,1/2] meep'
- >>> clean_subject('[PATCH] [RFC] [1/2] meep')
- '[RFC,1/2] meep'
- >>> clean_subject('[PATCH] rewrite [a-z] regexes')
- 'rewrite [a-z] regexes'
- >>> clean_subject('[PATCH] [RFC] rewrite [a-z] regexes')
- '[RFC] rewrite [a-z] regexes'
- >>> clean_subject('[foo] [bar] meep', ['foo'])
- '[bar] meep'
- >>> clean_subject('[FOO] [bar] meep', ['foo'])
- '[bar] meep'
- """
+ comparing case-insensitively."""
+
subject = clean_header(subject)
# the scheme based on current access. This is useful if SSL protocol
# is terminated upstream of the server (e.g. at the load balancer)
FORCE_HTTPS_LINKS = False
+
+TEST_RUNNER = 'django.test.runner.DiscoverRunner'
},
}
-if django.VERSION >= (1, 7):
- TEST_RUNNER = 'django.test.runner.DiscoverRunner'
-
#
# Patchwork settings
#
-# 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
-
-from patchwork.tests.test_patchparser import *
-from patchwork.tests.test_tags import *
-from patchwork.tests.test_encodings import *
-from patchwork.tests.test_bundles import *
-from patchwork.tests.test_mboxviews import *
-from patchwork.tests.test_updates import *
-from patchwork.tests.test_filters import *
-from patchwork.tests.test_confirm import *
-from patchwork.tests.test_registration import *
-from patchwork.tests.test_user import *
-from patchwork.tests.test_mail_settings import *
-from patchwork.tests.test_notifications import *
-from patchwork.tests.test_list import *
-from patchwork.tests.test_person import *
-from patchwork.tests.test_expiry import *
-from patchwork.tests.test_xmlrpc import *
project = defaults.project
from patchwork.bin.parsemail import find_content, find_author, find_project, \
- parse_mail
+ parse_mail, split_prefixes, clean_subject
class InlinePatchTest(PatchTest):
patch_filename = '0001-add-line.patch'
tag__name='Reviewed-by').count, 1)
self.assertEquals(patch.patchtag_set.get(
tag__name='Tested-by').count, 1)
+
+class PrefixTest(TestCase):
+
+ def testSplitPrefixes(self):
+ self.assertEquals(split_prefixes('PATCH'), ['PATCH'])
+ self.assertEquals(split_prefixes('PATCH,RFC'), ['PATCH', 'RFC'])
+ self.assertEquals(split_prefixes(''), [])
+ self.assertEquals(split_prefixes('PATCH,'), ['PATCH'])
+ self.assertEquals(split_prefixes('PATCH '), ['PATCH'])
+ self.assertEquals(split_prefixes('PATCH,RFC'), ['PATCH', 'RFC'])
+ self.assertEquals(split_prefixes('PATCH 1/2'), ['PATCH', '1/2'])
+
+class SubjectTest(TestCase):
+
+ def testCleanSubject(self):
+ self.assertEquals(clean_subject('meep'), 'meep')
+ self.assertEquals(clean_subject('Re: meep'), 'meep')
+ self.assertEquals(clean_subject('[PATCH] meep'), 'meep')
+ self.assertEquals(clean_subject('[PATCH] meep \n meep'), 'meep meep')
+ self.assertEquals(clean_subject('[PATCH RFC] meep'), '[RFC] meep')
+ self.assertEquals(clean_subject('[PATCH,RFC] meep'), '[RFC] meep')
+ self.assertEquals(clean_subject('[PATCH,1/2] meep'), '[1/2] meep')
+ self.assertEquals(clean_subject('[PATCH RFC 1/2] meep'),
+ '[RFC,1/2] meep')
+ self.assertEquals(clean_subject('[PATCH] [RFC] meep'),
+ '[RFC] meep')
+ self.assertEquals(clean_subject('[PATCH] [RFC,1/2] meep'),
+ '[RFC,1/2] meep')
+ self.assertEquals(clean_subject('[PATCH] [RFC] [1/2] meep'),
+ '[RFC,1/2] meep')
+ self.assertEquals(clean_subject('[PATCH] rewrite [a-z] regexes'),
+ 'rewrite [a-z] regexes')
+ self.assertEquals(clean_subject('[PATCH] [RFC] rewrite [a-z] regexes'),
+ '[RFC] rewrite [a-z] regexes')
+ self.assertEquals(clean_subject('[foo] [bar] meep', ['foo']),
+ '[bar] meep')
+ self.assertEquals(clean_subject('[FOO] [bar] meep', ['foo']),
+ '[bar] meep')