]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
tests: Add test for updating tag counts in patch comments
authorAndrew Donnellan <andrew.donnellan@au1.ibm.com>
Sun, 20 Aug 2017 14:40:11 +0000 (00:40 +1000)
committerStephen Finucane <stephen@that.guru>
Wed, 23 Aug 2017 16:19:00 +0000 (17:19 +0100)
We accidentally broke the updating of tag counts for tags in comments, and
we didn't notice for quite a while.

Add a test for this.

Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Reviewed-by: Stephen Finucane <stephen@that.guru>
patchwork/tests/test_parser.py

index 52de351e60bd83059cc77a1430fbe82461cd857f..583dfcc4b4e8811130e723169dfc56c6cea4f111 100644 (file)
@@ -75,19 +75,22 @@ def read_mail(filename, project=None):
     return mail
 
 
-def _create_email(msg, msgid=None, sender=None, listid=None):
+def _create_email(msg, msgid=None, sender=None, listid=None, in_reply_to=None):
     msg['Message-Id'] = msgid or make_msgid()
     msg['Subject'] = 'Test subject'
     msg['From'] = sender or 'Test Author <test-author@example.com>'
     msg['List-Id'] = listid or 'test.example.com'
+    if in_reply_to:
+        msg['In-Reply-To'] = in_reply_to
 
     return msg
 
 
-def create_email(content, msgid=None, sender=None, listid=None):
+def create_email(content, msgid=None, sender=None, listid=None,
+                 in_reply_to=None):
     msg = MIMEText(content, _charset='us-ascii')
 
-    return _create_email(msg, msgid, sender, listid)
+    return _create_email(msg, msgid, sender, listid, in_reply_to)
 
 
 def parse_mail(*args, **kwargs):
@@ -767,6 +770,34 @@ class ParseInitialTagsTest(PatchTest):
             tag__name='Tested-by').count, 1)
 
 
+class ParseCommentTagsTest(PatchTest):
+    fixtures = ['default_tags']
+    patch_filename = '0001-add-line.patch'
+    comment_content = ('test comment\n\n' +
+                       'Tested-by: Test User <test@example.com>\n' +
+                       'Reviewed-by: Test User <test@example.com>\n')
+
+    def setUp(self):
+        project = create_project(listid='test.example.com')
+        self.orig_diff = read_patch(self.patch_filename)
+        email = create_email(self.orig_diff,
+                             listid=project.listid)
+        parse_mail(email)
+        email2 = create_email(self.comment_content,
+                              in_reply_to=email['Message-Id'])
+        parse_mail(email2)
+
+    def test_tags(self):
+        self.assertEqual(Patch.objects.count(), 1)
+        patch = Patch.objects.all()[0]
+        self.assertEqual(patch.patchtag_set.filter(
+            tag__name='Acked-by').count(), 0)
+        self.assertEqual(patch.patchtag_set.get(
+            tag__name='Reviewed-by').count, 1)
+        self.assertEqual(patch.patchtag_set.get(
+            tag__name='Tested-by').count, 1)
+
+
 class SubjectTest(TestCase):
 
     def test_clean_subject(self):