URL: https://github.com/freeipa/freeipa/pull/181 Author: gkaihorodova Title: #181: Tests : User Tracker creation of user with minimal values Action: synchronized
To pull the PR as Git branch: git remote add ghfreeipa https://github.com/freeipa/freeipa git fetch ghfreeipa pull/181/head:pr181 git checkout pr181
From 298e1a136c6a430e8deaa558a946ba51874ffd95 Mon Sep 17 00:00:00 2001 From: Ganna Kaihorodova <gkaih...@redhat.com> Date: Mon, 10 Oct 2016 14:00:51 +0200 Subject: [PATCH 1/3] Unaccessible variable self.attrs in Tracker In tracker, 'self.attrs' variable is created and filled in track_create method. Some objects are not created but still require access to this variable. Created 'self.attrs' variable in init https://fedorahosted.org/freeipa/ticket/6125 --- ipatests/test_xmlrpc/tracker/base.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ipatests/test_xmlrpc/tracker/base.py b/ipatests/test_xmlrpc/tracker/base.py index a2b7406..aa88e6b 100644 --- a/ipatests/test_xmlrpc/tracker/base.py +++ b/ipatests/test_xmlrpc/tracker/base.py @@ -76,6 +76,7 @@ def __init__(self, default_version=None): self.api = api self.default_version = default_version or API_VERSION self._dn = None + self.attrs = {} self.exists = False From 239ce30184b29af67a674cbc2cf0bec402212f05 Mon Sep 17 00:00:00 2001 From: Ganna Kaihorodova <gkaih...@redhat.com> Date: Thu, 8 Dec 2016 15:06:36 +0100 Subject: [PATCH 2/3] 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 --- ipatests/test_xmlrpc/tracker/user_plugin.py | 42 +++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/ipatests/test_xmlrpc/tracker/user_plugin.py b/ipatests/test_xmlrpc/tracker/user_plugin.py index 4485fd9..29b3177 100644 --- a/ipatests/test_xmlrpc/tracker/user_plugin.py +++ b/ipatests/test_xmlrpc/tracker/user_plugin.py @@ -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 """ From 7205d9feba68ba3dbe183b64f6d28833b258ddd2 Mon Sep 17 00:00:00 2001 From: Ganna Kaihorodova <gkaih...@redhat.com> Date: Thu, 8 Dec 2016 15:08:41 +0100 Subject: [PATCH 3/3] User Tracker: Test to create user with minimal values Test to create user with minimal values, where uid is not specified https://fedorahosted.org/freeipa/ticket/6126 --- ipatests/test_xmlrpc/test_user_plugin.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ipatests/test_xmlrpc/test_user_plugin.py b/ipatests/test_xmlrpc/test_user_plugin.py index 7508578..b90363e 100644 --- a/ipatests/test_xmlrpc/test_user_plugin.py +++ b/ipatests/test_xmlrpc/test_user_plugin.py @@ -79,6 +79,13 @@ @pytest.fixture(scope='class') +def user_min(request): + """ User tracker fixture for testing user with uid no specified """ + tracker = UserTracker(givenname=u'Testmin', sn=u'Usermin') + return tracker.make_fixture(request) + + +@pytest.fixture(scope='class') def user(request): tracker = UserTracker(name=u'user1', givenname=u'Test', sn=u'User1') return tracker.make_fixture(request) @@ -405,6 +412,12 @@ def test_rename_to_invalid_login(self, user): @pytest.mark.tier1 class TestCreate(XMLRPC_test): + def test_create_user_with_min_values(self, user_min): + """ Create user with uid not specified """ + user_min.ensure_missing() + command = user_min.make_create_command() + command() + def test_create_with_krb_ticket_policy(self): """ Try to create user with krbmaxticketlife set """ testuser = UserTracker(
-- Manage your subscription for the Freeipa-devel mailing list: https://www.redhat.com/mailman/listinfo/freeipa-devel Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code