Add group support to the create_account pytest helper

This commit is contained in:
Pedro Algarvio 2022-11-03 18:31:36 +00:00 committed by Pedro Algarvio
parent 022412ebb3
commit e4c8839cd2

View file

@ -253,7 +253,7 @@ class TestAccount:
hashed_password = attr.ib(repr=False)
create_group = attr.ib(repr=False, default=False)
group_name = attr.ib()
_group = attr.ib(init=False, repr=False)
_group = attr.ib(init=True, repr=False)
_delete_account = attr.ib(init=False, repr=False, default=False)
@sminion.default
@ -299,6 +299,10 @@ class TestAccount:
)
return self._group
@group.setter
def _set_group(self, value):
self._group = value
def __enter__(self):
if not self.sminion.functions.user.info(self.username):
log.debug("Creating system account: %s", self)
@ -381,6 +385,7 @@ def create_account(
hashed_password=attr.NOTHING,
group_name=attr.NOTHING,
create_group=False,
group=attr.NOTHING,
sminion=attr.NOTHING,
):
with TestAccount(
@ -390,6 +395,7 @@ def create_account(
hashed_password=hashed_password,
group_name=group_name,
create_group=create_group,
group=group,
) as account:
yield account