def test_subject(self): # No string interpolation should occur on the subject. branch = self.factory.makeAnyBranch() # Subscribe the owner to get revision email. branch.getSubscription(branch.owner).notification_level = BranchSubscriptionNotificationLevel.FULL mailer = BranchMailer.forRevision(branch, 1, "*****@*****.**", "content", "diff", "Testing %j foo") branch_owner_email = removeSecurityProxy(branch.owner).preferredemail.email self.assertEqual("Testing %j foo", mailer._getSubject(branch_owner_email, branch.owner))
def makeBobMailController(self, diff=None, max_lines=BranchSubscriptionDiffSize.WHOLEDIFF): bob = self.factory.makePerson(email="*****@*****.**") branch = self.factory.makeProductBranch(owner=bob) subscription = branch.getSubscription(bob) subscription.max_diff_lines = max_lines subscription.notification_level = BranchSubscriptionNotificationLevel.FULL mailer = BranchMailer.forRevision(branch, 1, "*****@*****.**", contents="", diff=diff, subject="") return mailer.generateEmail("*****@*****.**", branch.owner)
def test_subject(self): # No string interpolation should occur on the subject. branch = self.factory.makeAnyBranch() # Subscribe the owner to get revision email. branch.getSubscription(branch.owner).notification_level = ( BranchSubscriptionNotificationLevel.FULL) mailer = BranchMailer.forRevision(branch, 1, '*****@*****.**', 'content', 'diff', 'Testing %j foo') branch_owner_email = removeSecurityProxy( branch.owner).preferredemail.email self.assertEqual('Testing %j foo', mailer._getSubject(branch_owner_email, branch.owner))
def makeBobMailController(self, diff=None, max_lines=BranchSubscriptionDiffSize.WHOLEDIFF): bob = self.factory.makePerson(email='*****@*****.**') branch = self.factory.makeProductBranch(owner=bob) subscription = branch.getSubscription(bob) subscription.max_diff_lines = max_lines subscription.notification_level = ( BranchSubscriptionNotificationLevel.FULL) mailer = BranchMailer.forRevision(branch, 1, '*****@*****.**', contents='', diff=diff, subject='') return mailer.generateEmail('*****@*****.**', branch.owner)
def test_branch_revision(self): # Test the email headers for new revision email. bob = self.factory.makePerson(email="*****@*****.**") branch = self.factory.makeProductBranch(owner=bob) branch.getSubscription(bob).notification_level = BranchSubscriptionNotificationLevel.FULL mailer = BranchMailer.forRevision(branch, 1, "*****@*****.**", contents="", diff=None, subject="") mailer.message_id = "<foobar-example-com>" ctrl = mailer.generateEmail("*****@*****.**", branch.owner) self.assertEqual( { "X-Launchpad-Branch": branch.unique_name, "X-Launchpad-Message-Rationale": "Subscriber", "X-Launchpad-Notification-Type": "branch-revision", "X-Launchpad-Branch-Revision-Number": "1", "X-Launchpad-Project": branch.product.name, "Message-Id": "<foobar-example-com>", }, ctrl.headers, )
def test_branch_revision(self): # Test the email headers for new revision email. bob = self.factory.makePerson(email='*****@*****.**') branch = self.factory.makeProductBranch(owner=bob) branch.getSubscription(bob).notification_level = ( BranchSubscriptionNotificationLevel.FULL) mailer = BranchMailer.forRevision(branch, 1, '*****@*****.**', contents='', diff=None, subject='') mailer.message_id = '<foobar-example-com>' ctrl = mailer.generateEmail('*****@*****.**', branch.owner) self.assertEqual( { 'X-Launchpad-Branch': branch.unique_name, 'X-Launchpad-Message-Rationale': 'Subscriber', 'X-Launchpad-Notification-Type': 'branch-revision', 'X-Launchpad-Branch-Revision-Number': '1', 'X-Launchpad-Project': branch.product.name, 'Message-Id': '<foobar-example-com>' }, ctrl.headers)
def getMailerForRevision(self, revision, revno, generate_diff): """Return a BranchMailer for a revision. :param revision: A bzr revision. :param revno: The revno of the revision in this branch. :param generate_diffs: If true, generate a diff for the revision. """ message = self.getRevisionMessage(revision.revision_id, revno) # Use the first (non blank) line of the commit message # as part of the subject, limiting it to 100 characters # if it is longer. message_lines = [ line.strip() for line in revision.message.split('\n') if len(line.strip()) > 0] if len(message_lines) == 0: first_line = 'no commit message given' else: first_line = message_lines[0] if len(first_line) > SUBJECT_COMMIT_MESSAGE_LENGTH: offset = SUBJECT_COMMIT_MESSAGE_LENGTH - 3 first_line = first_line[:offset] + '...' subject = '[Branch %s] Rev %s: %s' % ( self.branch.unique_name, revno, first_line) if generate_diff: if len(revision.parent_ids) > 0: parent_id = revision.parent_ids[0] else: parent_id = NULL_REVISION diff_text = self.getDiffForRevisions( parent_id, revision.revision_id) else: diff_text = None return BranchMailer.forRevision( self.branch, revno, self.from_address, message, diff_text, subject)
def getMailerForRevision(self, revision, revno, generate_diff): """Return a BranchMailer for a revision. :param revision: A bzr revision. :param revno: The revno of the revision in this branch. :param generate_diffs: If true, generate a diff for the revision. """ message = self.getRevisionMessage(revision.revision_id, revno) # Use the first (non blank) line of the commit message # as part of the subject, limiting it to 100 characters # if it is longer. message_lines = [ line.strip() for line in revision.message.split('\n') if len(line.strip()) > 0] if len(message_lines) == 0: first_line = 'no commit message given' else: first_line = message_lines[0] if len(first_line) > SUBJECT_COMMIT_MESSAGE_LENGTH: offset = SUBJECT_COMMIT_MESSAGE_LENGTH - 3 first_line = first_line[:offset] + '...' subject = '[Branch %s] Rev %s: %s' % ( self.branch.unique_name, revno, first_line) if generate_diff: if len(revision.parent_ids) > 0: parent_id = revision.parent_ids[0] else: parent_id = NULL_REVISION diff_text = self.getDiffForRevisions( parent_id, revision.revision_id) else: diff_text = None return BranchMailer.forRevision( self.branch, self.from_address, message, diff_text, subject, revno=revno)
def getMailer(self): """Return a BranchMailer for this job.""" return BranchMailer.forRevision( self.branch, self.revno, self.from_address, self.body, None, self.subject)
def getMailer(self): """Return a BranchMailer for this job.""" return BranchMailer.forRevision( self.branch, self.from_address, self.body, None, self.subject, revno=self.revno)