This instance will be upgraded to Heptapod 0.26.0rc1 on 2021-10-25 at 14:00 UTC+2 (a few minutes of down time)

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

User: adopted session.ensure_user

This follows up on the principle that the `session` module should
be lower level than the `Heptapod` and `User` classes and prepares
for future refactorings by avoiding import loops.
parent 6254d1e283b2
......@@ -312,9 +312,9 @@ class Heptapod:
self.set_vcs_types_settings(['hg', 'git', 'hg_git'])
logger.info("Preparing basic user.")
session.ensure_user(self, 'test_basic',
fullname='Bäsîc Test',
password='test_basic')
User.ensure(self, 'test_basic',
fullname='Bäsîc Test',
password='test_basic')
logger.info("Uploading users SSH keys.")
self.load_ssh_keys()
......
......@@ -3,7 +3,6 @@ from selenium.webdriver.common.keys import Keys
import time
from .selenium import webdriver_wait_get
from .user import default_password, User
logger = logging.getLogger(__name__)
......@@ -80,27 +79,6 @@ def login_as_root(driver, heptapod, password):
'root', time.time() - start)
def ensure_user(heptapod, name, password=None, fullname=None):
"""Retrieve user or create it.
:returns: `User` instance
"""
if password is None:
password = default_password(password)
user = heptapod.users.get(name)
if user is None:
user = User.search(heptapod, name)
if user is None:
user = User.create(heptapod, name,
password=password, fullname=fullname)
user.store_in_heptapod()
user.password = password
user.ensure_private_token()
return user
def login(user):
"""Perform login for user.
......
......@@ -55,6 +55,27 @@ class User(object):
user.store_in_heptapod()
return user
@classmethod
def ensure(cls, heptapod, name, password=None, fullname=None):
"""Retrieve user or create it.
:returns: `User` instance
"""
if password is None:
password = default_password(password)
user = heptapod.users.get(name)
if user is None:
user = User.search(heptapod, name)
if user is None:
user = User.create(heptapod, name,
password=password, fullname=fullname)
user.store_in_heptapod()
user.password = password
user.ensure_private_token()
return user
@classmethod
def search(cls, heptapod, name):
"""Lookup user in API and returns instance.
......
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