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