This instance will be upgraded to Heptapod 0.23.2 on 2021-08-05 at 11:00 UTC+2 (a few minutes of down time)

Commit a5d646e9 authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

User: made webdriver a property

Now the creation of the webdriver and the login sequence are
all transparently (and lazily) handled by the `User` instance.

This is much simpler for tests, as demonstrated in the case
of the test with the external_user fixture.

This makes `Heptapod.get_user_webdriver` fairly trivial.
parent 341c98d15d38
......@@ -332,7 +332,7 @@ def test_housekeeping(test_project):
def test_external_user_can_create_project(test_group, external_user):
heptapod = test_group.heptapod
webdriver = external_user.signed_in_webdriver()
webdriver = external_user.webdriver
# if the external user has no group, there's no link to create a project.
# note that the "+" menu title itself is such a link
......@@ -159,17 +159,7 @@ class Heptapod:
return selenium.webdriver.Chrome(options=options)
def get_user_webdriver(self, user_name):
user = self.users[user_name]
driver = user.webdriver
if driver is not None:
return driver"Initializing a signed-in webdriver for user %r",
# guaranteeing driver to be available for teardown as soon as created
user.webdriver = self.new_webdriver()
return user.login()
return self.users[user_name].webdriver
def wait_startup(self, first_response_timeout=INITIAL_TIMEOUT,
......@@ -408,11 +398,11 @@ class Heptapod:
def close_webdrivers(self):
for user in self.users.values():
driver = user.webdriver
driver = user._webdriver
if driver is not None:"Closing webdriver for user %r",
user.webdriver = None
user._webdriver = None
def close(self):
if self.dead is not False:
......@@ -26,7 +26,7 @@ class User(object):
heptapod = attr.ib(repr=False)
password = attr.ib(default=None, repr=False)
token = attr.ib(default=None, repr=False)
webdriver = attr.ib(default=None, repr=False)
_webdriver = attr.ib(default=None, repr=False)
_python_gitlab_client = attr.ib(default=None, repr=False)
......@@ -110,9 +110,9 @@ class User(object):
def login(self):
"""Perform the webdriver login sequence if not already done.
Assumes :attr:`webdriver` not to be None
Assumes :attr:`_webdriver` not to be None
heptapod, driver, name = self.heptapod, self.webdriver,
heptapod, driver, name = self.heptapod, self._webdriver,
if name == 'root':
login_as_root(driver, heptapod, self.password)
......@@ -124,12 +124,20 @@ class User(object):, time.time() - start)
return driver
def signed_in_webdriver(self):
"""Return a Selenium webdriver, authentified as self.
Actual sign in sequence is performed only if not already done.
def webdriver(self):
"""Selenium webdriver, authentified as self.
return self.heptapod.get_user_webdriver(
driver = self._webdriver
if driver is not None:
return driver"Initializing a signed-in webdriver for user %r",
# guaranteeing driver to be available for teardown as soon as created
self._webdriver = self.heptapod.new_webdriver()
return self.login()
def api_request(self, method, subpath=None, **data):
"""Perform a request on user API as root"""
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