Пример #1
0
 def test_empty_branch(self):
     self.makeBzrSync(self.db_branch).syncBranchAndClose()
     JobRunner.fromReady(getUtility(IRevisionMailJobSource)).runAll()
     self.assertEqual(len(stub.test_emails), 1)
     [initial_email] = stub.test_emails
     expected = 'First scan of the branch detected 0 revisions'
     message = email.message_from_string(initial_email[2])
     email_body = message.get_payload()
     self.assertIn(expected, email_body)
     self.assertEmailHeadersEqual(
         '[Branch %s] 0 revisions' % self.db_branch.unique_name,
         message['Subject'])
Пример #2
0
 def test_empty_branch(self):
     self.makeBzrSync(self.db_branch).syncBranchAndClose()
     JobRunner.fromReady(getUtility(IRevisionMailJobSource)).runAll()
     self.assertEqual(len(stub.test_emails), 1)
     [initial_email] = stub.test_emails
     expected = 'First scan of the branch detected 0 revisions'
     message = email.message_from_string(initial_email[2])
     email_body = message.get_payload()
     self.assertTextIn(expected, email_body)
     self.assertEmailHeadersEqual(
         '[Branch %s] 0 revisions' % self.db_branch.unique_name,
         message['Subject'])
Пример #3
0
 def test_import_revision(self):
     self.commitRevision()
     self.makeBzrSync(self.db_branch).syncBranchAndClose()
     JobRunner.fromReady(getUtility(IRevisionMailJobSource)).runAll()
     self.assertEqual(len(stub.test_emails), 1)
     [initial_email] = stub.test_emails
     expected = ('First scan of the branch detected 1 revision'
                 ' in the revision history of the=\n branch.')
     message = email.message_from_string(initial_email[2])
     email_body = message.get_payload()
     self.assertTextIn(expected, email_body)
     self.assertEmailHeadersEqual(
         '[Branch %s] 1 revision' % self.db_branch.unique_name,
         message['Subject'])
Пример #4
0
def run_mail_jobs():
    """Process job queues that send out emails.

    If a new job type is added that sends emails, this function can be
    extended to run those jobs, so that testing emails doesn't require a
    bunch of different function calls to process different queues.
    """
    # Circular import.
    from lp.testing.pages import permissive_security_policy

    # Commit the transaction to make sure that the JobRunner can find
    # the queued jobs.
    transaction.commit()
    for interface in (
            IExpiringMembershipNotificationJobSource,
            IMembershipNotificationJobSource,
            ISelfRenewalNotificationJobSource,
            ITeamInvitationNotificationJobSource,
            ITeamJoinNotificationJobSource,
            ):
        job_source = getUtility(interface)
        logger = DevNullLogger()
        dbuser_name = getattr(config, interface.__name__).dbuser
        with permissive_security_policy(dbuser_name):
            runner = JobRunner.fromReady(job_source, logger)
            runner.runAll()
Пример #5
0
 def test_import_uncommit(self):
     self.commitRevision()
     self.makeBzrSync(self.db_branch).syncBranchAndClose()
     JobRunner.fromReady(getUtility(IRevisionMailJobSource)).runAll()
     stub.test_emails = []
     self.uncommitRevision()
     self.makeBzrSync(self.db_branch).syncBranchAndClose()
     JobRunner.fromReady(getUtility(IRevisionMailJobSource)).runAll()
     self.assertEqual(len(stub.test_emails), 1)
     [uncommit_email] = stub.test_emails
     expected = '1 revision was removed from the branch.'
     message = email.message_from_string(uncommit_email[2])
     email_body = message.get_payload()
     self.assertIn(expected, email_body)
     self.assertEmailHeadersEqual(
         '[Branch %s] 1 revision removed' % self.db_branch.unique_name,
         message['Subject'])
Пример #6
0
 def test_import_uncommit(self):
     self.commitRevision()
     self.makeBzrSync(self.db_branch).syncBranchAndClose()
     JobRunner.fromReady(getUtility(IRevisionMailJobSource)).runAll()
     stub.test_emails = []
     self.uncommitRevision()
     self.makeBzrSync(self.db_branch).syncBranchAndClose()
     JobRunner.fromReady(getUtility(IRevisionMailJobSource)).runAll()
     self.assertEqual(len(stub.test_emails), 1)
     [uncommit_email] = stub.test_emails
     expected = '1 revision was removed from the branch.'
     message = email.message_from_string(uncommit_email[2])
     email_body = message.get_payload()
     self.assertTextIn(expected, email_body)
     self.assertEmailHeadersEqual(
         '[Branch %s] 1 revision removed' % self.db_branch.unique_name,
         message['Subject'])
Пример #7
0
def run_mail_jobs():
    """Process job queues that send out emails.

    If a new job type is added that sends emails, this function can be
    extended to run those jobs, so that testing emails doesn't require a
    bunch of different function calls to process different queues.
    """
    # Commit the transaction to make sure that the JobRunner can find
    # the queued jobs.
    transaction.commit()
    job_source = getUtility(IMembershipNotificationJobSource)
    logger = DevNullLogger()
    runner = JobRunner.fromReady(job_source, logger)
    runner.runAll()
Пример #8
0
    def test_import_recommit(self):
        # When scanning the uncommit and new commit there should be an email
        # generated saying that 1 (in this case) revision has been removed,
        # and another email with the diff and log message.
        self.commitRevision('first')
        self.makeBzrSync(self.db_branch).syncBranchAndClose()
        JobRunner.fromReady(getUtility(IRevisionMailJobSource)).runAll()
        stub.test_emails = []
        self.uncommitRevision()
        self.writeToFile(filename="hello.txt",
                         contents="Hello World\n")
        author = self.factory.getUniqueString()
        self.commitRevision('second', committer=author)
        self.makeBzrSync(self.db_branch).syncBranchAndClose()
        JobRunner.fromReady(getUtility(IRevisionsAddedJobSource)).runAll()
        JobRunner.fromReady(getUtility(IRevisionMailJobSource)).runAll()
        self.assertEqual(len(stub.test_emails), 2)
        [recommit_email, uncommit_email] = stub.test_emails
        uncommit_email_body = uncommit_email[2]
        expected = '1 revision was removed from the branch.'
        self.assertTextIn(expected, uncommit_email_body)
        subject = (
            'Subject: [Branch %s] Test branch' % self.db_branch.unique_name)
        self.assertTextIn(expected, uncommit_email_body)

        recommit_email_msg = email.message_from_string(recommit_email[2])
        recommit_email_body = recommit_email_msg.get_payload()[0].get_payload(
            decode=True)
        subject = '[Branch %s] Rev 1: second' % self.db_branch.unique_name
        self.assertEmailHeadersEqual(subject, recommit_email_msg['Subject'])
        body_bits = [
            'revno: 1',
            'committer: %s' % author,
            'branch nick: %s' % self.bzr_branch.nick,
            'message:\n  second',
            'added:\n  hello.txt',
            ]
        for bit in body_bits:
            self.assertTextIn(bit, recommit_email_body)
Пример #9
0
 def runMailJobs(self):
     with permissive_security_policy('person-transfer-job'):
         JobRunner.fromReady(
             getUtility(ITeamJoinNotificationJobSource)).runAll()