本文整理汇总了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
示例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')
示例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')
示例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
示例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
示例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)
示例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)
示例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
示例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)
示例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"')
示例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'))
示例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')
示例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([])
示例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
示例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&fieldRealName=relatedItems"
'&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&fieldRealName=relatedItems"
'&at_url=plone/folder1/page1" rel="Home"> '
"<span>Home</span> </a>"
)
in normalize(browser.contents)
)