~patchwork-devs/patchwork/patchwork

« back to all changes in this revision

Viewing changes to patchwork/tests/test_parser.py

  • Committer: Stephen Finucane
  • Date: 2021-10-28 10:43:35 UTC
  • Revision ID: git-v1:f5cd52144cd4cbd0dd2c9cbcecdb90e6d25cbc17
parser: Add 'X-Patchwork-Action-Required' header

Allow submitters to indicate that their comment is something that needs
to be addressed.

Some minors issues are addressed in the docs while we're here.

Signed-off-by: Stephen Finucane <stephen@that.guru>

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
from django.db import connection
19
19
 
20
20
from patchwork.models import Cover
 
21
from patchwork.models import CoverComment
21
22
from patchwork.models import Patch
22
23
from patchwork.models import PatchComment
23
24
from patchwork.models import Person
68
69
    return mail
69
70
 
70
71
 
71
 
def _create_email(msg, msgid=None, sender=None, listid=None, in_reply_to=None):
 
72
def _create_email(
 
73
    msg,
 
74
    msgid=None,
 
75
    subject=None,
 
76
    sender=None,
 
77
    listid=None,
 
78
    in_reply_to=None,
 
79
    headers=None,
 
80
):
72
81
    msg['Message-Id'] = msgid or make_msgid()
73
 
    msg['Subject'] = 'Test subject'
 
82
    msg['Subject'] = subject or 'Test subject'
74
83
    msg['From'] = sender or 'Test Author <test-author@example.com>'
75
84
    msg['List-Id'] = listid or 'test.example.com'
 
85
 
76
86
    if in_reply_to:
77
87
        msg['In-Reply-To'] = in_reply_to
78
88
 
 
89
    for header in headers or {}:
 
90
        msg[header] = headers[header]
 
91
 
79
92
    return msg
80
93
 
81
94
 
82
 
def create_email(content, msgid=None, sender=None, listid=None,
83
 
                 in_reply_to=None):
 
95
def create_email(
 
96
    content,
 
97
    msgid=None,
 
98
    subject=None,
 
99
    sender=None,
 
100
    listid=None,
 
101
    in_reply_to=None,
 
102
    headers=None,
 
103
):
84
104
    msg = MIMEText(content, _charset='us-ascii')
85
105
 
86
 
    return _create_email(msg, msgid, sender, listid, in_reply_to)
 
106
    return _create_email(
 
107
        msg, msgid, subject, sender, listid, in_reply_to, headers)
87
108
 
88
109
 
89
110
def parse_mail(*args, **kwargs):
821
842
        self.assertDelegate(None)
822
843
 
823
844
 
 
845
class CommentActionRequiredTest(TestCase):
 
846
 
 
847
    fixtures = ['default_tags']
 
848
 
 
849
    def setUp(self):
 
850
        self.project = create_project(listid='test.example.com')
 
851
 
 
852
    def _create_submission_and_comments(self, submission_email):
 
853
        comment_a_email = create_email(
 
854
            'test comment\n',
 
855
            in_reply_to=submission_email['Message-Id'],
 
856
            listid=self.project.listid,
 
857
            headers={},
 
858
        )
 
859
        comment_b_email = create_email(
 
860
            'another test comment\n',
 
861
            in_reply_to=submission_email['Message-Id'],
 
862
            listid=self.project.listid,
 
863
            headers={'X-Patchwork-Action-Required': ''},
 
864
        )
 
865
        parse_mail(submission_email)
 
866
        parse_mail(comment_a_email)
 
867
        parse_mail(comment_b_email)
 
868
 
 
869
        comment_a_msgid = comment_a_email.get('Message-ID')
 
870
        comment_b_msgid = comment_b_email.get('Message-ID')
 
871
 
 
872
        return comment_a_msgid, comment_b_msgid
 
873
 
 
874
    def test_patch_comment(self):
 
875
        body = read_patch('0001-add-line.patch')
 
876
        patch_email = create_email(body, listid=self.project.listid)
 
877
        comment_a_msgid, comment_b_msgid = \
 
878
            self._create_submission_and_comments(patch_email)
 
879
 
 
880
        self.assertEqual(1, Patch.objects.count())
 
881
        self.assertEqual(2, PatchComment.objects.count())
 
882
        comment_a = PatchComment.objects.get(msgid=comment_a_msgid)
 
883
        self.assertIsNone(comment_a.addressed)
 
884
        comment_b = PatchComment.objects.get(msgid=comment_b_msgid)
 
885
        self.assertFalse(comment_b.addressed)
 
886
 
 
887
    def test_cover_comment(self):
 
888
        cover_email = create_email(
 
889
            'test cover letter',
 
890
            subject='[0/2] A cover letter',
 
891
            listid=self.project.listid)
 
892
        comment_a_msgid, comment_b_msgid = \
 
893
            self._create_submission_and_comments(cover_email)
 
894
 
 
895
        self.assertEqual(1, Cover.objects.count())
 
896
        self.assertEqual(2, CoverComment.objects.count())
 
897
        comment_a = CoverComment.objects.get(msgid=comment_a_msgid)
 
898
        self.assertIsNone(comment_a.addressed)
 
899
        comment_b = CoverComment.objects.get(msgid=comment_b_msgid)
 
900
        self.assertFalse(comment_b.addressed)
 
901
 
 
902
 
824
903
class InitialPatchStateTest(TestCase):
825
904
 
826
905
    patch_filename = '0001-add-line.patch'