예제 #1
0
 def test_subjectWithStringExpansions(self):
     # The mailer should not attempt to expand templates in the subject.
     comment, subscriber = self.makeCommentAndSubscriber(
         subject='A %(carefully)s constructed subject')
     mailer = CodeReviewCommentMailer.forCreation(comment)
     self.assertEqual('A %(carefully)s constructed subject',
                      mailer._getSubject(email=None, recipient=subscriber))
예제 #2
0
 def makeMailer(self, body=None, as_reply=False, vote=None, vote_tag=None):
     """Return a CodeReviewCommentMailer and the sole subscriber."""
     comment, subscriber = self.makeCommentAndSubscriber(body=body,
                                                         as_reply=as_reply,
                                                         vote=vote,
                                                         vote_tag=vote_tag)
     return CodeReviewCommentMailer.forCreation(comment), subscriber
    def test_generateEmailWithInlineComments(self):
        """Review comments emails consider the inline comments.

        See `build_inline_comments_section` tests for formatting details.
        """
        comment = self.makeCommentWithInlineComments(
            inline_comments={'3': 'Is this from Pl\u0060net Earth ?'})
        switch_dbuser(config.IBranchMergeProposalJobSource.dbuser)
        mailer = CodeReviewCommentMailer.forCreation(comment)
        commenter = comment.branch_merge_proposal.registrant
        ctrl = mailer.generateEmail(commenter.preferredemail.email, commenter)

        expected_lines = [
            '',
            'Diff comments:',
            '',
            ("> === zbqvsvrq svyr 'yvo/yc/pbqr/vagresnprf/qvss.cl'"),
            ('> --- yvo/yc/pbqr/vagresnprf/qvss.cl      '
             '2009-10-01 13:25:12 +0000'),
            ('> +++ yvo/yc/pbqr/vagresnprf/qvss.cl      '
             '2010-02-02 15:48:56 +0000'),
            '',
            'Is this from Pl\u0060net Earth ?',
            '',
        ]
        self.assertEqual(expected_lines, ctrl.body.splitlines()[1:10])
 def makeMailer(self, body=None, as_reply=False, vote=None, vote_tag=None):
     """Return a CodeReviewCommentMailer and the sole subscriber."""
     comment, subscriber = self.makeCommentAndSubscriber(body=body,
                                                         as_reply=as_reply,
                                                         vote=vote,
                                                         vote_tag=vote_tag)
     switch_dbuser(config.IBranchMergeProposalJobSource.dbuser)
     return CodeReviewCommentMailer.forCreation(comment), subscriber
 def test_subjectWithStringExpansions(self):
     # The mailer should not attempt to expand templates in the subject.
     comment, subscriber = self.makeCommentAndSubscriber(
         subject='A %(carefully)s constructed subject')
     mailer = CodeReviewCommentMailer.forCreation(comment)
     self.assertEqual(
         'A %(carefully)s constructed subject',
         mailer._getSubject(email=None, recipient=subscriber))
예제 #6
0
 def test_getToAddresses_no_parent(self):
     """To address for a comment with no parent should be the proposer."""
     comment = self.makeCommentAndParticipants()
     mailer = CodeReviewCommentMailer.forCreation(comment)
     to = mailer._getToAddresses(comment.message.owner, '*****@*****.**')
     self.assertEqual(['Proposer <*****@*****.**>'], to)
     to = mailer._getToAddresses(comment.branch_merge_proposal.registrant,
                                 '*****@*****.**')
     self.assertEqual(['Proposer <*****@*****.**>'], to)
예제 #7
0
 def test_nonReplyCommentUsesRootMessageId(self):
     """Ensure mailer's generateEmail method produces expected values."""
     comment, subscriber = self.makeCommentAndSubscriber()
     second_comment = self.factory.makeCodeReviewComment(
         merge_proposal=comment.branch_merge_proposal)
     mailer = CodeReviewCommentMailer.forCreation(second_comment)
     ctrl = mailer.generateEmail(subscriber.preferredemail.email,
                                 subscriber)
     self.assertEqual(comment.branch_merge_proposal.root_message_id,
                      ctrl.headers['In-Reply-To'])
예제 #8
0
 def test_forCreationStatusNoEmail(self):
     """Ensure that subscriptions with NOEMAIL aren't used."""
     comment, subscriber = self.makeCommentAndSubscriber(
         CodeReviewNotificationLevel.NOEMAIL)
     mailer = CodeReviewCommentMailer.forCreation(comment)
     bmp = comment.branch_merge_proposal
     # The branch owners are implicitly subscribed to their branches
     # when the branches are created.
     self.assertRecipientsMatches(
         [bmp.source_branch.owner, bmp.target_branch.owner], mailer)
 def test_getToAddresses_no_parent(self):
     """To address for a comment with no parent should be the proposer."""
     comment = self.makeCommentAndParticipants()
     mailer = CodeReviewCommentMailer.forCreation(comment)
     to = mailer._getToAddresses(
         comment.message.owner, '*****@*****.**')
     self.assertEqual(['Proposer <*****@*****.**>'], to)
     to = mailer._getToAddresses(
         comment.branch_merge_proposal.registrant, '*****@*****.**')
     self.assertEqual(['Proposer <*****@*****.**>'], to)
 def test_forCreationStatusSubscriber(self):
     """Ensure that subscriptions with STATUS aren't used."""
     comment, subscriber = self.makeCommentAndSubscriber(
         CodeReviewNotificationLevel.STATUS)
     mailer = CodeReviewCommentMailer.forCreation(comment)
     bmp = comment.branch_merge_proposal
     # The branch owners are implicitly subscribed to their branches
     # when the branches are created.
     self.assertRecipientsMatches(
         [bmp.source_branch.owner, bmp.target_branch.owner], mailer)
 def test_nonReplyCommentUsesRootMessageId(self):
     """Ensure mailer's generateEmail method produces expected values."""
     comment, subscriber = self.makeCommentAndSubscriber()
     second_comment = self.factory.makeCodeReviewComment(
         merge_proposal=comment.branch_merge_proposal)
     mailer = CodeReviewCommentMailer.forCreation(second_comment)
     ctrl = mailer.generateEmail(
         subscriber.preferredemail.email, subscriber)
     self.assertEqual(comment.branch_merge_proposal.root_message_id,
                      ctrl.headers['In-Reply-To'])
 def test_getToAddresses_with_hidden_address(self):
     """Don't show address if Person.hide_email_addresses."""
     comment = self.makeCommentAndParticipants()
     removeSecurityProxy(comment.message.owner).hide_email_addresses = True
     second_commenter = self.factory.makePerson(
         email='*****@*****.**', displayname='Commenter2')
     reply = comment.branch_merge_proposal.createComment(
         second_commenter, 'hello2', parent=comment)
     mailer = CodeReviewCommentMailer.forCreation(reply)
     to = mailer._getToAddresses(second_commenter, '*****@*****.**')
     self.assertEqual([mailer.merge_proposal.address], to)
예제 #13
0
    def test_generateEmail_addresses(self):
        """The to_addrs but not envelope_to should follow getToAddress.

        We provide false to addresses to make filters happier, but this
        should not affect the actual recipient list.
        """
        comment = self.makeCommentAndParticipants()
        mailer = CodeReviewCommentMailer.forCreation(comment)
        ctrl = mailer.generateEmail('*****@*****.**',
                                    comment.message.owner)
        self.assertEqual(['Proposer <*****@*****.**>'], ctrl.to_addrs)
        self.assertEqual(['*****@*****.**'], ctrl.envelope_to)
예제 #14
0
 def test_getToAddresses_with_hidden_address(self):
     """Don't show address if Person.hide_email_addresses."""
     comment = self.makeCommentAndParticipants()
     removeSecurityProxy(comment.message.owner).hide_email_addresses = True
     second_commenter = self.factory.makePerson(
         email='*****@*****.**', displayname='Commenter2')
     reply = comment.branch_merge_proposal.createComment(second_commenter,
                                                         'hello2',
                                                         parent=comment)
     mailer = CodeReviewCommentMailer.forCreation(reply)
     to = mailer._getToAddresses(second_commenter, '*****@*****.**')
     self.assertEqual([mailer.merge_proposal.address], to)
    def test_generateEmail_addresses(self):
        """The to_addrs but not envelope_to should follow getToAddress.

        We provide false to addresses to make filters happier, but this
        should not affect the actual recipient list.
        """
        comment = self.makeCommentAndParticipants()
        mailer = CodeReviewCommentMailer.forCreation(comment)
        ctrl = mailer.generateEmail('*****@*****.**',
                                    comment.message.owner)
        self.assertEqual(['Proposer <*****@*****.**>'], ctrl.to_addrs)
        self.assertEqual(['*****@*****.**'], ctrl.envelope_to)
예제 #16
0
 def test_getToAddresses_with_parent(self):
     """To address for a reply should be the parent comment author."""
     comment = self.makeCommentAndParticipants()
     second_commenter = self.factory.makePerson(
         email='*****@*****.**', displayname='Commenter2')
     reply = comment.branch_merge_proposal.createComment(second_commenter,
                                                         'hello2',
                                                         parent=comment)
     mailer = CodeReviewCommentMailer.forCreation(reply)
     to = mailer._getToAddresses(second_commenter, '*****@*****.**')
     self.assertEqual(['Commenter <*****@*****.**>'], to)
     to = mailer._getToAddresses(comment.message.owner, '*****@*****.**')
     self.assertEqual(['Commenter <*****@*****.**>'], to)
 def test_encoded_attachments(self):
     msg = self.factory.makeEmailMessage(
         body='This is the body of the email.',
         attachments=[('inc.diff', 'text/x-diff', 'This is a diff.')],
         encode_attachments=True)
     comment = self.makeComment(msg)
     mailer = CodeReviewCommentMailer.forCreation(comment)
     person = comment.branch_merge_proposal.target_branch.owner
     message = mailer.generateEmail(
         person.preferredemail.email, person).makeMessage()
     attachment = message.get_payload()[1]
     self.assertEqual(
         'This is a diff.', attachment.get_payload(decode=True))
 def test_getToAddresses_with_parent(self):
     """To address for a reply should be the parent comment author."""
     comment = self.makeCommentAndParticipants()
     second_commenter = self.factory.makePerson(
         email='*****@*****.**', displayname='Commenter2')
     reply = comment.branch_merge_proposal.createComment(
         second_commenter, 'hello2', parent=comment)
     mailer = CodeReviewCommentMailer.forCreation(reply)
     to = mailer._getToAddresses(second_commenter, '*****@*****.**')
     self.assertEqual(['Commenter <*****@*****.**>'], to)
     to = mailer._getToAddresses(
         comment.message.owner, '*****@*****.**')
     self.assertEqual(['Commenter <*****@*****.**>'], to)
예제 #19
0
 def test_encoded_attachments(self):
     msg = self.factory.makeEmailMessage(
         body='This is the body of the email.',
         attachments=[('inc.diff', 'text/x-diff', 'This is a diff.')],
         encode_attachments=True)
     comment = self.makeComment(msg)
     mailer = CodeReviewCommentMailer.forCreation(comment)
     person = comment.branch_merge_proposal.target_branch.owner
     message = mailer.generateEmail(person.preferredemail.email,
                                    person).makeMessage()
     attachment = message.get_payload()[1]
     self.assertEqual('This is a diff.',
                      attachment.get_payload(decode=True))
예제 #20
0
 def test_forCreation(self):
     """Ensure that forCreation produces a mailer with expected values."""
     comment, subscriber = self.makeCommentAndSubscriber()
     mailer = CodeReviewCommentMailer.forCreation(comment)
     self.assertEqual(comment.message.subject, mailer._subject_template)
     bmp = comment.branch_merge_proposal
     # The branch owners are implicitly subscribed to their branches
     # when the branches are created.
     self.assertRecipientsMatches(
         [subscriber, bmp.source_branch.owner, bmp.target_branch.owner],
         mailer)
     self.assertEqual(comment.branch_merge_proposal, mailer.merge_proposal)
     sender = comment.message.owner
     sender_address = format_address(sender.displayname,
                                     sender.preferredemail.email)
     self.assertEqual(sender_address, mailer.from_address)
     self.assertEqual(comment, mailer.code_review_comment)
 def test_forCreation(self):
     """Ensure that forCreation produces a mailer with expected values."""
     comment, subscriber = self.makeCommentAndSubscriber()
     mailer = CodeReviewCommentMailer.forCreation(comment)
     self.assertEqual(comment.message.subject,
                      mailer._subject_template)
     bmp = comment.branch_merge_proposal
     # The branch owners are implicitly subscribed to their branches
     # when the branches are created.
     self.assertRecipientsMatches(
         [subscriber, bmp.source_branch.owner, bmp.target_branch.owner],
         mailer)
     self.assertEqual(
         comment.branch_merge_proposal, mailer.merge_proposal)
     sender = comment.message.owner
     sender_address = format_address(sender.displayname,
         sender.preferredemail.email)
     self.assertEqual(sender_address, mailer.from_address)
     self.assertEqual(comment, mailer.code_review_comment)
예제 #22
0
 def test_mailer_attachments(self):
     # Ensure that the attachments are attached.
     # Only attachments that we would show in the web ui are attached,
     # so the diff should be attached, and the jpeg image not.
     msg = self.factory.makeEmailMessage(
         body='This is the body of the email.',
         attachments=[('inc.diff', 'text/x-diff', 'This is a diff.'),
                      ('pic.jpg', 'image/jpeg', 'Binary data')])
     comment = self.makeComment(msg)
     mailer = CodeReviewCommentMailer.forCreation(comment)
     # The attachments of the mailer should have only the diff.
     [outgoing_attachment] = mailer.attachments
     self.assertEqual('inc.diff', outgoing_attachment[1])
     self.assertEqual('text/x-diff', outgoing_attachment[2])
     # The attachments are attached to the outgoing message.
     person = comment.branch_merge_proposal.target_branch.owner
     message = mailer.generateEmail(person.preferredemail.email,
                                    person).makeMessage()
     self.assertTrue(message.is_multipart())
     attachment = message.get_payload()[1]
     self.assertEqual('inc.diff', attachment.get_filename())
     self.assertEqual('text/x-diff', attachment['content-type'])
 def test_mailer_attachments(self):
     # Ensure that the attachments are attached.
     # Only attachments that we would show in the web ui are attached,
     # so the diff should be attached, and the jpeg image not.
     msg = self.factory.makeEmailMessage(
         body='This is the body of the email.',
         attachments=[
             ('inc.diff', 'text/x-diff', 'This is a diff.'),
             ('pic.jpg', 'image/jpeg', 'Binary data')])
     comment = self.makeComment(msg)
     mailer = CodeReviewCommentMailer.forCreation(comment)
     # The attachments of the mailer should have only the diff.
     [outgoing_attachment] = mailer.attachments
     self.assertEqual('inc.diff', outgoing_attachment[1])
     self.assertEqual('text/x-diff', outgoing_attachment[2])
     # The attachments are attached to the outgoing message.
     person = comment.branch_merge_proposal.target_branch.owner
     message = mailer.generateEmail(
         person.preferredemail.email, person).makeMessage()
     self.assertTrue(message.is_multipart())
     attachment = message.get_payload()[1]
     self.assertEqual('inc.diff', attachment.get_filename())
     self.assertEqual('text/x-diff', attachment['content-type'])
 def makeMailer(self, body=None, as_reply=False, vote=None, vote_tag=None):
     """Return a CodeReviewCommentMailer and the sole subscriber."""
     comment, subscriber = self.makeCommentAndSubscriber(
         body=body, as_reply=as_reply, vote=vote, vote_tag=vote_tag)
     return CodeReviewCommentMailer.forCreation(comment), subscriber
 def run(self):
     """See `IRunnableJob`."""
     mailer = CodeReviewCommentMailer.forCreation(self.code_review_comment)
     mailer.sendAll()
예제 #26
0
 def run(self):
     """See `IRunnableJob`."""
     mailer = CodeReviewCommentMailer.forCreation(self.code_review_comment)
     mailer.sendAll()