summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Finucane <stephen@that.guru>2020-11-28 16:34:01 +0000
committerStephen Finucane <stephen@that.guru>2020-11-28 16:59:48 +0000
commit70c9db8b9c1bee8ddc32eb1d6fceff6ef616ba3e (patch)
tree7dc3088d46ee3968c898fcfd15f687d205c83117
parentbdb049c7939b7cdea1eddf029a0bc47cb338da67 (diff)
downloadpatchwork-70c9db8b9c1bee8ddc32eb1d6fceff6ef616ba3e.tar
patchwork-70c9db8b9c1bee8ddc32eb1d6fceff6ef616ba3e.tar.gz
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 <stephen@that.guru> Fixes: 0686a736 ("models: Split 'CoverLetter' from 'Submission'") Closes: #384
-rw-r--r--patchwork/parser.py4
-rw-r--r--patchwork/tests/test_parser.py68
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)