mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2024-12-24 16:10:02 -06:00
User Tracker: creation of user with minimal values
Fix provide possibility to create user-add test with minimal values, where uid is not specified, to provide better coverage. Also provide check for non-empty unicode string for attributes required in init method https://fedorahosted.org/freeipa/ticket/6126 Reviewed-By: Stanislav Laznicka <slaznick@redhat.com> Reviewed-By: Milan Kubik <mkubik@redhat.com> Reviewed-By: Lenka Doudova <ldoudova@redhat.com>
This commit is contained in:
parent
c391f6ba58
commit
fa7aaef1de
@ -62,22 +62,42 @@ class UserTracker(KerberosAliasMixin, Tracker):
|
||||
|
||||
primary_keys = {u'uid', u'dn'}
|
||||
|
||||
def __init__(self, name, givenname, sn, **kwargs):
|
||||
def __init__(self, name=None, givenname=None, sn=None, **kwargs):
|
||||
""" Check for non-empty unicode string for the required attributes
|
||||
in the init method """
|
||||
|
||||
if not (isinstance(givenname, six.string_types) and givenname):
|
||||
raise ValueError(
|
||||
"Invalid first name provided: {!r}".format(givenname)
|
||||
)
|
||||
if not (isinstance(sn, six.string_types) and sn):
|
||||
raise ValueError("Invalid second name provided: {!r}".format(sn))
|
||||
|
||||
super(UserTracker, self).__init__(default_version=None)
|
||||
self.uid = name
|
||||
self.givenname = givenname
|
||||
self.sn = sn
|
||||
self.uid = unicode(name)
|
||||
self.givenname = unicode(givenname)
|
||||
self.sn = unicode(sn)
|
||||
self.dn = DN(('uid', self.uid), api.env.container_user, api.env.basedn)
|
||||
|
||||
self.kwargs = kwargs
|
||||
|
||||
def make_create_command(self):
|
||||
""" Make function that crates a user using user-add """
|
||||
return self.make_command(
|
||||
'user_add', self.uid,
|
||||
givenname=self.givenname,
|
||||
sn=self.sn, **self.kwargs
|
||||
)
|
||||
def make_create_command(self, force=None):
|
||||
|
||||
""" Make function that creates a user using user-add
|
||||
with all set of attributes and with minimal values,
|
||||
where uid is not specified """
|
||||
|
||||
if self.uid is not None:
|
||||
return self.make_command(
|
||||
'user_add', self.uid,
|
||||
givenname=self.givenname,
|
||||
sn=self.sn, **self.kwargs
|
||||
)
|
||||
else:
|
||||
return self.make_command(
|
||||
'user_add', givenname=self.givenname,
|
||||
sn=self.sn, **self.kwargs
|
||||
)
|
||||
|
||||
def make_delete_command(self, no_preserve=True, preserve=False):
|
||||
""" Make function that deletes a user using user-del
|
||||
|
Loading…
Reference in New Issue
Block a user