Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Pages: optimize login for zope.testbrowser by using header injection.

  • Loading branch information...
commit 8e9e3cc0972dd6e7a72cf7cdb4d22b0b27d74352 1 parent 8b7ed9d
@jone jone authored
Showing with 13 additions and 6 deletions.
  1. +12 −6 ftw/testing/pages.py
  2. +1 −0  ftw/testing/tests/test_pages_plone.py
View
18 ftw/testing/pages.py
@@ -99,12 +99,18 @@ def login(self, user=TEST_USER_NAME, password=TEST_USER_PASSWORD):
"""Log the current browser in with the passed user / password or with
the default `plone.app.testing` user if no arguemnts are passed.
"""
- # This should be implemented by setting request headers.
- browser().visit(self.concat_portal_url('login'))
- browser().fill('__ac_name', user)
- browser().fill('__ac_password', password)
- browser().find_by_xpath(
- '//input[@type="submit" and @value="Log in"]').first.click()
+
+ if self.browser_driver == 'zope.testbrowser':
+ browser()._browser.addHeader('Authorization',
+ 'Basic %s:%s' % (user, password))
+
+ else:
+ browser().visit(self.concat_portal_url('login'))
+ browser().fill('__ac_name', user)
+ browser().fill('__ac_password', password)
+ browser().find_by_xpath(
+ '//input[@type="submit" and @value="Log in"]').first.click()
+
return self
def get_first_heading(self):
View
1  ftw/testing/tests/test_pages_plone.py
@@ -32,6 +32,7 @@ def test_login__ZOPE_TESTBROWSER(self):
'Could not find login link.')
Plone().login()
+ Plone().visit_portal()
self.assertFalse(browser().find_link_by_text('Log in'),
'Found Log in link - assuming not logged in.')
Please sign in to comment.
Something went wrong with that request. Please try again.