Commit da9aa12a authored by Arnaud Fontaine's avatar Arnaud Fontaine

Add stateful login() method which opens the login page


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@45152 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 341700ce
......@@ -196,12 +196,11 @@ class Browser(ExtendedTestBrowser):
self._logger = logging.getLogger('erp5.utils.test_browser')
self._is_legacy_listbox = is_legacy_listbox
self._is_logged_in = False
super(Browser, self).__init__()
# Open login page, then login with the given username and password
self.open('login_form')
self.mainForm.submitLogin()
self.login()
def open(self, url_or_path=None, data=None):
"""
......@@ -219,6 +218,27 @@ class Browser(ExtendedTestBrowser):
self._logger.info("Opening url: " + absolute_url)
super(Browser, self).open(absolute_url, data)
def login(self, force=False):
"""
Log in only if not already logged in unless explicitely specified
to do so.
@param force: Log in even if already logged in
@type force: bool
"""
if force or not self._is_logged_in:
try:
url_before_login = self.url
except:
url_before_login = None
self.open('login_form')
self.mainForm.submitLogin()
# Go back to the page before trying to log in if any URL, or to
# the homepage otherwise
self.open(url_before_login)
def getCookieValue(self, name, default=None):
"""
Get the cookie value of the given cookie name.
......@@ -675,6 +695,8 @@ class MainForm(Form):
if 'Logged In as' not in self.browser.contents:
raise LoginError
self.browser._is_logged_in = True
def submitSelectFavourite(self, label=None, value=None):
"""
Select and submit a favourite, given either by its label (such as
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment