[PATCH] parser: Update reference to PatchComment

Stephen Finucane stephen at that.guru
Sun Nov 29 04:02:00 AEDT 2020


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 at that.guru>
Fixes: 0686a736 ("models: Split 'CoverLetter' from 'Submission'")
Closes: #384
---
 patchwork/parser.py            |  4 +-
 patchwork/tests/test_parser.py | 68 ++++++++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+), 2 deletions(-)

diff --git patchwork/parser.py patchwork/parser.py
index 6d33bcd4..61a81246 100644
--- patchwork/parser.py
+++ patchwork/parser.py
@@ -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
 
diff --git patchwork/tests/test_parser.py patchwork/tests/test_parser.py
index 99e27f10..eaf6599c 100644
--- patchwork/tests/test_parser.py
+++ patchwork/tests/test_parser.py
@@ -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)
-- 
2.28.0



More information about the Patchwork mailing list