Commit 52540f19 authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

Testing production servers: defaulting to topmost group

This is a bit nicer for users, a reasonable default instead
of a mandatory group id.

branch : stable
parent 9796ee2d68f1
......@@ -63,6 +63,9 @@ def pytest_addoption(parser):
group.addoption('--heptapod-prod-group-id', type=int,
help="prod servers only: numeric id for the group "
"where most projects and subgroups are to be created. "
"If not specified, a random group with minimal depth "
"among those owned by the user given in "
"--heptapod-prod-group-owner-credentials will be used."
"Some tests may still use personal namespaces.")
parser.addoption('--heptapod-remote', action='store_true',
help="Test a remote server. This means that no "
......@@ -538,6 +538,18 @@ class ProductionHeptapod(Heptapod):
def init_default_group(self):
gid = self.default_group_id
if gid is None:
groups = self.group_owner.api_owned_groups()
min_depth = None
for group in groups:
depth = group['full_path'].count('/')
if min_depth is None or depth < min_depth:
min_depth = depth
gid = group['id']
if gid is None:
raise RuntimeError(
"Could not find a group owned by %r" % self.group_owner)
self.default_group = Group.api_retrieve(
self, gid,
......@@ -220,7 +220,20 @@ class User(object):
return None
return requests.get(self.heptapod.api_url + '/users/%d' %,
headers={'Private-Token': token})
def api_owned_groups(self):
"""List the groups owned by this user.
TODO it lists actually the first page, which is expected to
be good enough for the foreseeable future.
resp = requests.get(self.heptapod.api_url + '/groups',
assert resp.status_code < 400
return resp.json()
def ensure_private_token(self):
"""Generate a private token for already logged in user if needed.
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