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 a7bad23f12b5c6227e1e5f1d976883dc2edf9146 Mon Sep 17 00:00:00 2001 From: Ganna Kaihorodova <gkaih...@redhat.com> Date: Thu, 8 Dec 2016 15:06:36 +0100 Subject: [PATCH 1/2] 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 | 40 +++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/ipatests/test_xmlrpc/tracker/user_plugin.py b/ipatests/test_xmlrpc/tracker/user_plugin.py index 4485fd9..ca28e7e 100644 --- a/ipatests/test_xmlrpc/tracker/user_plugin.py +++ b/ipatests/test_xmlrpc/tracker/user_plugin.py @@ -62,22 +62,40 @@ 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" % givenname) + if not (isinstance(sn, six.string_types) and sn): + raise ValueError("Invalid second name provided: %r" % 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 b0d51d7f9460064479c2dc49541c4ce6f0408371 Mon Sep 17 00:00:00 2001 From: Ganna Kaihorodova <gkaih...@redhat.com> Date: Thu, 8 Dec 2016 15:08:41 +0100 Subject: [PATCH 2/2] 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