summaryrefslogtreecommitdiffstats
path: root/tests/test_xmlrpc/test_user_plugin.py
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2009-12-09 09:09:53 -0700
committerJason Gerard DeRose <jderose@redhat.com>2009-12-10 08:29:15 -0700
commitb6e4972e7f6aa08e0392a2cf441b60ab0e7d88b7 (patch)
tree7e5329a51af169ce34a7d275a1bbd63c1e31c026 /tests/test_xmlrpc/test_user_plugin.py
parentd08b8858ddc3bf6265f6ea8acae6661b9fff5112 (diff)
downloadfreeipa-b6e4972e7f6aa08e0392a2cf441b60ab0e7d88b7.tar.gz
freeipa-b6e4972e7f6aa08e0392a2cf441b60ab0e7d88b7.tar.xz
freeipa-b6e4972e7f6aa08e0392a2cf441b60ab0e7d88b7.zip
Take 2: Extensible return values and validation; steps toward a single output_for_cli(); enable more webUI stuff
Diffstat (limited to 'tests/test_xmlrpc/test_user_plugin.py')
-rw-r--r--tests/test_xmlrpc/test_user_plugin.py386
1 files changed, 263 insertions, 123 deletions
diff --git a/tests/test_xmlrpc/test_user_plugin.py b/tests/test_xmlrpc/test_user_plugin.py
index efe48d843..3fc613aa9 100644
--- a/tests/test_xmlrpc/test_user_plugin.py
+++ b/tests/test_xmlrpc/test_user_plugin.py
@@ -1,8 +1,9 @@
# Authors:
# Rob Crittenden <rcritten@redhat.com>
# Pavel Zuna <pzuna@redhat.com>
+# Jason Gerard DeRose <jderose@redhat.com>
#
-# Copyright (C) 2008 Red Hat
+# Copyright (C) 2008, 2009 Red Hat
# see file 'COPYING' for use and warranty information
#
# This program is free software; you can redistribute it and/or
@@ -17,130 +18,269 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
"""
Test the `ipalib/plugins/user.py` module.
"""
-import sys
-from xmlrpc_test import XMLRPC_test, assert_attr_equal
-from ipalib import api
-from ipalib import errors
-
-
-class test_user(XMLRPC_test):
- """
- Test the `user` plugin.
- """
- uid = u'jexample'
- givenname = u'Jim'
- sn = u'Example'
- home = u'/home/%s' % uid
- principalname = u'%s@%s' % (uid, api.env.realm)
- kw = {'givenname': givenname, 'sn': sn, 'uid': uid, 'homedirectory': home}
-
- def test_1_user_add(self):
- """
- Test the `xmlrpc.user_add` method.
- """
- (dn, res) = api.Command['user_add'](**self.kw)
- assert res
- assert_attr_equal(res, 'givenname', self.givenname)
- assert_attr_equal(res, 'sn', self.sn)
- assert_attr_equal(res, 'uid', self.uid)
- assert_attr_equal(res, 'homedirectory', self.home)
- assert_attr_equal(res, 'objectclass', 'ipaobject')
-
- def test_2_user_add(self):
- """
- Test the `xmlrpc.user_add` method duplicate detection.
- """
- try:
- api.Command['user_add'](**self.kw)
- except errors.DuplicateEntry:
- pass
-
- def test_3_user_show(self):
- """
- Test the `xmlrpc.user_show` method.
- """
- kw = {'uid': self.uid, 'all': True}
- (dn, res) = api.Command['user_show'](**kw)
- assert res
- assert_attr_equal(res, 'givenname', self.givenname)
- assert_attr_equal(res, 'sn', self.sn)
- assert_attr_equal(res, 'uid', self.uid)
- assert_attr_equal(res, 'homedirectory', self.home)
- assert_attr_equal(res, 'krbprincipalname', self.principalname)
-
- def test_4_user_find(self):
- """
- Test the `xmlrpc.user_find` method with all attributes.
- """
- kw = {'all': True}
- (res, truncated) = api.Command['user_find'](self.uid, **kw)
- assert res
- assert_attr_equal(res[0][1], 'givenname', self.givenname)
- assert_attr_equal(res[0][1], 'sn', self.sn)
- assert_attr_equal(res[0][1], 'uid', self.uid)
- assert_attr_equal(res[0][1], 'homedirectory', self.home)
- assert_attr_equal(res[0][1], 'krbprincipalname', self.principalname)
-
- def test_5_user_find(self):
- """
- Test the `xmlrpc.user_find` method with minimal attributes.
- """
- (res, truncated) = api.Command['user_find'](self.uid)
- assert res
- assert_attr_equal(res[0][1], 'givenname', self.givenname)
- assert_attr_equal(res[0][1], 'sn', self.sn)
- assert_attr_equal(res[0][1], 'uid', self.uid)
- assert_attr_equal(res[0][1], 'homedirectory', self.home)
- assert 'krbprincipalname' not in res[0][1]
-
- def test_6_user_lock(self):
- """
- Test the `xmlrpc.user_lock` method.
- """
- res = api.Command['user_lock'](self.uid)
- assert res == True
-
- def test_7_user_unlock(self):
- """
- Test the `xmlrpc.user_unlock` method.
- """
- res = api.Command['user_unlock'](self.uid)
- assert res == True
-
- def test_8_user_mod(self):
- """
- Test the `xmlrpc.user_mod` method.
- """
- modkw = self.kw
- modkw['givenname'] = u'Finkle'
- (dn, res) = api.Command['user_mod'](**modkw)
- assert res
- assert_attr_equal(res, 'givenname', 'Finkle')
- assert_attr_equal(res, 'sn', self.sn)
-
- # Ok, double-check that it was changed
- (dn, res) = api.Command['user_show'](self.uid)
- assert res
- assert_attr_equal(res, 'givenname', 'Finkle')
- assert_attr_equal(res, 'sn', self.sn)
- assert_attr_equal(res, 'uid', self.uid)
-
- def test_9_user_del(self):
- """
- Test the `xmlrpc.user_del` method.
- """
- res = api.Command['user_del'](self.uid)
- assert res == True
-
- # Verify that it is gone
- try:
- api.Command['user_show'](self.uid)
- except errors.NotFound:
- pass
- else:
- assert False
+from ipalib import api, errors
+from xmlrpc_test import Declarative
+
+user_objectclass = (
+ u'top',
+ u'person',
+ u'organizationalperson',
+ u'inetorgperson',
+ u'inetuser',
+ u'posixaccount',
+ u'krbprincipalaux',
+ u'radiusprofile',
+ u'ipaobject',
+)
+
+user_memberof = (u'cn=ipausers,cn=groups,cn=accounts,dc=example,dc=com',)
+
+
+class test_user(Declarative):
+
+ cleanup_commands = [
+ ('user_del', [u'tuser1'], {}),
+ ]
+
+ tests = [
+
+ dict(
+ desc='Try to retrieve non-existant user',
+ command=(
+ 'user_show', [u'tuser1'], {}
+ ),
+ expected=errors.NotFound(reason='no such entry'),
+ ),
+
+
+ dict(
+ desc='Create a user',
+ command=(
+ 'user_add', [], dict(givenname=u'Test', sn=u'User1')
+ ),
+ expected=dict(
+ value=u'tuser1',
+ result=dict(
+ cn=(u'Test User1',),
+ gecos=(u'tuser1',),
+ givenname=(u'Test',),
+ homedirectory=(u'/home/tuser1',),
+ krbprincipalname=(u'tuser1@' + api.env.realm,),
+ loginshell=(u'/bin/sh',),
+ objectclass=user_objectclass,
+ sn=(u'User1',),
+ uid=(u'tuser1',),
+ ),
+ summary=u'Added user "tuser1"',
+ ),
+ ignore_values=(
+ 'ipauniqueid', 'gidnumber'
+ ),
+ ),
+
+
+ dict(
+ desc='Try to create another user with same login',
+ command=(
+ 'user_add', [], dict(givenname=u'Test', sn=u'User1')
+ ),
+ expected=errors.DuplicateEntry(),
+ ),
+
+
+ dict(
+ desc='Retrieve the user',
+ command=(
+ 'user_show', [u'tuser1'], {}
+ ),
+ expected=dict(
+ result=dict(
+ dn=u'uid=tuser1,cn=users,cn=accounts,dc=example,dc=com',
+ givenname=(u'Test',),
+ homedirectory=(u'/home/tuser1',),
+ loginshell=(u'/bin/sh',),
+ sn=(u'User1',),
+ uid=(u'tuser1',),
+ ),
+ value=u'tuser1',
+ summary=None,
+ ),
+ ),
+
+
+ dict(
+ desc='Search for this user with all=True',
+ command=(
+ 'user_find', [u'tuser1'], {'all': True}
+ ),
+ expected=dict(
+ result=(
+ {
+ 'cn': (u'Test User1',),
+ 'gecos': (u'tuser1',),
+ 'givenname': (u'Test',),
+ 'homedirectory': (u'/home/tuser1',),
+ 'krbprincipalname': (u'tuser1@' + api.env.realm,),
+ 'loginshell': (u'/bin/sh',),
+ 'memberof group': (u'ipausers',),
+ 'objectclass': user_objectclass,
+ 'sn': (u'User1',),
+ 'uid': (u'tuser1',),
+ },
+ ),
+ summary=u'1 user matched',
+ count=1,
+ truncated=False,
+ ),
+ ignore_values=['uidnumber', 'gidnumber', 'ipauniqueid'],
+ ),
+
+
+ dict(
+ desc='Search for this user with minimal attributes',
+ command=(
+ 'user_find', [u'tuser1'], {}
+ ),
+ expected=dict(
+ result=(
+ dict(
+ givenname=(u'Test',),
+ homedirectory=(u'/home/tuser1',),
+ loginshell=(u'/bin/sh',),
+ sn=(u'User1',),
+ uid=(u'tuser1',),
+ ),
+ ),
+ summary=u'1 user matched',
+ count=1,
+ truncated=False,
+ ),
+ ),
+
+
+ dict(
+ desc='Search for all users',
+ command=(
+ 'user_find', [], {}
+ ),
+ expected=dict(
+ result=(
+ dict(
+ homedirectory=(u'/home/admin',),
+ loginshell=(u'/bin/bash',),
+ sn=(u'Administrator',),
+ uid=(u'admin',),
+ ),
+ dict(
+ givenname=(u'Test',),
+ homedirectory=(u'/home/tuser1',),
+ loginshell=(u'/bin/sh',),
+ sn=(u'User1',),
+ uid=(u'tuser1',),
+ ),
+ ),
+ summary=u'2 users matched',
+ count=2,
+ truncated=False,
+ ),
+ ),
+
+
+ dict(
+ desc='Lock user',
+ command=(
+ 'user_lock', [u'tuser1'], {}
+ ),
+ expected=dict(
+ result=True,
+ value=u'tuser1',
+ summary=u'Locked user "tuser1"',
+ ),
+ ),
+
+
+ dict(
+ desc='Unlock user',
+ command=(
+ 'user_unlock', [u'tuser1'], {}
+ ),
+ expected=dict(
+ result=True,
+ value=u'tuser1',
+ summary=u'Unlocked user "tuser1"',
+ ),
+ ),
+
+
+ dict(
+ desc='Update user',
+ command=(
+ 'user_mod', [u'tuser1'], dict(givenname=u'Finkle')
+ ),
+ expected=dict(
+ result=dict(
+ givenname=(u'Finkle',),
+ ),
+ summary=u'Modified user "tuser1"',
+ value=u'tuser1',
+ ),
+ ),
+
+
+ dict(
+ desc='Retrieve user to verify update',
+ command=(
+ 'user_show', [u'tuser1'], {}
+ ),
+ expected=dict(
+ result=dict(
+ dn=u'uid=tuser1,cn=users,cn=accounts,dc=example,dc=com',
+ givenname=(u'Finkle',),
+ homedirectory=(u'/home/tuser1',),
+ loginshell=(u'/bin/sh',),
+ sn=(u'User1',),
+ uid=(u'tuser1',),
+ ),
+ summary=None,
+ value=u'tuser1',
+ ),
+
+ ),
+
+
+ dict(
+ desc='Delete user',
+ command=(
+ 'user_del', [u'tuser1'], {}
+ ),
+ expected=dict(
+ result=True,
+ summary=u'Deleted user "tuser1"',
+ value=u'tuser1',
+ ),
+ ),
+
+
+ dict(
+ desc='Do double delete',
+ command=(
+ 'user_del', [u'tuser1'], {}
+ ),
+ expected=errors.NotFound(reason='no such entry'),
+ ),
+
+
+ dict(
+ desc='Verify user is gone',
+ command=(
+ 'user_show', [u'tuser1'], {}
+ ),
+ expected=errors.NotFound(reason='no such entry'),
+ ),
+ ]