当前位置: 首页>>代码示例>>Python>>正文


Python testbrowser.Browser类代码示例

本文整理汇总了Python中Testing.testbrowser.Browser的典型用法代码示例。如果您正苦于以下问题:Python Browser类的具体用法?Python Browser怎么用?Python Browser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Browser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getBrowser

 def getBrowser(self, loggedIn=True):
     """ instantiate and return a testbrowser for convenience """
     browser = Browser()
     if loggedIn:
         auth = 'Basic %s' % self.getCredentials()
         browser.addHeader('Authorization', auth)
     return browser
开发者ID:Vinsurya,项目名称:Plone,代码行数:7,代码来源:base.py

示例2: test_raise_http_errors_false_redirect

    def test_raise_http_errors_false_redirect(self):
        self.folder._setObject('redirect', RedirectStub())
        browser = Browser()
        browser.raiseHttpErrors = False

        browser.open('http://localhost/test_folder_1_/redirect')
        self.assertTrue(browser.headers['status'].startswith('404'))
        self.assertEqual(browser.url, 'http://localhost/redirected')
开发者ID:dhavlik,项目名称:Zope,代码行数:8,代码来源:test_testbrowser.py

示例3: test_handle_errors_true_redirect

    def test_handle_errors_true_redirect(self):
        self.folder._setObject('redirect', RedirectStub())
        browser = Browser()

        with self.assertRaises(HTTPError):
            browser.open('http://localhost/test_folder_1_/redirect')
        self.assertTrue(browser.headers['status'].startswith('404'))
        self.assertEqual(browser.url, 'http://localhost/redirected')
开发者ID:dhavlik,项目名称:Zope,代码行数:8,代码来源:test_testbrowser.py

示例4: getBrowser

 def getBrowser(self, loggedIn=False):
     """ instantiate and return a testbrowser for convenience """
     browser = Browser()
     if loggedIn:
         user = PloneTestCase.default_user
         pwd = PloneTestCase.default_password
         browser.addHeader('Authorization', 'Basic %s:%s' % (user, pwd))
     return browser
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:8,代码来源:testDocTests.py

示例5: getBrowser

 def getBrowser(self, loggedIn=True):
     """ instantiate and return a testbrowser for convenience """
     browser = Browser()
     if loggedIn:
         user = default_user
         pwd = default_password
         browser.addHeader("Authorization", "Basic %s:%s" % (user, pwd))
     return browser
开发者ID:seantis,项目名称:Products.CMFPlone,代码行数:8,代码来源:PloneTestCase.py

示例6: test_handle_errors_false_redirect

    def test_handle_errors_false_redirect(self):
        self.folder._setObject('redirect', RedirectStub())
        browser = Browser()
        browser.handleErrors = False

        with self.assertRaises(NotFound):
            browser.open('http://localhost/test_folder_1_/redirect')
        self.assertTrue(browser.contents is None)
开发者ID:dhavlik,项目名称:Zope,代码行数:8,代码来源:test_testbrowser.py

示例7: test_handle_errors_false

    def test_handle_errors_false(self):
        self.folder._setObject('stub', ExceptionStub())
        browser = Browser()
        browser.handleErrors = False

        # Even errors which can be handled by Zope go to the client:
        with self.assertRaises(NotFound):
            browser.open('http://localhost/nothing-is-here')
        self.assertTrue(browser.contents is None)
开发者ID:dhavlik,项目名称:Zope,代码行数:9,代码来源:test_testbrowser.py

示例8: getBrowser

 def getBrowser(self, logged_in=False):
     """ instantiate and return a testbrowser for convenience """
     browser = Browser()
     if logged_in:
         # Add an authorization header using the given or default
         # credentials """
         browser.addHeader('Authorization', 'Basic %s:%s' % (
                 PloneTestCase.portal_owner,
                 PloneTestCase.default_password))
     return browser
开发者ID:nacho22martin,项目名称:tesis,代码行数:10,代码来源:test_configlet.py

示例9: test_headers_camel_case

    def test_headers_camel_case(self):
        # The Zope2 response mungs headers so they come out
        # in camel case. We should do the same.
        self.folder._setObject('stub', CookieStub())

        browser = Browser()
        browser.open('http://localhost/test_folder_1_/stub')
        header_text = str(browser.headers)
        self.assertTrue('Content-Length: ' in header_text)
        self.assertTrue('Content-Type: ' in header_text)
开发者ID:dhavlik,项目名称:Zope,代码行数:10,代码来源:test_testbrowser.py

示例10: test_cookies

    def test_cookies(self):
        # We want to make sure that our testbrowser correctly
        # understands cookies.
        self.folder._setObject('stub', CookieStub())

        # Test direct publishing
        response = self.publish('/test_folder_1_/stub')
        self.assertEqual(response.getCookie('evil')['value'], 'cookie')

        browser = Browser()
        browser.open('http://localhost/test_folder_1_/stub')
        self.assertEqual(browser.cookies.get('evil'), '"cookie"')
开发者ID:dhavlik,项目名称:Zope,代码行数:12,代码来源:test_testbrowser.py

示例11: test_handle_errors_true

    def test_handle_errors_true(self):
        self.folder._setObject('stub', ExceptionStub())
        browser = Browser()

        # An error which cannot be handled by Zope is propagated to the client:
        with self.assertRaises(ValueError):
            browser.open('http://localhost/test_folder_1_/stub')
        self.assertIsNone(browser.contents)

        # Handled errors become an instance of `HTTPError`:
        with self.assertRaises(HTTPError):
            browser.open('http://localhost/nothing-is-here')
        self.assertTrue(browser.headers['status'].startswith('404'))
开发者ID:dhavlik,项目名称:Zope,代码行数:13,代码来源:test_testbrowser.py

示例12: test_auth

    def test_auth(self):
        # Based on Testing.ZopeTestCase.testFunctional
        basic_auth = '%s:%s' % (user_name, user_password)
        self.folder.addDTMLDocument('secret_html', file='secret')
        self.folder.secret_html.manage_permission(view, ['Owner'])
        path = '/' + self.folder.absolute_url(1) + '/secret_html'

        # Test direct publishing
        response = self.publish(path + '/secret_html')
        self.assertEqual(response.getStatus(), 401)
        response = self.publish(path + '/secret_html', basic_auth)
        self.assertEqual(response.getStatus(), 200)
        self.assertEqual(response.getBody(), b'secret')

        # Test browser
        url = 'http://localhost' + path
        browser = Browser()
        browser.raiseHttpErrors = False
        browser.open(url)
        self.assertTrue(browser.headers['status'].startswith('401'))

        browser.addHeader('Authorization', 'Basic ' + basic_auth)
        browser.open(url)
        self.assertTrue(browser.headers['status'].startswith('200'))
        self.assertEqual(browser.contents, 'secret')
开发者ID:dhavlik,项目名称:Zope,代码行数:25,代码来源:test_testbrowser.py

示例13: afterSetUp

    def afterSetUp(self):
        """Add some extra content and do some setup.
        """
        # We need to do this as Manager:
        self.setRoles(['Manager'])

        # Add some news items:
        sample_text = "<p>Have I got news for <em>you</em>!</p>"
        self.portal.news.invokeFactory(
            'News Item', 'first', title="First News", text=sample_text)
        self.portal.news.invokeFactory(
            'News Item', 'second', title="Second News", text=sample_text)

        # Set fullname and email address of test user:
        member = self.portal.portal_membership.getAuthenticatedMember()
        member.setMemberProperties({'fullname': 'Test User',
                                    'email': '[email protected]'})

        # Add extra members:
        self.addMember('maurits', 'Maurits van Rees', '[email protected]')
        self.addMember('reinout', 'Reinout van Rees', '[email protected]')

        # Setup test browser:
        try:
            from Testing.testbrowser import Browser
            Browser  # pyflakes
        except ImportError:
            from Products.Five.testbrowser import Browser
        self.browser = Browser()
        self.browser.handleErrors = False
        self.browser.addHeader('Accept-Language', 'en-US')
        self.portal.error_log._ignored_exceptions = ()

        # No more Manager:
        self.setRoles([])
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:35,代码来源:test_integration.py

示例14: setUp

    def setUp(self):
        """\
        Sets up the environment that the workspace doctest needs.
        """

        DocTestCase.setUp(self)
        from Testing.testbrowser import Browser
        from Products.PloneTestCase.setup import default_user, default_password

        from pmr2.app.settings.interfaces import IPMR2GlobalSettings

        # point the physical root for repo_root to the tmpdir.
        self.pmr2 = zope.component.getUtility(IPMR2GlobalSettings)
        self.pmr2.repo_root = self.tmpdir

        # user workspace
        _createObjectByType('Folder', self.portal, id='w')
        self.pmr2.user_workspace_subpath = u'w'
        self.pmr2.create_user_workspace = True

        # set up test browser with default user logged in.
        b = Browser()
        portal_url = self.portal.absolute_url()
        b.open(portal_url + '/login')
        b.getControl(name='__ac_name').value = default_user
        b.getControl(name='__ac_password').value = default_password
        b.getControl(name='submit').click()

        self.testbrowser = b
开发者ID:PMR2,项目名称:pmr2.app,代码行数:29,代码来源:base.py

示例15: test_bc_navigationroot

    def test_bc_navigationroot(self):
        makeContent(self.portal.folder1, portal_type="Document", id="page1")

        page = self.portal.folder1.page1

        browser = Browser()
        data = {"fieldName": "relatedItems", "fieldRealName": "relatedItems", "at_url": page.absolute_url(1)}

        basic = "%s:%s" % (portal_owner, default_password)

        browser.addHeader("Authorization", "Basic %s" % basic)
        browser.open("%s/refbrowser_popup?%s" % (page.absolute_url(), urlencode(data)))
        self.assertTrue(
            (
                '<a class="browsesite" href="http://nohost/plone/refbrowser_popup?'
                "fieldName=relatedItems&amp;fieldRealName=relatedItems"
                '&amp;at_url=plone/folder1/page1" rel="Home"> '
                "<span>Home</span> </a>"
            )
            in normalize(browser.contents)
        )

        # now let's change the navigation root
        zope.interface.alsoProvides(self.portal.folder1, INavigationRoot)
        browser.open("%s/refbrowser_popup?%s" % (page.absolute_url(), urlencode(data)))
        self.assertTrue(
            (
                '<a class="browsesite" href="http://nohost/plone/folder1/refbrowser_popup?'
                "fieldName=relatedItems&amp;fieldRealName=relatedItems"
                '&amp;at_url=plone/folder1/page1" rel="Home"> '
                "<span>Home</span> </a>"
            )
            in normalize(browser.contents)
        )
开发者ID:RedTurtle,项目名称:archetypes.referencebrowserwidget,代码行数:34,代码来源:test_product.py


注:本文中的Testing.testbrowser.Browser类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。