summaryrefslogtreecommitdiffstats
path: root/patchwork/tests/test_patchparser.py
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2015-05-27 09:56:36 +0800
committerJeremy Kerr <jk@ozlabs.org>2015-05-28 09:05:45 +0800
commit3b8a61c68fa61eadebf7b19329e8d3bffde9e6b4 (patch)
tree88f53364498523371c2bd1fc33b2e0dbbbb41372 /patchwork/tests/test_patchparser.py
parentdaa3ae42eee5e569881070bcc2958b361743f70a (diff)
downloadpatchwork-3b8a61c68fa61eadebf7b19329e8d3bffde9e6b4.tar.bz2
patchwork-3b8a61c68fa61eadebf7b19329e8d3bffde9e6b4.tar.xz
Add patch tag infrastructure
This change add patch 'tags', eg 'Acked-by' / 'Reviewed-by', etc., to patchwork. Tag parsing is implemented in the patch parser's extract_tags function, which returns a Counter object of the tags in a comment. These are stored in the PatchTag (keyed to Tag) objects associated with each patch. We need to ensure that the main patch lists do not cause per-patch queries on the Patch.tags ManyToManyField (this would result in ~500 queries per page), so we introduce a new QuerySet (and Manager) for Patch, adding a with_tag_counts() method to populate the tag counts in a single query. As users may be migrating from previous patchwork versions (ie, with no tag counts in the database), we add a 'retag' management command. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'patchwork/tests/test_patchparser.py')
-rw-r--r--patchwork/tests/test_patchparser.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/patchwork/tests/test_patchparser.py b/patchwork/tests/test_patchparser.py
index 119936a..5eefeb5 100644
--- a/patchwork/tests/test_patchparser.py
+++ b/patchwork/tests/test_patchparser.py
@@ -552,3 +552,30 @@ class InitialPatchStateTest(TestCase):
def tearDown(self):
self.p1.delete()
self.user.delete()
+
+class ParseInitialTagsTest(PatchTest):
+ patch_filename = '0001-add-line.patch'
+ test_comment = ('test comment\n\n' +
+ 'Tested-by: Test User <test@example.com>\n' +
+ 'Reviewed-by: Test User <test@example.com>\n')
+ fixtures = ['default_tags']
+
+ def setUp(self):
+ project = defaults.project
+ project.listid = 'test.example.com'
+ project.save()
+ self.orig_patch = read_patch(self.patch_filename)
+ email = create_email(self.test_comment + '\n' + self.orig_patch,
+ project = project)
+ email['Message-Id'] = '<1@example.com>'
+ parse_mail(email)
+
+ def testTags(self):
+ self.assertEquals(Patch.objects.count(), 1)
+ patch = Patch.objects.all()[0]
+ self.assertEquals(patch.patchtag_set.filter(
+ tag__name='Acked-by').count(), 0)
+ self.assertEquals(patch.patchtag_set.get(
+ tag__name='Reviewed-by').count, 1)
+ self.assertEquals(patch.patchtag_set.get(
+ tag__name='Tested-by').count, 1)