71
def _create_email(msg, msgid=None, sender=None, listid=None, in_reply_to=None):
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'
77
87
msg['In-Reply-To'] = in_reply_to
89
for header in headers or {}:
90
msg[header] = headers[header]
82
def create_email(content, msgid=None, sender=None, listid=None,
84
104
msg = MIMEText(content, _charset='us-ascii')
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)
89
110
def parse_mail(*args, **kwargs):
821
842
self.assertDelegate(None)
845
class CommentActionRequiredTest(TestCase):
847
fixtures = ['default_tags']
850
self.project = create_project(listid='test.example.com')
852
def _create_submission_and_comments(self, submission_email):
853
comment_a_email = create_email(
855
in_reply_to=submission_email['Message-Id'],
856
listid=self.project.listid,
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': ''},
865
parse_mail(submission_email)
866
parse_mail(comment_a_email)
867
parse_mail(comment_b_email)
869
comment_a_msgid = comment_a_email.get('Message-ID')
870
comment_b_msgid = comment_b_email.get('Message-ID')
872
return comment_a_msgid, comment_b_msgid
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)
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)
887
def test_cover_comment(self):
888
cover_email = create_email(
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)
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)
824
903
class InitialPatchStateTest(TestCase):
826
905
patch_filename = '0001-add-line.patch'