From 70c9db8b9c1bee8ddc32eb1d6fceff6ef616ba3e Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Sat, 28 Nov 2020 16:34:01 +0000 Subject: parser: Update reference to PatchComment 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 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 a/patchwork/parser.py b/patchwork/parser.py index 6d33bcd..61a8124 100644 --- a/patchwork/parser.py +++ b/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 a/patchwork/tests/test_parser.py b/patchwork/tests/test_parser.py index 99e27f1..eaf6599 100644 --- a/patchwork/tests/test_parser.py +++ b/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) -- cgit v1.2.3