]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
parser: Update reference to PatchComment
authorStephen Finucane <stephen@that.guru>
Sat, 28 Nov 2020 16:34:01 +0000 (16:34 +0000)
committerStephen Finucane <stephen@that.guru>
Sat, 28 Nov 2020 16:59:48 +0000 (16:59 +0000)
Commit 0686a736fbf6d869bd31bd135ba38080ac96de22 split out 'CoverLetter'
from the old 'Submission' model, removing the common 'Comment' model in
favour of distinct 'CoverComment' and 'PatchComment' models in the
process. Unfortunately we misssed some references to the old model in
the 'patchwork.parser' module. Correct these now, adding unit tests to
prevent regressions.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Fixes: 0686a736 ("models: Split 'CoverLetter' from 'Submission'")
Closes: #384
patchwork/parser.py
patchwork/tests/test_parser.py

index 6d33bcd46efdd5463692658cefee1109b141de16..61a812461312f9a5620a8b3db811f6c8a9eee27e 100644 (file)
@@ -668,7 +668,7 @@ def find_patch_for_comment(project, refs):
                 patch__project=project,
                 msgid=ref,
             )
-            return comment.submission
+            return comment.patch
         except PatchComment.MultipleObjectsReturned:
             # NOTE(stephenfin): This is a artifact of prior lack of support
             # for cover letters in Patchwork. Previously all replies to
@@ -688,7 +688,7 @@ def find_patch_for_comment(project, refs):
                 msgid=ref,
             )
             # The latter item will be the cover letter
-            return comments.reverse()[0].submission
+            return comments.reverse()[0].patch
         except PatchComment.DoesNotExist:
             pass
 
index 99e27f10da8031dcba5abab7f67c25ea27b5bacc..eaf6599c5817e0e6255b05cdd485a1ddf1daf30e 100644 (file)
@@ -22,6 +22,7 @@ from patchwork.models import Patch
 from patchwork.models import PatchComment
 from patchwork.models import Person
 from patchwork.models import State
+from patchwork import parser
 from patchwork.parser import clean_subject
 from patchwork.parser import get_or_create_author
 from patchwork.parser import find_patch_content as find_content
@@ -37,6 +38,10 @@ from patchwork.parser import subject_check
 from patchwork.parser import DuplicateMailError
 from patchwork.tests import TEST_MAIL_DIR
 from patchwork.tests import TEST_FUZZ_DIR
+from patchwork.tests.utils import create_cover
+from patchwork.tests.utils import create_cover_comment
+from patchwork.tests.utils import create_patch
+from patchwork.tests.utils import create_patch_comment
 from patchwork.tests.utils import create_project
 from patchwork.tests.utils import create_series
 from patchwork.tests.utils import create_series_reference
@@ -1167,3 +1172,66 @@ class DuplicateMailTest(TestCase):
         self._test_duplicate_mail(m)
 
         self.assertEqual(Cover.objects.count(), 1)
+
+
+class TestCommentCorrelation(TestCase):
+
+    def test_find_patch_for_comment__no_reply(self):
+        """Test behavior for mails that don't match anything we have."""
+        project = create_project()
+        create_patch(project=project)
+
+        result = parser.find_patch_for_comment(project, ['foo'])
+
+        self.assertIsNone(result)
+
+    def test_find_patch_for_comment__direct_reply(self):
+        """Test behavior when we have a reference to the original patch."""
+        msgid = make_msgid()
+        project = create_project()
+        patch = create_patch(msgid=msgid, project=project)
+
+        result = parser.find_patch_for_comment(project, [msgid])
+
+        self.assertEqual(patch, result)
+
+    def test_find_patch_for_comment__indirect_reply(self):
+        """Test behavior when we only have a reference to a comment."""
+        msgid = make_msgid()
+        project = create_project()
+        patch = create_patch(project=project)
+        create_patch_comment(patch=patch, msgid=msgid)
+
+        result = parser.find_patch_for_comment(project, [msgid])
+
+        self.assertEqual(patch, result)
+
+    def test_find_cover_for_comment__no_reply(self):
+        """Test behavior for mails that don't match anything we have."""
+        project = create_project()
+        create_cover(project=project)
+
+        result = parser.find_cover_for_comment(project, ['foo'])
+
+        self.assertIsNone(result)
+
+    def test_find_cover_for_comment__direct_reply(self):
+        """Test behavior when we have a reference to the original cover."""
+        msgid = make_msgid()
+        project = create_project()
+        cover = create_cover(msgid=msgid, project=project)
+
+        result = parser.find_cover_for_comment(project, [msgid])
+
+        self.assertEqual(cover, result)
+
+    def test_find_cover_for_comment__indirect_reply(self):
+        """Test behavior when we only have a reference to a comment."""
+        msgid = make_msgid()
+        project = create_project()
+        cover = create_cover(project=project)
+        create_cover_comment(cover=cover, msgid=msgid)
+
+        result = parser.find_cover_for_comment(project, [msgid])
+
+        self.assertEqual(cover, result)