コード例 #1
0
    def test_run_cronscript(self):
        # The cronscript is configured: schema-lazr.conf and security.cfg.
        job = make_question_job(self.factory,
                                QuestionRecipientSet.ASKER_SUBSCRIBER)
        question = job.question
        with person_logged_in(question.target.owner):
            question.linkBug(self.factory.makeBug(target=question.target))
            question.linkFAQ(question.target.owner,
                             self.factory.makeFAQ(target=question.target),
                             'test FAQ link')
        user = job.user
        with person_logged_in(user):
            lang_set = getUtility(ILanguageSet)
            user.addLanguage(lang_set['en'])
            question.target.addAnswerContact(user, user)
        transaction.commit()

        out, err, exit_code = run_script(
            "LP_DEBUG_SQL=1 cronscripts/process-job-source.py -vv %s" %
            (IQuestionEmailJobSource.getName()))
        self.addDetail("stdout", Content(UTF8_TEXT, lambda: out))
        self.addDetail("stderr", Content(UTF8_TEXT, lambda: err))
        self.assertEqual(0, exit_code)
        self.assertTrue('Traceback (most recent call last)' not in err)
        message = ('QuestionEmailJob has sent email for question %s.' %
                   question.id)
        self.assertTrue(
            message in err,
            'Cound not find "%s" in err log:\n%s.' % (message, err))
        IStore(job.job).invalidate()
        self.assertEqual(JobStatus.COMPLETED, job.job.status)
コード例 #2
0
    def test_run_cronscript(self):
        # The cronscript is configured: schema-lazr.conf and security.cfg.
        job = make_question_job(
            self.factory, QuestionRecipientSet.ASKER_SUBSCRIBER)
        question = job.question
        with person_logged_in(question.target.owner):
            question.linkBug(self.factory.makeBug(target=question.target))
            question.linkFAQ(
                question.target.owner,
                self.factory.makeFAQ(target=question.target),
                'test FAQ link')
        user = job.user
        with person_logged_in(user):
            lang_set = getUtility(ILanguageSet)
            user.addLanguage(lang_set['en'])
            question.target.addAnswerContact(user, user)
        transaction.commit()

        out, err, exit_code = run_script(
            "LP_DEBUG_SQL=1 cronscripts/process-job-source.py -vv %s" % (
                IQuestionEmailJobSource.getName()))
        self.addDetail("stdout", Content(UTF8_TEXT, lambda: out))
        self.addDetail("stderr", Content(UTF8_TEXT, lambda: err))
        self.assertEqual(0, exit_code)
        self.assertTrue(
            'Traceback (most recent call last)' not in err)
        message = (
            'QuestionEmailJob has sent email for question %s.' % question.id)
        self.assertTrue(
            message in err,
            'Cound not find "%s" in err log:\n%s.' % (message, err))
        IStore(job.job).invalidate()
        self.assertEqual(JobStatus.COMPLETED, job.job.status)
コード例 #3
0
 def test_smoke_admining_team(self):
     # Smoke test, primarily for DB permissions needed by queries to work
     # with admining users and teams
     # Check the oopses in /var/tmp/lperr.test if the assertions fail.
     with person_logged_in(self.team.teamowner):
         # This implicitly creates a job, but it is not the job under test.
         admining_team = self.factory.makeTeam()
         self.team.addMember(
             admining_team, self.team.teamowner, force_team_add=True)
         membership = getUtility(ITeamMembershipSet).getByPersonAndTeam(
             admining_team, self.team)
         membership.setStatus(
             TeamMembershipStatus.ADMIN, self.team.teamowner)
     job = self.job_source.create(
         self.person, self.team, self.team.teamowner,
         TeamMembershipStatus.APPROVED, TeamMembershipStatus.ADMIN)
     job_repr = repr(job)
     transaction.commit()
     out, err, exit_code = run_script(
         "LP_DEBUG_SQL=1 cronscripts/process-job-source.py -vv %s" % (
             IMembershipNotificationJobSource.getName()))
     self.addDetail("stdout", Content(UTF8_TEXT, lambda: [out]))
     self.addDetail("stderr", Content(UTF8_TEXT, lambda: [err]))
     self.assertEqual(0, exit_code)
     self.assertTrue(job_repr in err, err)
     self.assertTrue("MembershipNotificationJob sent email" in err, err)
コード例 #4
0
    def test_smoke(self):
        # Smoke test, primarily for DB permissions need for users and teams.
        # Check the oopses in /var/tmp/lperr.test if the person.merged
        # assertion fails.
        self.transfer_email()
        to_team = self.factory.makeTeam(name='legion')
        from_team = self.factory.makeTeam(name='null')
        with person_logged_in(from_team.teamowner):
            from_team.teamowner.leave(from_team)
        self.job_source.create(from_person=from_team,
                               to_person=to_team,
                               reviewer=from_team.teamowner,
                               requester=self.factory.makePerson())
        transaction.commit()

        out, err, exit_code = run_script(
            "LP_DEBUG_SQL=1 cronscripts/process-job-source.py -vv %s" %
            (IPersonMergeJobSource.getName()))

        self.addDetail("stdout", Content(UTF8_TEXT, lambda: out))
        self.addDetail("stderr", Content(UTF8_TEXT, lambda: err))

        self.assertEqual(0, exit_code)
        IStore(self.from_person).invalidate()
        self.assertEqual(self.to_person, self.from_person.merged)
        self.assertEqual(to_team, from_team.merged)
コード例 #5
0
    def _assert_run_cronscript(self, create_job):
        # The cronscript is configured: schema-lazr.conf and security.cfg.
        # The job runs correctly and the requested bug subscriptions are
        # removed.
        distro = self.factory.makeDistribution()
        grantee = self.factory.makePerson()
        owner = self.factory.makePerson()
        bug = self.factory.makeBug(
            owner=owner, target=distro,
            information_type=InformationType.USERDATA)
        with person_logged_in(owner):
            bug.subscribe(grantee, owner)
        job, job_type = create_job(distro, bug, grantee, owner)
        # Subscribing grantee has created an artifact grant so we need to
        # revoke that to test the job.
        artifact = self.factory.makeAccessArtifact(concrete=bug)
        getUtility(IAccessArtifactGrantSource).revokeByArtifact(
            [artifact], [grantee])
        transaction.commit()

        out, err, exit_code = run_script(
            "LP_DEBUG_SQL=1 cronscripts/process-job-source.py -vv %s" % (
                job_type))
        self.addDetail("stdout", Content(UTF8_TEXT, lambda: out))
        self.addDetail("stderr", Content(UTF8_TEXT, lambda: err))
        self.assertEqual(0, exit_code)
        self.assertTrue(
            'Traceback (most recent call last)' not in err)
        IStore(job.job).invalidate()
        self.assertEqual(JobStatus.COMPLETED, job.job.status)
        self.assertNotIn(
            grantee, removeSecurityProxy(bug).getDirectSubscribers())
コード例 #6
0
    def test_smoke(self):
        # Smoke test, primarily for DB permissions need for users and teams.
        # Check the oopses in /var/tmp/lperr.test if the person.merged
        # assertion fails.
        self.transfer_email()
        to_team = self.factory.makeTeam(name='legion')
        from_team = self.factory.makeTeam(name='null')
        with person_logged_in(from_team.teamowner):
            from_team.teamowner.leave(from_team)
        self.job_source.create(
            from_person=from_team, to_person=to_team,
            reviewer=from_team.teamowner, requester=self.factory.makePerson())
        transaction.commit()

        out, err, exit_code = run_script(
            "LP_DEBUG_SQL=1 cronscripts/process-job-source.py -vv %s" % (
                IPersonMergeJobSource.getName()))

        self.addDetail("stdout", Content(UTF8_TEXT, lambda: out))
        self.addDetail("stderr", Content(UTF8_TEXT, lambda: err))

        self.assertEqual(0, exit_code)
        IStore(self.from_person).invalidate()
        self.assertEqual(self.to_person, self.from_person.merged)
        self.assertEqual(to_team, from_team.merged)
コード例 #7
0
    def _assert_run_cronscript(self, create_job):
        # The cronscript is configured: schema-lazr.conf and security.cfg.
        # The job runs correctly and the requested bug subscriptions are
        # removed.
        distro = self.factory.makeDistribution()
        grantee = self.factory.makePerson()
        owner = self.factory.makePerson()
        bug = self.factory.makeBug(owner=owner,
                                   target=distro,
                                   information_type=InformationType.USERDATA)
        with person_logged_in(owner):
            bug.subscribe(grantee, owner)
        job, job_type = create_job(distro, bug, grantee, owner)
        # Subscribing grantee has created an artifact grant so we need to
        # revoke that to test the job.
        artifact = self.factory.makeAccessArtifact(concrete=bug)
        getUtility(IAccessArtifactGrantSource).revokeByArtifact([artifact],
                                                                [grantee])
        transaction.commit()

        out, err, exit_code = run_script(
            "LP_DEBUG_SQL=1 cronscripts/process-job-source.py -vv %s" %
            (job_type))
        self.addDetail("stdout", Content(UTF8_TEXT, lambda: out))
        self.addDetail("stderr", Content(UTF8_TEXT, lambda: err))
        self.assertEqual(0, exit_code)
        self.assertTrue('Traceback (most recent call last)' not in err)
        IStore(job.job).invalidate()
        self.assertEqual(JobStatus.COMPLETED, job.job.status)
        self.assertNotIn(grantee,
                         removeSecurityProxy(bug).getDirectSubscribers())
コード例 #8
0
 def test_script(self):
     # Run self.script_path with '-h' to make sure it runs cleanly.
     cmd_line = self.script_path + " -h"
     out, err, returncode = run_script(cmd_line)
     self.assertThat(err, DocTestMatches('', doctest.REPORT_NDIFF))
     self.assertEqual('', err)
     self.assertEqual(os.EX_OK, returncode)
コード例 #9
0
 def upgrade_all_branches(self, target, finish=False):
     """Run the script to upgrade all branches."""
     transaction.commit()
     if finish:
         flags = ' --finish '
     else:
         flags = ' '
     return run_script(
         'scripts/upgrade_all_branches.py' + flags + target, cwd=self.cwd)
コード例 #10
0
    def test_smoke(self):
        diff = create_proper_job(self.factory)
        transaction.commit()
        out, err, exit_code = run_script(
            "LP_DEBUG_SQL=1 cronscripts/process-job-source.py -vv %s" % (IPackageDiffJobSource.getName())
        )

        self.addDetail("stdout", text_content(out))
        self.addDetail("stderr", text_content(err))
        self.assertEqual(0, exit_code)
        self.assertEqual(PackageDiffStatus.COMPLETED, diff.status)
        self.assertIsNot(None, diff.diff_content)
コード例 #11
0
 def test_run(self):
     # The script called ProductJobManager.createAllDailyJobs().
     # This test uses the same setup as
     # ProductJobManagerTestCase.test_createAllDailyJobs
     self.make_test_products()
     transaction.commit()
     stdout, stderr, retcode = run_script(
         'cronscripts/daily_product_jobs.py')
     self.addDetail("stdout", Content(UTF8_TEXT, lambda: stdout))
     self.addDetail("stderr", Content(UTF8_TEXT, lambda: stderr))
     self.assertEqual(0, retcode)
     self.assertIn('Requested 3 total product jobs.', stderr)
コード例 #12
0
    def test_smoke(self):
        diff = create_proper_job(self.factory)
        transaction.commit()
        out, err, exit_code = run_script(
            "LP_DEBUG_SQL=1 cronscripts/process-job-source.py -vv %s" %
            (IPackageDiffJobSource.getName()))

        self.addDetail("stdout", text_content(out))
        self.addDetail("stderr", text_content(err))
        self.assertEqual(0, exit_code)
        self.assertEqual(PackageDiffStatus.COMPLETED, diff.status)
        self.assertIsNot(None, diff.diff_content)
コード例 #13
0
    def test_smoke(self):
        spr = self.factory.makeSourcePackageRelease(
            distroseries=self.distroseries, changelog_entry="changelog")
        bug = self.factory.makeBug()
        bugtask = self.factory.makeBugTask(target=spr.sourcepackage, bug=bug)
        self.assertEqual(BugTaskStatus.NEW, bugtask.status)
        self.makeJob(spr=spr, bug_ids=[bug.id])
        transaction.commit()

        out, err, exit_code = run_script(
            "LP_DEBUG_SQL=1 cronscripts/process-job-source.py -vv %s" % (
                IProcessAcceptedBugsJobSource.getName()))

        self.addDetail("stdout", text_content(out))
        self.addDetail("stderr", text_content(err))

        self.assertEqual(0, exit_code)
        self.assertEqual(BugTaskStatus.FIXRELEASED, bugtask.status)
コード例 #14
0
    def test_smoke(self):
        spr = self.factory.makeSourcePackageRelease(
            distroseries=self.distroseries, changelog_entry="changelog")
        bug = self.factory.makeBug()
        bugtask = self.factory.makeBugTask(target=spr.sourcepackage, bug=bug)
        self.assertEqual(BugTaskStatus.NEW, bugtask.status)
        self.makeJob(spr=spr, bug_ids=[bug.id])
        transaction.commit()

        out, err, exit_code = run_script(
            "LP_DEBUG_SQL=1 cronscripts/process-job-source.py -vv %s" %
            (IProcessAcceptedBugsJobSource.getName()))

        self.addDetail("stdout", text_content(out))
        self.addDetail("stderr", text_content(err))

        self.assertEqual(0, exit_code)
        self.assertEqual(BugTaskStatus.FIXRELEASED, bugtask.status)
コード例 #15
0
    def test_run_cronscript(self):
        # Everything is configured: ZCML, schema-lazr.conf, and security.cfg.
        product, reviewer = self.make_notification_data()
        private_branch = self.factory.makeBranch(
            owner=product.owner, product=product,
            information_type=InformationType.USERDATA)
        with person_logged_in(product.owner):
            product.development_focus.branch = private_branch
        self.expire_commercial_subscription(product)
        job = self.JOB_CLASS.create(product, reviewer)
        # Create a proprietary project owned by a team which will have
        # different DB relations.
        team = self.factory.makeTeam(
            membership_policy=TeamMembershipPolicy.RESTRICTED)
        proprietary_product = self.factory.makeProduct(
            owner=team, licenses=[License.OTHER_PROPRIETARY])
        self.expire_commercial_subscription(proprietary_product)
        proprietary_job = self.JOB_CLASS.create(proprietary_product, reviewer)
        transaction.commit()

        out, err, exit_code = run_script(
            "LP_DEBUG_SQL=1 cronscripts/process-job-source.py -vv %s" %
             self.JOB_SOURCE_INTERFACE.getName())
        self.addDetail("stdout", Content(UTF8_TEXT, lambda: out))
        self.addDetail("stderr", Content(UTF8_TEXT, lambda: err))
        self.assertEqual(0, exit_code)
        self.assertTrue(
            'Traceback (most recent call last)' not in err)
        message = (
            '%s has sent email to the maintainer of %s.' % (
                self.JOB_CLASS.__name__, product.name))
        self.assertTrue(
            message in err,
            'Cound not find "%s" in err log:\n%s.' % (message, err))
        message = (
            '%s has sent email to the maintainer of %s.' % (
                self.JOB_CLASS.__name__, proprietary_product.name))
        self.assertTrue(
            message in err,
            'Cound not find "%s" in err log:\n%s.' % (message, err))
        IStore(job.job).invalidate()
        self.assertEqual(JobStatus.COMPLETED, job.job.status)
        self.assertEqual(JobStatus.COMPLETED, proprietary_job.job.status)
コード例 #16
0
    def test_smoke(self):
        tar_content = {
            'source/po/foobar.pot': 'FooBar template',
        }
        spr, sp, job = self.makeJob(tar_content=tar_content)
        transaction.commit()
        out, err, exit_code = run_script(
            "LP_DEBUG_SQL=1 cronscripts/process-job-source.py -vv %s" % (
                IPackageTranslationsUploadJobSource.getName()))

        self.addDetail("stdout", text_content(out))
        self.addDetail("stderr", text_content(err))

        self.assertEqual(0, exit_code)
        translation_import_queue = getUtility(ITranslationImportQueue)
        entries_in_queue = translation_import_queue.getAllEntries(target=sp)

        self.assertEqual(1, entries_in_queue.count())
        # Check if the file in tar_content is queued:
        self.assertTrue("po/foobar.pot", entries_in_queue[0].path)
コード例 #17
0
    def test_smoke(self):
        tar_content = {
            'source/po/foobar.pot': 'FooBar template',
        }
        spr, job = self.makeJob(tar_content=tar_content)
        transaction.commit()
        out, err, exit_code = run_script(
            "LP_DEBUG_SQL=1 cronscripts/process-job-source.py -vv %s" % (
                IPackageTranslationsUploadJobSource.getName()))

        self.addDetail("stdout", text_content(out))
        self.addDetail("stderr", text_content(err))

        self.assertEqual(0, exit_code)
        translation_import_queue = getUtility(ITranslationImportQueue)
        entries_in_queue = translation_import_queue.getAllEntries(
            target=spr.sourcepackage)

        self.assertEqual(1, entries_in_queue.count())
        # Check if the file in tar_content is queued:
        self.assertTrue("po/foobar.pot", entries_in_queue[0].path)
コード例 #18
0
 def test_script_runs_successfully(self):
     self.prepareUbuntu()
     self.layer.txn.commit()
     stdout, stderr, retval = run_script(
         self.SCRIPT_PATH + " -d ubuntu")
     self.assertEqual(0, retval, "Script failure:\n" + stderr)
コード例 #19
0
 def test_script_runs_successfully(self):
     self.prepareUbuntu()
     self.layer.txn.commit()
     stdout, stderr, retval = run_script(self.SCRIPT_PATH + " -d ubuntu")
     self.assertEqual(0, retval, "Script failure:\n" + stderr)