From 3b8a61c68fa61eadebf7b19329e8d3bffde9e6b4 Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Wed, 27 May 2015 09:56:36 +0800 Subject: 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 --- patchwork/tests/test_patchparser.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'patchwork/tests/test_patchparser.py') 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 \n' + + 'Reviewed-by: Test User \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) -- cgit v1.2.3