Commit 81c0c65d authored by Georges Racinet's avatar Georges Racinet 🌳
Browse files

session,Heptapod: standardisation of login sequence

- the webdriver is no longer created either by the `Heptapod`
  method or by the `session` module. An expected benefit is
  to avoid webdriver process leaks in case of failed logins
- the special case of the `root` user is handled transparently by
  `session.login()`
parent c49a65be9f69
......@@ -168,17 +168,9 @@ class Heptapod:
logger.info("Initializing a signed-in webdriver for user %r",
user_name)
if user_name == 'root':
driver = self.new_webdriver()
# guaranteeing driver to be available for teardown
# as soon as created
session.login_as_root(driver, self, user.password)
else:
# TODO should init webdriver from here and store it before login
# attempt as well
driver = session.make_webdriver(self, user_name, user.password)
user.webdriver = driver
return driver
# guaranteeing driver to be available for teardown as soon as created
user.webdriver = self.new_webdriver()
return session.login(user)
def wait_startup(self, first_response_timeout=INITIAL_TIMEOUT,
wait_after_first_response=None):
......
......@@ -101,11 +101,18 @@ def ensure_user(heptapod, name, password=None, fullname=None):
return user
def make_webdriver(heptapod, user_name, password):
start = time.time()
driver = heptapod.new_webdriver()
webdriver_wait_get(heptapod, driver, relative_uri='/users/sign_in')
sign_in_page_login(driver, heptapod, user_name, password=password)
logger.info("Made signed-in webdriver for user %s in %.2f seconds",
user_name, time.time() - start)
def login(user):
"""Perform login for user.
This assumes user.webdriver is already created.
"""
heptapod, driver, name = user.heptapod, user.webdriver, user.name
if name == 'root':
login_as_root(driver, heptapod, user.password)
else:
start = time.time()
webdriver_wait_get(heptapod, driver, relative_uri='/users/sign_in')
sign_in_page_login(driver, heptapod, user.name, password=user.password)
logger.info("Signed in user %s in %.2f seconds",
user.name, time.time() - start)
return driver
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