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


Python Browser.open方法代码示例

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


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

示例1: setUp

# 需要导入模块: from Testing.testbrowser import Browser [as 别名]
# 或者: from Testing.testbrowser.Browser import open [as 别名]
    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,代码行数:31,代码来源:base.py

示例2: test_auth

# 需要导入模块: from Testing.testbrowser import Browser [as 别名]
# 或者: from Testing.testbrowser.Browser import open [as 别名]
    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,代码行数:27,代码来源:test_testbrowser.py

示例3: test_bc_navigationroot

# 需要导入模块: from Testing.testbrowser import Browser [as 别名]
# 或者: from Testing.testbrowser.Browser import open [as 别名]
    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,代码行数:36,代码来源:test_product.py

示例4: test_raise_http_errors_false_redirect

# 需要导入模块: from Testing.testbrowser import Browser [as 别名]
# 或者: from Testing.testbrowser.Browser import open [as 别名]
    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,代码行数:10,代码来源:test_testbrowser.py

示例5: test_handle_errors_false_redirect

# 需要导入模块: from Testing.testbrowser import Browser [as 别名]
# 或者: from Testing.testbrowser.Browser import open [as 别名]
    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,代码行数:10,代码来源:test_testbrowser.py

示例6: test_handle_errors_true_redirect

# 需要导入模块: from Testing.testbrowser import Browser [as 别名]
# 或者: from Testing.testbrowser.Browser import open [as 别名]
    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,代码行数:10,代码来源:test_testbrowser.py

示例7: test_handle_errors_false

# 需要导入模块: from Testing.testbrowser import Browser [as 别名]
# 或者: from Testing.testbrowser.Browser import open [as 别名]
    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,代码行数:11,代码来源:test_testbrowser.py

示例8: test_headers_camel_case

# 需要导入模块: from Testing.testbrowser import Browser [as 别名]
# 或者: from Testing.testbrowser.Browser import open [as 别名]
    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,代码行数:12,代码来源:test_testbrowser.py

示例9: getBrowser

# 需要导入模块: from Testing.testbrowser import Browser [as 别名]
# 或者: from Testing.testbrowser.Browser import open [as 别名]
 def getBrowser(self, loggedIn=False, admin=False):
     """ instantiate and return a testbrowser for convenience """
     browser = Browser()
     if loggedIn:
         u = PloneTestCase.default_user
         p = PloneTestCase.default_password
         browser.open(self.portal.absolute_url() + "/login_form")
         browser.getControl(name='__ac_name').value = u
         browser.getControl(name='__ac_password').value = p
         browser.getControl(name='submit').click()
     return browser
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:13,代码来源:base.py

示例10: test_cookies

# 需要导入模块: from Testing.testbrowser import Browser [as 别名]
# 或者: from Testing.testbrowser.Browser import open [as 别名]
    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,代码行数:14,代码来源:test_testbrowser.py

示例11: test_handle_errors_true

# 需要导入模块: from Testing.testbrowser import Browser [as 别名]
# 或者: from Testing.testbrowser.Browser import open [as 别名]
    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,代码行数:15,代码来源:test_testbrowser.py

示例12: test_raise_http_errors_false

# 需要导入模块: from Testing.testbrowser import Browser [as 别名]
# 或者: from Testing.testbrowser.Browser import open [as 别名]
    def test_raise_http_errors_false(self):
        self.folder._setObject('stub', ExceptionStub())
        browser = Browser()
        browser.raiseHttpErrors = False

        # Internal server errors are still raised:
        with self.assertRaises(ValueError):
            browser.open('http://localhost/test_folder_1_/stub')
        self.assertIsNone(browser.contents)

        # But errors handled by Zope do not create an exception:
        browser.open('http://localhost/nothing-is-here')
        self.assertTrue(browser.headers['status'].startswith('404'))
开发者ID:dhavlik,项目名称:Zope,代码行数:15,代码来源:test_testbrowser.py

示例13: TestIDFromTitle

# 需要导入模块: from Testing.testbrowser import Browser [as 别名]
# 或者: from Testing.testbrowser.Browser import open [as 别名]
class TestIDFromTitle(FunctionalTestCase):
    """Browsertests to make sure ATImages derive their default IDs from their titles"""
    # TODO: Merge into TestATImageFunctional, below.
    
    def afterSetUp(self):
        self.userId = 'fred'
        self.password = 'secret'
        self.portal.acl_users.userFolderAddUser(self.userId, self.password, ['Manager'], [])
        self.browser = Browser()
        self._log_in()

    def _log_in(self):
        """Log in as someone who can add new Images."""
        self.browser.open(self.portal.absolute_url())
        self.browser.getLink('Log in').click()
        self.browser.getControl('Login Name').value = self.userId
        self.browser.getControl('Password').value = self.password
        self.browser.getControl('Log in').click()

    def _make_image(self, title, filename='canoneye.jpg'):
        """Add a new Image at the root of the Plone site."""
        self.browser.open(self.portal.absolute_url() + '/createObject?type_name=Image')
        self.browser.getControl('Title').value = title
        image = self.browser.getControl(name='image_file')
        image.filename = filename
        TEST_JPEG_FILE.seek(0)
        image.value = TEST_JPEG_FILE
        self.browser.getControl('Save').click()

    def test_image_id_from_filename_and_title(self):
        # Get ID from filename:
        self._make_image('')
        self.failUnless('canoneye.jpg' in self.browser.url)

        # Get ID from title.
        # As a side effect, make sure the ID validator doesn't overzealously
        # deny our upload of something else called canoneye.jpg, even though
        # we're not going to compute its ID from its filename.
        self._make_image('Wonderful Image')
        self.failUnless('/wonderful-image' in self.browser.url)

    def test_image_id_from_unicode_title(self):
        self._make_image('', filename=u'Pictüre 1.png'.encode('utf-8'))
        normalized = 'Picture%201.png'
        self.failUnless(normalized in self.browser.url)
开发者ID:nacho22martin,项目名称:tesis,代码行数:47,代码来源:test_atimage.py

示例14: test_handle_errors_false_HTTPExceptionHandler_in_app

# 需要导入模块: from Testing.testbrowser import Browser [as 别名]
# 或者: from Testing.testbrowser.Browser import open [as 别名]
    def test_handle_errors_false_HTTPExceptionHandler_in_app(self):
        """HTTPExceptionHandler does not handle errors if requested via WSGI.

        This is needed when HTTPExceptionHandler is part of the WSGI pipeline.
        """
        class WSGITestAppWithHTTPExceptionHandler(object):
            """Minimized testbrowser.WSGITestApp with HTTPExceptionHandler."""

            def __call__(self, environ, start_response):
                publish = HTTPExceptionHandler(publish_module)
                wsgi_result = publish(environ, start_response)

                return wsgi_result

        self.folder._setObject('stub', ExceptionStub())
        transaction.commit()
        browser = Browser(wsgi_app=WSGITestAppWithHTTPExceptionHandler())
        browser.handleErrors = False

        with self.assertRaises(ValueError):
            browser.open('http://localhost/test_folder_1_/stub')
        self.assertIsNone(browser.contents)
开发者ID:dhavlik,项目名称:Zope,代码行数:24,代码来源:test_testbrowser.py

示例15: ZPTBrowserTests

# 需要导入模块: from Testing.testbrowser import Browser [as 别名]
# 或者: from Testing.testbrowser.Browser import open [as 别名]
class ZPTBrowserTests(FunctionalTestCase):
    """Browser testing ZopePageTemplate"""

    def setUp(self):
        from Products.PageTemplates.ZopePageTemplate import \
            manage_addPageTemplate
        super(ZPTBrowserTests, self).setUp()

        Zope2.App.zcml.load_site(force=True)

        uf = self.app.acl_users
        uf.userFolderAddUser('manager', 'manager_pass', ['Manager'], [])
        manage_addPageTemplate(self.app, 'page_template')

        self.browser = Browser()
        self.browser.login('manager', 'manager_pass')
        self.browser.open('http://localhost/page_template/manage_main')

    def test_pt_upload__no_file(self):
        """It renders an error message if no file is uploaded."""
        self.browser.getControl('Upload File').click()
        self.assertIn('No file specified', self.browser.contents)
开发者ID:zopefoundation,项目名称:Zope,代码行数:24,代码来源:testZopePageTemplate.py


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