Skip to content

Commit

Permalink
Pages: optimize login for zope.testbrowser by using header injection.
Browse files Browse the repository at this point in the history
  • Loading branch information
jone committed Mar 24, 2013
1 parent 8b7ed9d commit 8e9e3cc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
18 changes: 12 additions & 6 deletions ftw/testing/pages.py
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions ftw/testing/tests/test_pages_plone.py
Expand Up @@ -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.')
Expand Down

0 comments on commit 8e9e3cc

Please sign in to comment.