コード例 #1
0
 def _createPreviewDiff(self, line_count=0, added=None, removed=None, conflicts=None, diffstat=None):
     # Login an admin to avoid the launchpad.Edit requirements.
     login("*****@*****.**")
     # Create a dummy preview diff, and make sure the branches have the
     # correct last scanned ids to ensure that the new diff is not stale.
     bmp = self.factory.makeBranchMergeProposal()
     if line_count:
         content = "".join(unified_diff("", "random content"))
     else:
         content = ""
     preview = bmp.updatePreviewDiff(content, u"rev-a", u"rev-b", conflicts=conflicts)
     bmp.source_branch.last_scanned_id = preview.source_revision_id
     bmp.target_branch.last_scanned_id = preview.target_revision_id
     # Update the values directly sidestepping the security.
     naked_diff = removeSecurityProxy(preview)
     naked_diff.diff_lines_count = line_count
     naked_diff.added_lines_count = added
     naked_diff.removed_lines_count = removed
     naked_diff.diffstat = diffstat
     # In order to get the canonical url of the librarian file, we need to
     # commit.
     # transaction.commit()
     # Make sure that the preview diff is in the db for the test.
     # Storm bug: 324724
     Store.of(bmp).flush()
     return preview
コード例 #2
0
 def _createPreviewDiff(self,
                        line_count=0,
                        added=None,
                        removed=None,
                        conflicts=None,
                        diffstat=None):
     # Login an admin to avoid the launchpad.Edit requirements.
     login('*****@*****.**')
     # Create a dummy preview diff, and make sure the branches have the
     # correct last scanned ids to ensure that the new diff is not stale.
     bmp = self.factory.makeBranchMergeProposal()
     if line_count:
         content = ''.join(unified_diff('', 'random content'))
     else:
         content = ''
     preview = bmp.updatePreviewDiff(content,
                                     'rev-a',
                                     'rev-b',
                                     conflicts=conflicts)
     bmp.source_branch.last_scanned_id = preview.source_revision_id
     bmp.target_branch.last_scanned_id = preview.target_revision_id
     # Update the values directly sidestepping the security.
     naked_diff = removeSecurityProxy(preview)
     naked_diff.diff_lines_count = line_count
     naked_diff.added_lines_count = added
     naked_diff.removed_lines_count = removed
     naked_diff.diffstat = diffstat
     # In order to get the canonical url of the librarian file, we need to
     # commit.
     # transaction.commit()
     # Make sure that the preview diff is in the db for the test.
     # Storm bug: 324724
     Store.of(bmp).flush()
     return preview
コード例 #3
0
def _createUbuntuBugTaskLinkedToQuestion():
    """Get the id of an Ubuntu bugtask linked to a question.

    The Ubuntu team is set as the answer contact for Ubuntu, and no-priv
    is used as the submitter..
    """
    login('*****@*****.**')
    sample_person = getUtility(IPersonSet).getByEmail('*****@*****.**')
    ubuntu_team = getUtility(IPersonSet).getByName('ubuntu-team')
    ubuntu_team.addLanguage(getUtility(ILanguageSet)['en'])
    ubuntu = getUtility(IDistributionSet).getByName('ubuntu')
    ubuntu.addAnswerContact(ubuntu_team, ubuntu_team.teamowner)
    ubuntu_question = ubuntu.newQuestion(
        sample_person, "Can't install Ubuntu",
        "I insert the install CD in the CD-ROM drive, but it won't boot.")
    no_priv = getUtility(IPersonSet).getByEmail('*****@*****.**')
    params = CreateBugParams(owner=no_priv,
                             title="Installer fails on a Mac PPC",
                             comment=ubuntu_question.description)
    bug = ubuntu.createBug(params)
    ubuntu_question.linkBug(bug)
    [ubuntu_bugtask] = bug.bugtasks
    login(ANONYMOUS)
    # Remove the notifcations for the newly created question.
    pop_notifications()
    return ubuntu_bugtask.id
コード例 #4
0
 def test_requestBuild_not_owner(self):
     # If the requester is not the owner or a member of the owner team,
     # build requests are rejected.
     other_team = self.factory.makeTeam(displayname="Other Team")
     distroseries = self.factory.makeDistroSeries(registrant=self.person)
     distroarchseries = self.factory.makeDistroArchSeries(
         distroseries=distroseries, owner=self.person)
     distroarchseries_url = api_url(distroarchseries)
     archive_url = api_url(distroseries.main_archive)
     other_webservice = webservice_for_person(
         other_team.teamowner, permission=OAuthPermission.WRITE_PUBLIC)
     other_webservice.default_api_version = "devel"
     login(ANONYMOUS)
     livefs, _ = self.makeLiveFS(owner=other_team,
                                 distroseries=distroseries,
                                 webservice=other_webservice)
     response = self.webservice.named_post(
         livefs["self_link"],
         "requestBuild",
         archive=archive_url,
         distro_arch_series=distroarchseries_url,
         pocket="Release")
     self.assertEqual(401, response.status)
     self.assertEqual(
         "Test Person cannot create live filesystem builds owned by Other "
         "Team.", response.body)
コード例 #5
0
 def test_correct_value_is_cached(self):
     login(ANONYMOUS)
     menu = TestMenu(object())
     link = menu._get_link('test_link')
     request = get_current_browser_request()
     cache = request.annotations.get(MENU_ANNOTATION_KEY)
     self.assertEquals([link], cache.values())
コード例 #6
0
ファイル: test_menu.py プロジェクト: vitaminmoo/unnaturalcode
 def test_cache_when_there_is_a_request(self):
     login(ANONYMOUS)
     menu = TestMenu(object())
     menu._get_link("test_link")
     self.assertEquals(menu.times_called, 1)
     menu._get_link("test_link")
     self.assertEquals(menu.times_called, 1)
コード例 #7
0
 def testDisallowNoOpSetStatus(self):
     """Test that calling setStatus to change to the same status
     raises an InvalidQuestionStateError.
     """
     login('*****@*****.**')
     self.assertRaises(InvalidQuestionStateError, self.question.setStatus,
             self.admin, QuestionStatus.OPEN, 'Status Change')
コード例 #8
0
 def makeCommentAndSubscriber(self,
                              notification_level=None,
                              body=None,
                              as_reply=False,
                              vote=None,
                              vote_tag=None,
                              subject=None):
     """Return a comment and a subscriber."""
     sender = self.factory.makePerson(displayname='Sender',
                                      email='*****@*****.**')
     comment = self.factory.makeCodeReviewComment(sender,
                                                  body=body,
                                                  vote=vote,
                                                  vote_tag=vote_tag,
                                                  subject=subject)
     if as_reply:
         comment = self.factory.makeCodeReviewComment(sender,
                                                      body=body,
                                                      parent=comment,
                                                      subject=subject)
     subscriber = self.factory.makePerson(displayname='Subscriber',
                                          email='*****@*****.**')
     if notification_level is None:
         notification_level = CodeReviewNotificationLevel.FULL
     comment.branch_merge_proposal.source_branch.subscribe(
         subscriber, BranchSubscriptionNotificationLevel.NOEMAIL, None,
         notification_level, subscriber)
     # Email is not sent on construction, so fake a root message id on the
     # merge proposal.
     login_person(comment.branch_merge_proposal.registrant)
     comment.branch_merge_proposal.root_message_id = 'fake-id'
     # Log our test user back in.
     login('*****@*****.**')
     return comment, subscriber
コード例 #9
0
    def test_cancel_build(self):
        """An admin can cancel a build."""
        queue = self.factory.makeSourcePackageRecipeBuildJob()
        build = queue.specific_job.build
        transaction.commit()
        build_url = canonical_url(build)
        logout()

        browser = self.getUserBrowser(build_url, user=self.admin)
        browser.getLink('Cancel build').click()

        self.assertEqual(
            browser.getLink('Cancel').url,
            build_url)

        browser.getControl('Cancel build').click()

        self.assertEqual(
            browser.url,
            build_url)

        login(ANONYMOUS)
        self.assertEqual(
            BuildStatus.SUPERSEDED,
            build.status)
コード例 #10
0
 def setUp(self):
     super(TestConfigureBugTrackerBase, self).setUp()
     login('*****@*****.**')
     self.target = self.makeTarget()
     self.menu = self.getMenu()
     self.view = create_initialized_view(self.target, name="+index",
                                         layer=BugsLayer)
コード例 #11
0
    def test_rescore_build(self):
        """An admin can rescore a build."""
        queue = self.factory.makeSourcePackageRecipeBuildJob()
        build = queue.specific_job.build
        transaction.commit()
        build_url = canonical_url(build)
        logout()

        browser = self.getUserBrowser(build_url, user=self.admin)
        browser.getLink('Rescore build').click()

        self.assertEqual(
            browser.getLink('Cancel').url,
            build_url)

        browser.getControl('Score').value = '1024'

        browser.getControl('Rescore build').click()

        self.assertEqual(
            browser.url,
            build_url)

        login(ANONYMOUS)
        self.assertEqual(
            build.buildqueue_record.lastscore,
            1024)
コード例 #12
0
    def test_script_run(self):
        # Before we run the script, the LibraryFileAliases with id 1, 2 and 3
        # will have download counts set to 0.  After the script's run, each of
        # them will have their download counts set to 1, matching the sample
        # log files we use for this test:
        # scripts/tests/apache-log-files-for-sampledata.
        login(ANONYMOUS)
        libraryfile_set = getUtility(ILibraryFileAliasSet)
        self.assertEqual(libraryfile_set[1].hits, 0)
        self.assertEqual(libraryfile_set[2].hits, 0)
        self.assertEqual(libraryfile_set[3].hits, 0)

        process = subprocess.Popen(
            'cronscripts/parse-librarian-apache-access-logs.py',
            shell=True,
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)
        (out, err) = process.communicate()
        self.assertEqual(process.returncode, 0,
                         "stdout:%s, stderr:%s" % (out, err))

        # Must commit because the changes were done in another transaction.
        import transaction
        transaction.commit()
        self.assertEqual(libraryfile_set[1].hits, 1)
        self.assertEqual(libraryfile_set[2].hits, 1)
        self.assertEqual(libraryfile_set[3].hits, 1)
コード例 #13
0
 def test_attachments_query_counts_constant(self):
     # XXX j.c.sackett 2010-09-02 bug=619017
     # This test was being thrown off by the reference bug. To get around
     # the problem, flush and reset are called on the bug storm cache
     # before each call to the webservice. When lp's storm is updated
     # to release the committed fix for this bug, please see about
     # updating this test.
     login(USER_EMAIL)
     self.bug = self.factory.makeBug()
     store = Store.of(self.bug)
     self.factory.makeBugAttachment(self.bug)
     self.factory.makeBugAttachment(self.bug)
     webservice = LaunchpadWebServiceCaller('launchpad-library',
                                            'salgado-change-anything')
     collector = RequestTimelineCollector()
     collector.register()
     self.addCleanup(collector.unregister)
     url = '/bugs/%d/attachments?ws.size=75' % self.bug.id
     # First request.
     store.flush()
     store.reset()
     response = webservice.get(url)
     self.assertThat(collector, HasQueryCount(LessThan(24)))
     with_2_count = collector.count
     self.assertEqual(response.status, 200)
     login(USER_EMAIL)
     for i in range(5):
         self.factory.makeBugAttachment(self.bug)
     logout()
     # Second request.
     store.flush()
     store.reset()
     response = webservice.get(url)
     self.assertThat(collector, HasQueryCount(Equals(with_2_count)))
コード例 #14
0
 def test_webservice_traverse(self):
     login(ANONYMOUS)
     product = self.factory.makeProduct()
     context, view, request = test_traverse(
         'http://api.launchpad.dev/devel/' + product.name)
     self.assertEqual(product, context)
     self.assertIsInstance(view, EntryResource)
コード例 #15
0
    def test_linkFAQPermission(self):
        """Test that only a logged in user can access linkFAQ()."""
        login(ANONYMOUS)
        self.assertRaises(Unauthorized, getattr, self.question, 'linkFAQ')

        login_person(self.answerer)
        getattr(self.question, 'linkFAQ')
コード例 #16
0
 def setUp(self):
     """Create a ppa for the tests and login as an admin."""
     super(TestArchivePrivacySwitchingView, self).setUp()
     self.ppa = self.factory.makeArchive()
     # Login as an admin to ensure access to the view's context
     # object.
     login("*****@*****.**")
コード例 #17
0
    def testRejectPermission(self):
        """Test the reject() access control.

        Only an answer contacts and administrator can reject a question.
        """
        login(ANONYMOUS)
        self.assertRaises(Unauthorized, getattr, self.question, 'reject')

        login_person(self.owner)
        self.assertRaises(Unauthorized, getattr, self.question, 'reject')

        login_person(self.answerer)
        self.assertRaises(Unauthorized, getattr, self.question, 'reject')

        # Answer contacts must speak a language
        self.answerer.addLanguage(getUtility(ILanguageSet)['en'])
        self.question.target.addAnswerContact(self.answerer, self.answerer)
        # clear authorization cache for check_permission
        clear_cache()
        self.assertTrue(
            getattr(self.question, 'reject'),
            "Answer contact cannot reject question.")
        login_person(self.admin)
        self.assertTrue(
            getattr(self.question, 'reject'),
            "Admin cannot reject question.")
コード例 #18
0
 def test_cache_when_there_is_a_request(self):
     login(ANONYMOUS)
     menu = TestMenu(object())
     menu._get_link('test_link')
     self.assertEquals(menu.times_called, 1)
     menu._get_link('test_link')
     self.assertEquals(menu.times_called, 1)
コード例 #19
0
 def test_link_shows_email_if_necessary(self):
     # If nothing else is available, the author link will show the
     # author's email address.
     login(USER_EMAIL)
     email = "*****@*****.**" % self.factory.getUniqueString()
     revision = self.factory.makeRevision(author=email)
     self.assertEqual(email, self._formatAuthorLink(revision))
コード例 #20
0
 def setUp(self):
     super(ExtractBugTrackerAndBugTest, self).setUp()
     login(ANONYMOUS)
     self.bugwatch_set = getUtility(IBugWatchSet)
     self.bugtracker_set = getUtility(IBugTrackerSet)
     self.sample_person = getUtility(IPersonSet).getByEmail(
         '*****@*****.**')
コード例 #21
0
 def test_email_is_escaped(self):
     # The author's email address is HTML-escaped.
     login(USER_EMAIL)
     raw_email = "a&[email protected]"
     escaped_email = "a&[email protected]"
     revision = self.factory.makeRevision(author=raw_email)
     self.assertEqual(escaped_email, self._formatAuthorLink(revision))
コード例 #22
0
ファイル: test_menu.py プロジェクト: vitaminmoo/unnaturalcode
 def test_correct_value_is_cached(self):
     login(ANONYMOUS)
     menu = TestMenu(object())
     link = menu._get_link("test_link")
     request = get_current_browser_request()
     cache = request.annotations.get(MENU_ANNOTATION_KEY)
     self.assertEquals([link], cache.values())
コード例 #23
0
 def test_traverse_stores_the_path(self):
     login(ANONYMOUS)
     object, view, request = test_traverse(
         'http://launchpad.dev/+yuitest/'
         'lib/lp/testing/tests/test_yuixhr_fixture.js')
     self.assertEquals('lib/lp/testing/tests/test_yuixhr_fixture.js',
                       removeSecurityProxy(view).traversed_path)
コード例 #24
0
 def test_distro_owners_can_edit(self):
     dsp = self.factory.makeDistroSeriesParent()
     person = self.factory.makePerson()
     login(LAUNCHPAD_ADMIN)
     dsp.derived_series.distribution.owner = person
     with person_logged_in(person):
         self.assertCanEdit(dsp)
コード例 #25
0
 def setUp(self):
     login(ANONYMOUS)
     self._original_launch_bag = getUtility(ILaunchBag)
     self.factory = LaunchpadObjectFactory()
     self.launch_bag = self.installLaunchBag(
         user=self.factory.makePerson(), product=self.factory.makeProduct())
     self.popup = self.makeBranchPopup()
コード例 #26
0
 def test_link_shows_email_if_necessary(self):
     # If nothing else is available, the author link will show the
     # author's email address.
     login(USER_EMAIL)
     email = "*****@*****.**" % self.factory.getUniqueString()
     revision = self.factory.makeRevision(author=email)
     self.assertEqual(email, self._formatAuthorLink(revision))
コード例 #27
0
 def test_traverse_stores_the_path(self):
     login(ANONYMOUS)
     object, view, request = test_traverse(
         'http://launchpad.dev/+yuitest/'
         'lib/lp/testing/tests/test_yuixhr_fixture.js')
     self.assertEquals('lib/lp/testing/tests/test_yuixhr_fixture.js',
                       removeSecurityProxy(view).traversed_path)
コード例 #28
0
 def test_messages_query_counts_constant(self):
     # XXX Robert Collins 2010-09-15 bug=619017
     # This test may be thrown off by the reference bug. To get around the
     # problem, flush and reset are called on the bug storm cache before
     # each call to the webservice. When lp's storm is updated to release
     # the committed fix for this bug, please see about updating this test.
     login(USER_EMAIL)
     bug = self.factory.makeBug()
     store = Store.of(bug)
     self.factory.makeBugComment(bug)
     self.factory.makeBugComment(bug)
     self.factory.makeBugComment(bug)
     webservice = LaunchpadWebServiceCaller('launchpad-library',
                                            'salgado-change-anything')
     collector = QueryCollector()
     collector.register()
     self.addCleanup(collector.unregister)
     url = '/bugs/%d/messages?ws.size=75' % bug.id
     # First request.
     store.flush()
     store.reset()
     response = webservice.get(url)
     self.assertThat(collector, HasQueryCount(LessThan(24)))
     with_2_count = collector.count
     self.failUnlessEqual(response.status, 200)
     login(USER_EMAIL)
     for i in range(50):
         self.factory.makeBugComment(bug)
     self.factory.makeBugAttachment(bug)
     logout()
     # Second request.
     store.flush()
     store.reset()
     response = webservice.get(url)
     self.assertThat(collector, HasQueryCount(Equals(with_2_count)))
コード例 #29
0
 def test_initial_branches_does_not_contain_private_dev_focus_branch(self):
     product, branch = self.makeProductAndDevelopmentFocusBranch(
         information_type=InformationType.USERDATA)
     login(ANONYMOUS)
     view = create_initialized_view(
         product, '+code-index', rootsite='code')
     self.assertNotIn(branch, view.initial_branches)
コード例 #30
0
 def test_messages_query_counts_constant(self):
     # XXX Robert Collins 2010-09-15 bug=619017
     # This test may be thrown off by the reference bug. To get around the
     # problem, flush and reset are called on the bug storm cache before
     # each call to the webservice. When lp's storm is updated to release
     # the committed fix for this bug, please see about updating this test.
     login(USER_EMAIL)
     bug = self.factory.makeBug()
     store = Store.of(bug)
     self.factory.makeBugComment(bug)
     self.factory.makeBugComment(bug)
     self.factory.makeBugComment(bug)
     webservice = LaunchpadWebServiceCaller(
         'launchpad-library', 'salgado-change-anything')
     collector = QueryCollector()
     collector.register()
     self.addCleanup(collector.unregister)
     url = '/bugs/%d/messages?ws.size=75' % bug.id
     # First request.
     store.flush()
     store.reset()
     response = webservice.get(url)
     self.assertThat(collector, HasQueryCount(LessThan(24)))
     with_2_count = collector.count
     self.failUnlessEqual(response.status, 200)
     login(USER_EMAIL)
     for i in range(50):
         self.factory.makeBugComment(bug)
     self.factory.makeBugAttachment(bug)
     logout()
     # Second request.
     store.flush()
     store.reset()
     response = webservice.get(url)
     self.assertThat(collector, HasQueryCount(Equals(with_2_count)))
コード例 #31
0
 def test_email_is_escaped(self):
     # The author's email address is HTML-escaped.
     login(USER_EMAIL)
     raw_email = "a&[email protected]"
     escaped_email = "a&[email protected]"
     revision = self.factory.makeRevision(author=raw_email)
     self.assertEqual(escaped_email, self._formatAuthorLink(revision))
コード例 #32
0
    def test_script_run(self):
        # Before we run the script, the LibraryFileAliases with id 1, 2 and 3
        # will have download counts set to 0.  After the script's run, each of
        # them will have their download counts set to 1, matching the sample
        # log files we use for this test:
        # scripts/tests/apache-log-files-for-sampledata.
        login(ANONYMOUS)
        libraryfile_set = getUtility(ILibraryFileAliasSet)
        self.assertEqual(libraryfile_set[1].hits, 0)
        self.assertEqual(libraryfile_set[2].hits, 0)
        self.assertEqual(libraryfile_set[3].hits, 0)

        process = subprocess.Popen(
            'cronscripts/parse-librarian-apache-access-logs.py', shell=True,
            stdin=subprocess.PIPE, stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)
        (out, err) = process.communicate()
        self.assertEqual(
            process.returncode, 0, "stdout:%s, stderr:%s" % (out, err))

        # Must commit because the changes were done in another transaction.
        import transaction
        transaction.commit()
        self.assertEqual(libraryfile_set[1].hits, 1)
        self.assertEqual(libraryfile_set[2].hits, 1)
        self.assertEqual(libraryfile_set[3].hits, 1)
コード例 #33
0
 def setUp(self):
     super(TestDistroSeriesPackaging, self).setUp()
     self.series = self.factory.makeDistroSeries()
     self.user = self.series.distribution.owner
     login('*****@*****.**')
     component_set = getUtility(IComponentSet)
     self.packages = {}
     self.main_component = component_set['main']
     self.universe_component = component_set['universe']
     self.makeSeriesPackage('normal')
     self.makeSeriesPackage('translatable', messages=800)
     hot_package = self.makeSeriesPackage('hot', bugs=50)
     # Create a second SPPH for 'hot', to verify that duplicates are
     # eliminated in the queries.
     self.factory.makeSourcePackagePublishingHistory(
         sourcepackagename=hot_package.sourcepackagename,
         distroseries=self.series,
         component=self.universe_component,
         section_name='web')
     self.makeSeriesPackage('hot-translatable', bugs=25, messages=1000)
     self.makeSeriesPackage('main', is_main=True)
     self.makeSeriesPackage('linked')
     self.linkPackage('linked')
     transaction.commit()
     login(ANONYMOUS)
コード例 #34
0
 def setUp(self):
     """Create a ppa for the tests and login as an admin."""
     super(TestArchivePrivacySwitchingView, self).setUp()
     self.ppa = self.factory.makeArchive()
     # Login as an admin to ensure access to the view's context
     # object.
     login('*****@*****.**')
コード例 #35
0
 def test_login_with_email(self):
     # login() logs a person in by email.
     email = '*****@*****.**'
     person = self.factory.makePerson(email=email)
     logout()
     login(email)
     self.assertLoggedIn(person)
コード例 #36
0
 def setUp(self):
     """Create a distroarchseries for the tests and login as an admin."""
     super(TestDistroArchSeriesView, self).setUp()
     self.das = self.factory.makeDistroArchSeries()
     # Login as an admin to ensure access to the view's context
     # object.
     login(LAUNCHPAD_ADMIN)
コード例 #37
0
 def test_binary_query_counts(self):
     query_baseline = 40
     # Assess the baseline.
     collector = RequestTimelineCollector()
     collector.register()
     self.addCleanup(collector.unregister)
     ppa = self.factory.makeArchive()
     viewer = self.factory.makePerson()
     browser = self.getUserBrowser(user=viewer)
     with person_logged_in(viewer):
         # The baseline has one package, because otherwise the
         # short-circuit prevents the packages iteration happening at
         # all and we're not actually measuring scaling
         # appropriately.
         pkg = self.factory.makeBinaryPackagePublishingHistory(archive=ppa)
         url = canonical_url(ppa) + "/+packages"
     browser.open(url)
     self.assertThat(collector, HasQueryCount(LessThan(query_baseline)))
     expected_count = collector.count
     # Use all new objects - avoids caching issues invalidating the
     # gathered metrics.
     login(ADMIN_EMAIL)
     ppa = self.factory.makeArchive()
     viewer = self.factory.makePerson()
     browser = self.getUserBrowser(user=viewer)
     with person_logged_in(viewer):
         for i in range(3):
             pkg = self.factory.makeBinaryPackagePublishingHistory(
                 archive=ppa, distroarchseries=pkg.distroarchseries)
         url = canonical_url(ppa) + "/+packages"
     browser.open(url)
     self.assertThat(collector, HasQueryCount(Equals(expected_count)))
コード例 #38
0
 def setUp(self):
     super(TestBinaryPackageBuildWebservice, self).setUp()
     self.ppa = self.factory.makeArchive(purpose=ArchivePurpose.PPA)
     self.build = self.factory.makeBinaryPackageBuild(archive=self.ppa)
     self.webservice = webservice_for_person(
         self.ppa.owner, permission=OAuthPermission.WRITE_PUBLIC)
     login(ANONYMOUS)
コード例 #39
0
    def test_logging_in_and_logging_out_the_old_way(self):
        # A test showing that we can authenticate a request that had the
        # person/account ID stored in the 'personid' session variable instead
        # of 'accountid' -- where it's stored by logInPrincipal(). Also shows
        # that after logoutPerson() we can no longer authenticate it.
        # This is just for backwards compatibility.

        # This is to setup an interaction so that we can do the same thing
        # that's done by logInPrincipal() below.
        login('*****@*****.**')

        session = ISession(self.request)
        authdata = session['launchpad.authenticateduser']
        self.request.setPrincipal(self.principal)
        authdata['personid'] = self.principal.person.id
        authdata['logintime'] = datetime.utcnow()
        authdata['login'] = '******'
        notify(CookieAuthLoggedInEvent(self.request, '*****@*****.**'))

        # This is so that the authenticate() call below uses cookie auth.
        self.request.response.setCookie(
            config.launchpad_session.cookie, 'xxx')

        principal = getUtility(IPlacelessAuthUtility).authenticate(
            self.request)
        self.assertEqual(self.principal.id, principal.id)
        self.assertEqual(self.principal.person, principal.person)

        logoutPerson(self.request)

        principal = getUtility(IPlacelessAuthUtility).authenticate(
            self.request)
        self.assertIsNone(principal)
コード例 #40
0
 def setUp(self):
     TestCaseWithFactory.setUp(self)
     login('[email protected] ')
     self.person = self.factory.makePerson(
         name='test-person', displayname='Test Person')
     self.webservice = LaunchpadWebServiceCaller(
         'launchpad-library', 'salgado-change-anything')
コード例 #41
0
 def test_unauthorized(self):
     # Unauthorized method invocation.
     foo = Object()
     request = LaunchpadTestRequest()
     login(ANONYMOUS, request)
     obj_to_invoke = AvailableWithPermissionObject()
     self.assertRaises(Unauthorized, obj_to_invoke.test_function_foo, foo)
コード例 #42
0
 def makeCommentAndSubscriber(self, notification_level=None,
                              body=None, as_reply=False, vote=None,
                              vote_tag=None, subject=None):
     """Return a comment and a subscriber."""
     sender = self.factory.makePerson(
         displayname='Sender', email='*****@*****.**')
     comment = self.factory.makeCodeReviewComment(
         sender, body=body, vote=vote, vote_tag=vote_tag, subject=subject)
     if as_reply:
         comment = self.factory.makeCodeReviewComment(
             sender, body=body, parent=comment, subject=subject)
     subscriber = self.factory.makePerson(
         displayname='Subscriber', email='*****@*****.**')
     if notification_level is None:
         notification_level = CodeReviewNotificationLevel.FULL
     comment.branch_merge_proposal.source_branch.subscribe(
         subscriber, BranchSubscriptionNotificationLevel.NOEMAIL, None,
         notification_level, subscriber)
     # Email is not sent on construction, so fake a root message id on the
     # merge proposal.
     login_person(comment.branch_merge_proposal.registrant)
     comment.branch_merge_proposal.root_message_id = 'fake-id'
     # Log our test user back in.
     login('*****@*****.**')
     return comment, subscriber
コード例 #43
0
    def test_logging_in_and_logging_out(self):
        # A test showing that we can authenticate the request after
        # logInPrincipal() is called, and after logoutPerson() we can no
        # longer authenticate it.

        # This is to setup an interaction so that we can call logInPrincipal
        # below.
        login('*****@*****.**')

        logInPrincipal(self.request, self.principal, '*****@*****.**')
        session = ISession(self.request)
        # logInPrincipal() stores the account ID in a variable named
        # 'accountid'.
        self.failUnlessEqual(
            session['launchpad.authenticateduser']['accountid'],
            int(self.principal.id))

        # Ensure we are using cookie auth.
        self.assertIsNotNone(
            self.request.response.getCookie(config.launchpad_session.cookie)
            )

        principal = getUtility(IPlacelessAuthUtility).authenticate(
            self.request)
        self.failUnlessEqual(self.principal.id, principal.id)

        logoutPerson(self.request)

        principal = getUtility(IPlacelessAuthUtility).authenticate(
            self.request)
        self.failUnless(principal is None)
コード例 #44
0
    def test_logging_in_and_logging_out_the_old_way(self):
        # A test showing that we can authenticate a request that had the
        # person/account ID stored in the 'personid' session variable instead
        # of 'accountid' -- where it's stored by logInPrincipal(). Also shows
        # that after logoutPerson() we can no longer authenticate it.
        # This is just for backwards compatibility.

        # This is to setup an interaction so that we can do the same thing
        # that's done by logInPrincipal() below.
        login('*****@*****.**')

        session = ISession(self.request)
        authdata = session['launchpad.authenticateduser']
        self.request.setPrincipal(self.principal)
        authdata['personid'] = self.principal.person.id
        authdata['logintime'] = datetime.utcnow()
        authdata['login'] = '******'
        notify(CookieAuthLoggedInEvent(self.request, '*****@*****.**'))

        # This is so that the authenticate() call below uses cookie auth.
        self.request.response.setCookie(
            config.launchpad_session.cookie, 'xxx')

        principal = getUtility(IPlacelessAuthUtility).authenticate(
            self.request)
        self.failUnlessEqual(self.principal.id, principal.id)
        self.failUnlessEqual(self.principal.person, principal.person)

        logoutPerson(self.request)

        principal = getUtility(IPlacelessAuthUtility).authenticate(
            self.request)
        self.failUnless(principal is None)
コード例 #45
0
 def test_login_with_email(self):
     # login() logs a person in by email.
     email = '*****@*****.**'
     person = self.factory.makePerson(email=email)
     logout()
     login(email)
     self.assertLoggedIn(person)
コード例 #46
0
 def testDisallowNoOpSetStatus(self):
     """Test that calling setStatus to change to the same status
     raises an InvalidQuestionStateError.
     """
     login('*****@*****.**')
     self.assertRaises(InvalidQuestionStateError, self.question.setStatus,
                       self.admin, QuestionStatus.OPEN, 'Status Change')
コード例 #47
0
    def test_logging_in_and_logging_out(self):
        # A test showing that we can authenticate the request after
        # logInPrincipal() is called, and after logoutPerson() we can no
        # longer authenticate it.

        # This is to setup an interaction so that we can call logInPrincipal
        # below.
        login('*****@*****.**')

        logInPrincipal(self.request, self.principal, '*****@*****.**')
        session = ISession(self.request)
        # logInPrincipal() stores the account ID in a variable named
        # 'accountid'.
        self.assertEqual(
            session['launchpad.authenticateduser']['accountid'],
            int(self.principal.id))

        # Ensure we are using cookie auth.
        self.assertIsNotNone(
            self.request.response.getCookie(config.launchpad_session.cookie)
            )

        principal = getUtility(IPlacelessAuthUtility).authenticate(
            self.request)
        self.assertEqual(self.principal.id, principal.id)

        logoutPerson(self.request)

        principal = getUtility(IPlacelessAuthUtility).authenticate(
            self.request)
        self.assertIsNone(principal)
コード例 #48
0
    def test_linkFAQPermission(self):
        """Test that only a logged in user can access linkFAQ()."""
        login(ANONYMOUS)
        self.assertRaises(Unauthorized, getattr, self.question, 'linkFAQ')

        login_person(self.answerer)
        getattr(self.question, 'linkFAQ')
コード例 #49
0
 def setUp(self):
     """Create a distroarchseries for the tests and login as an admin."""
     super(TestDistroArchSeriesView, self).setUp()
     self.das = self.factory.makeDistroArchSeries()
     # Login as an admin to ensure access to the view's context
     # object.
     login(LAUNCHPAD_ADMIN)
コード例 #50
0
 def setUp(self):
     super(TestBinaryPackageBuildWebservice, self).setUp()
     self.ppa = self.factory.makeArchive(purpose=ArchivePurpose.PPA)
     self.build = self.factory.makeBinaryPackageBuild(archive=self.ppa)
     self.webservice = webservice_for_person(
         self.ppa.owner, permission=OAuthPermission.WRITE_PUBLIC)
     login(ANONYMOUS)
コード例 #51
0
 def test_binary_query_counts(self):
     query_baseline = 40
     # Assess the baseline.
     collector = QueryCollector()
     collector.register()
     self.addCleanup(collector.unregister)
     ppa = self.factory.makeArchive()
     viewer = self.factory.makePerson()
     browser = self.getUserBrowser(user=viewer)
     with person_logged_in(viewer):
         # The baseline has one package, because otherwise the
         # short-circuit prevents the packages iteration happening at
         # all and we're not actually measuring scaling
         # appropriately.
         pkg = self.factory.makeBinaryPackagePublishingHistory(
             archive=ppa)
         url = canonical_url(ppa) + "/+packages"
     browser.open(url)
     self.assertThat(collector, HasQueryCount(LessThan(query_baseline)))
     expected_count = collector.count
     # Use all new objects - avoids caching issues invalidating the
     # gathered metrics.
     login(ADMIN_EMAIL)
     ppa = self.factory.makeArchive()
     viewer = self.factory.makePerson()
     browser = self.getUserBrowser(user=viewer)
     with person_logged_in(viewer):
         for i in range(3):
             pkg = self.factory.makeBinaryPackagePublishingHistory(
                 archive=ppa, distroarchseries=pkg.distroarchseries)
         url = canonical_url(ppa) + "/+packages"
     browser.open(url)
     self.assertThat(collector, HasQueryCount(Equals(expected_count)))
コード例 #52
0
 def setUp(self):
     super(EmailNotificationTestBase, self).setUp()
     login('*****@*****.**')
     self.product_owner = self.factory.makePerson(name="product-owner")
     self.person = self.factory.makePerson(name="sample-person")
     self.product = self.factory.makeProduct(owner=self.product_owner)
     self.product_subscriber = self.factory.makePerson(
         name="product-subscriber")
     self.product.addBugSubscription(
         self.product_subscriber, self.product_subscriber)
     self.bug_subscriber = self.factory.makePerson(name="bug-subscriber")
     self.bug_owner = self.factory.makePerson(name="bug-owner")
     self.bug = self.factory.makeBug(
         target=self.product, owner=self.bug_owner,
         information_type=InformationType.USERDATA)
     self.reporter = self.bug.owner
     self.bug.subscribe(self.bug_subscriber, self.reporter)
     [self.product_bugtask] = self.bug.bugtasks
     commit()
     login('*****@*****.**')
     switch_dbuser(config.malone.bugnotification_dbuser)
     self.now = datetime.now(pytz.UTC)
     self.ten_minutes_ago = self.now - timedelta(minutes=10)
     self.notification_set = getUtility(IBugNotificationSet)
     for notification in self.notification_set.getNotificationsToSend():
         notification.date_emailed = self.now
     flush_database_updates()
コード例 #53
0
 def setUp(self):
     TestCaseWithFactory.setUp(self)
     login('[email protected] ')
     self.person = self.factory.makePerson(name='test-person',
                                           displayname='Test Person')
     self.webservice = LaunchpadWebServiceCaller('launchpad-library',
                                                 'salgado-change-anything')
コード例 #54
0
 def test_stale_targetNewer(self):
     # If the source branch has a different rev id, the diff is stale.
     mp = self._createProposalWithPreviewDiff()
     # Log in an admin to avoid the launchpad.Edit needs for last_scanned.
     login('*****@*****.**')
     mp.source_branch.last_scanned_id = 'rev-a'
     mp.target_branch.last_scanned_id = 'rev-d'
     self.assertEqual(True, mp.preview_diff.stale)
コード例 #55
0
 def test_participation_restored(self):
     # test_traverse restores the interaction (and hence
     # participation) that was present before it was called.
     request = LaunchpadTestRequest()
     login(ANONYMOUS, request)
     product = self.factory.makeProduct()
     test_traverse('https://launchpad.dev/' + product.name)
     self.assertIs(request, get_current_browser_request())