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


Python Browser.addHeader方法代码示例

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


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

示例1: test_bc_navigationroot

# 需要导入模块: from Testing.testbrowser import Browser [as 别名]
# 或者: from Testing.testbrowser.Browser import addHeader [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

示例2: getBrowser

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

示例3: test_auth

# 需要导入模块: from Testing.testbrowser import Browser [as 别名]
# 或者: from Testing.testbrowser.Browser import addHeader [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

示例4: getBrowser

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

示例5: getBrowser

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

示例6: getBrowser

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

示例7: PythonScriptBrowserTests

# 需要导入模块: from Testing.testbrowser import Browser [as 别名]
# 或者: from Testing.testbrowser.Browser import addHeader [as 别名]
class PythonScriptBrowserTests(FunctionalTestCase):
    """Browser testing Python Scripts"""

    def setUp(self):
        from Products.PythonScripts.PythonScript import manage_addPythonScript
        super(PythonScriptBrowserTests, self).setUp()

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

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

        self.browser = Browser()
        self.browser.addHeader(
            'Authorization',
            'basic {}'.format(codecs.encode(  # NOQA: flake8: P101
                b'manager:manager_pass', 'base64').decode()))
        self.browser.open('http://localhost/py_script/manage_main')

    def test_ZPythonScriptHTML_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,项目名称:Products.PythonScripts,代码行数:26,代码来源:testPythonScript.py

示例8: TestControlPanel

# 需要导入模块: from Testing.testbrowser import Browser [as 别名]
# 或者: from Testing.testbrowser.Browser import addHeader [as 别名]
class TestControlPanel(base.FunctionalTestCase):

    def afterSetUp(self):
        super(TestControlPanel, self).afterSetUp()
        self.browser = Browser()

    def test_extended_form(self):
        portal_url = self.portal.absolute_url()

        self.browser.addHeader('Authorization',
                'Basic %s:%s' % (portal_owner, default_password))
        self.browser.open('%s/@@collectivegeo-controlpanel' % portal_url)

        widget = None
        try:
            widget = self.browser.getControl(
                    name='form.widgets.geo_content_types.to') or False
        except:
            self.fail(
                'geo_content_types widget not Found in controlpanel form')

        if widget:
            geo_content_types = geo_settings(self.portal).geo_content_types
            self.assertEqual(widget.options, geo_content_types)
开发者ID:seantis,项目名称:collective.geo.contentlocations,代码行数:26,代码来源:test_controlpanel.py

示例9: FunctionalTestCase

# 需要导入模块: from Testing.testbrowser import Browser [as 别名]
# 或者: from Testing.testbrowser.Browser import addHeader [as 别名]
class FunctionalTestCase(TestCase, ptc.FunctionalTestCase):

    def _setup(self):
        ptc.PloneTestCase._setup(self)
        # Replace normal mailhost with mock mailhost
        self.portal._original_MailHost = self.portal.MailHost
        self.portal.MailHost = mailhost = MockMailHost('MailHost')
        sm = getSiteManager(context=self.portal)
        sm.unregisterUtility(provided=IMailHost)
        sm.registerUtility(mailhost, provided=IMailHost)
        # Make sure our mock mailhost does not give a mailhost_warning
        # in the overview-controlpanel.
        self.configure_mail_host(u'mock', '[email protected]')

    def _clear(self, call_close_hook=0):
        self.portal.MailHost = self.portal._original_MailHost
        sm = getSiteManager(context=self.portal)
        sm.unregisterUtility(provided=IMailHost)
        sm.registerUtility(aq_base(self.portal._original_MailHost),
                           provided=IMailHost)
        ptc.PloneTestCase._clear(self)

    def get_smtp_host(self):
        if IMailSchema is None:
            # Plone 4
            return self.portal.MailHost.smtp_host
        else:
            # Plone 5.0 and higher
            registry = getUtility(IRegistry)
            mail_settings = registry.forInterface(
                IMailSchema, prefix='plone', check=False)
            return mail_settings.smtp_host

    def configure_mail_host(self, smtp_host, address=None):
        if IMailSchema is None:
            # Plone 4
            self.portal.MailHost.smtp_host = smtp_host
            if address is not None:
                self.portal.email_from_address = address
        else:
            # Plone 5.0 and higher
            registry = getUtility(IRegistry)
            mail_settings = registry.forInterface(
                IMailSchema, prefix='plone', check=False)
            if not isinstance(smtp_host, unicode):
                # must be unicode
                smtp_host = smtp_host.decode('utf-8')
            mail_settings.smtp_host = smtp_host
            if address is not None:
                if isinstance(address, unicode):
                    # must be ascii
                    address = address.encode('utf-8')
                mail_settings.email_from_address = address

    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([])

    def addMember(self, username, fullname, email):
        self.portal.portal_membership.addMember(
            username, ptc.default_password, [], [])
        member = self.portal.portal_membership.getMemberById(username)
        member.setMemberProperties({'fullname': fullname, 'email': email})

    def browser_login(self, user=None):
        if not user:
            user = ptc.default_user
        self.browser.open(self.portal.absolute_url() + '/login_form')
#.........这里部分代码省略.........
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:103,代码来源:test_integration.py


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