Read about our upcoming Code of Conduct on this issue

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

Fixtures: simplified by use of new Context Managers

This is again cleaner, and ultimately the reason why
we've put a long timeout and `cleanup_teardown()` in
`Project.__exit__()`, even though it's much less necessary
now than it was before we made Project names unique.
parent 4554bbdd3422
Pipeline #12820 failed with stages
in 22 seconds
......@@ -217,51 +217,31 @@ def heptapod(pytestconfig):
@contextlib.contextmanager
def project_fixture(heptapod, name_prefix, owner, group=None, **opts):
name = '%s_%s' % (name_prefix, str(time.time()).replace('.', '_'))
proj = None
try:
proj = Project.api_create(heptapod, owner, name, group=group, **opts)
with Project.api_create(heptapod, owner, name,
group=group, **opts) as proj:
yield proj
finally:
if proj is not None:
proj.api_destroy(allow_missing=True, timeout=120)
proj.cleanup_teardown()
@contextlib.contextmanager
def group_fixture(heptapod, path_prefix, creator_name='root', parent=None):
group = None
try:
group = Group.api_create(heptapod, unique_name(path_prefix),
user_name=creator_name,
parent=parent)
with Group.api_create(heptapod, unique_name(path_prefix),
user_name=creator_name,
parent=parent) as group:
yield group
finally:
if group is not None:
group.api_delete()
@pytest.fixture()
def external_user(heptapod, accepts_concurrent):
user = None
try:
user = User.create(heptapod, unique_name('external_user'),
external=True)
with User.create(heptapod, unique_name('external_user'),
external=True) as user:
yield user
finally:
if user is not None:
user.delete()
@pytest.fixture()
def additional_user(heptapod, accepts_concurrent):
user = None
try:
user = User.create(heptapod, unique_name('add_user'))
with User.create(heptapod, unique_name('add_user')) as user:
user.ensure_private_token()
yield user
finally:
if user is not None:
user.delete()
@pytest.fixture()
......
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