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

User: adopted logic to close webdriver

Even the `Heptapod` instance should not care about the `_webdriver`
attribute, which is now an implementation detail.

Also allows to close the webdriver immediately if there's any
in `delete()`.
parent 391820b64471
......@@ -398,11 +398,7 @@ class Heptapod:
def close_webdrivers(self):
for user in self.users.values():
driver = user._webdriver
if driver is not None:
logger.info("Closing webdriver for user %r", user.name)
driver.close()
user._webdriver = None
user.close_webdriver()
def close(self):
if self.dead is not False:
......
......@@ -139,6 +139,16 @@ class User(object):
self._webdriver = self.heptapod.new_webdriver()
return self.login()
def close_webdriver(self):
"""Close current web driver if there is one."""
driver = self._webdriver
if driver is None:
return
logger.info("Closing webdriver for user %r", self.name)
driver.close()
self._webdriver = None
def api_request(self, method, subpath=None, **data):
"""Perform a request on user API as root"""
hepta = self.heptapod
......@@ -153,6 +163,8 @@ class User(object):
return self.api_request('POST', subpath=subpath, **data)
def delete(self, hard=True):
self.close_webdriver()
# TODO also remove from Heptapod instance
hepta = self.heptapod
resp = requests.delete(
'/'.join((hepta.api_url, 'users', str(self.id))),
......
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