Commit 2eaec8ab authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

User: adopted `session.login`

parent 6bb7ef588881
...@@ -17,7 +17,6 @@ from urllib.parse import urlparse ...@@ -17,7 +17,6 @@ from urllib.parse import urlparse
from tests.utils.group import Group from tests.utils.group import Group
from tests.utils.user import User from tests.utils.user import User
from tests.utils import docker from tests.utils import docker
from tests.utils import session
from .constants import DATA_DIR from .constants import DATA_DIR
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -170,7 +169,7 @@ class Heptapod: ...@@ -170,7 +169,7 @@ class Heptapod:
# guaranteeing driver to be available for teardown as soon as created # guaranteeing driver to be available for teardown as soon as created
user.webdriver = self.new_webdriver() user.webdriver = self.new_webdriver()
return session.login(user) return user.login()
def wait_startup(self, first_response_timeout=INITIAL_TIMEOUT, def wait_startup(self, first_response_timeout=INITIAL_TIMEOUT,
wait_after_first_response=None): wait_after_first_response=None):
......
...@@ -77,20 +77,3 @@ def login_as_root(driver, heptapod, password): ...@@ -77,20 +77,3 @@ def login_as_root(driver, heptapod, password):
sign_in_page_login(driver, heptapod, 'root', password) sign_in_page_login(driver, heptapod, 'root', password)
logger.info("Made signed-in webdriver for user %r in %.2f seconds", logger.info("Made signed-in webdriver for user %r in %.2f seconds",
'root', time.time() - start) 'root', 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
...@@ -4,6 +4,13 @@ import requests ...@@ -4,6 +4,13 @@ import requests
import time import time
from gitlab import Gitlab # python-gitlab from gitlab import Gitlab # python-gitlab
from .selenium import (
webdriver_wait_get,
)
from .session import (
login_as_root,
sign_in_page_login,
)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -100,6 +107,23 @@ class User(object): ...@@ -100,6 +107,23 @@ class User(object):
def store_in_heptapod(self): def store_in_heptapod(self):
self.heptapod.users[self.name] = self self.heptapod.users[self.name] = self
def login(self):
"""Perform the webdriver login sequence if not already done.
Assumes :attr:`webdriver` not to be None
"""
heptapod, driver, name = self.heptapod, self.webdriver, self.name
if name == 'root':
login_as_root(driver, heptapod, self.password)
else:
start = time.time()
webdriver_wait_get(heptapod, driver, relative_uri='/users/sign_in')
sign_in_page_login(driver, heptapod, self.name,
password=self.password)
logger.info("Signed in user %s in %.2f seconds",
self.name, time.time() - start)
return driver
def signed_in_webdriver(self): def signed_in_webdriver(self):
"""Return a Selenium webdriver, authentified as self. """Return a Selenium webdriver, authentified as self.
......
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