From 72e48161401afd5954101a747b26c1ca3fcf040e Mon Sep 17 00:00:00 2001 From: Pavel Zuna Date: Wed, 24 Jun 2009 15:12:27 +0200 Subject: Add unit tests for new plugins. --- tests/test_xmlrpc/test_automount_plugin.py | 295 +++++++++++++++++++++++++++ tests/test_xmlrpc/test_group_plugin.py | 187 +++++++++++++++++ tests/test_xmlrpc/test_host_plugin.py | 122 +++++++++++ tests/test_xmlrpc/test_hostgroup_plugin.py | 143 +++++++++++++ tests/test_xmlrpc/test_netgroup_plugin.py | 312 +++++++++++++++++++++++++++++ tests/test_xmlrpc/test_rolegroup_plugin.py | 143 +++++++++++++ tests/test_xmlrpc/test_service_plugin.py | 113 +++++++++++ tests/test_xmlrpc/test_taskgroup_plugin.py | 174 ++++++++++++++++ tests/test_xmlrpc/test_user_plugin.py | 145 ++++++++++++++ 9 files changed, 1634 insertions(+) create mode 100644 tests/test_xmlrpc/test_automount_plugin.py create mode 100644 tests/test_xmlrpc/test_group_plugin.py create mode 100644 tests/test_xmlrpc/test_host_plugin.py create mode 100644 tests/test_xmlrpc/test_hostgroup_plugin.py create mode 100644 tests/test_xmlrpc/test_netgroup_plugin.py create mode 100644 tests/test_xmlrpc/test_rolegroup_plugin.py create mode 100644 tests/test_xmlrpc/test_service_plugin.py create mode 100644 tests/test_xmlrpc/test_taskgroup_plugin.py create mode 100644 tests/test_xmlrpc/test_user_plugin.py diff --git a/tests/test_xmlrpc/test_automount_plugin.py b/tests/test_xmlrpc/test_automount_plugin.py new file mode 100644 index 000000000..d9c0c2edf --- /dev/null +++ b/tests/test_xmlrpc/test_automount_plugin.py @@ -0,0 +1,295 @@ +# Authors: +# Rob Crittenden +# Pavel Zuna +# +# Copyright (C) 2008 Red Hat +# see file 'COPYING' for use and warranty information +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; version 2 only +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# 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/automount.py' module. +""" + +import sys +from xmlrpc_test import XMLRPC_test, assert_attr_equal +from ipalib import api +from ipalib import errors + + +class test_automount(XMLRPC_test): + """ + Test the `automount` plugin. + """ + mapname = u'testmap' + keyname = u'testkey' + keyname2 = u'testkey2' + description = u'description of map' + info = u'ro' + map_kw = {'automountmapname': mapname, 'description': description} + key_kw = {'automountmapname': mapname, 'automountkey': keyname, 'automountinformation': info} + key_kw2 = {'automountmapname': mapname, 'automountkey': keyname2, 'automountinformation': info} + + def test_1_automountmap_add(self): + """ + Test adding a map `xmlrpc.automountmap_add` method. + """ + (dn, res) = api.Command['automountmap_add'](**self.map_kw) + assert res + assert_attr_equal(res, 'automountmapname', self.mapname) + + def test_2_automountkey_add(self): + """ + Test adding a key using `xmlrpc.automountkey_add` method. + """ + (dn, res) = api.Command['automountkey_add'](**self.key_kw2) + assert res + assert_attr_equal(res, 'automountkey', self.keyname2) + + def test_3_automountkey_add(self): + """ + Test adding a key using `xmlrpc.automountkey_add` method. + """ + (dn, res) = api.Command['automountkey_add'](**self.key_kw) + assert res + assert_attr_equal(res, 'automountkey', self.keyname) + + def test_4_automountkey_add(self): + """ + Test adding a duplicate key using `xmlrpc.automountkey_add` method. + """ + try: + api.Command['automountkey_add'](**self.key_kw) + except errors.DuplicateEntry: + pass + else: + assert False + + def test_5_automountmap_show(self): + """ + Test the `xmlrpc.automountmap_show` method. + """ + (dn, res) = api.Command['automountmap_show'](self.mapname) + assert res + assert_attr_equal(res, 'automountmapname', self.mapname) + + def test_6_automountmap_find(self): + """ + Test the `xmlrpc.automountmap_find` method. + """ + (res, truncated) = api.Command['automountmap_find'](self.mapname) + assert res + assert_attr_equal(res[0][1], 'automountmapname', self.mapname) + + def test_7_automountkey_show(self): + """ + Test the `xmlrpc.automountkey_show` method. + """ + showkey_kw={'automountmapname': self.mapname, 'automountkey': self.keyname} + (dn, res) = api.Command['automountkey_show'](**showkey_kw) + assert res + assert_attr_equal(res, 'automountkey', self.keyname) + assert_attr_equal(res, 'automountinformation', self.info) + + def test_8_automountkey_find(self): + """ + Test the `xmlrpc.automountkey_find` method. + """ + (res, truncated) = api.Command['automountkey_find'](self.mapname) + assert res + assert len(res) == 2 + assert_attr_equal(res[1][1], 'automountkey', self.keyname) + assert_attr_equal(res[1][1], 'automountinformation', self.info) + + def test_9_automountkey_mod(self): + """ + Test the `xmlrpc.automountkey_mod` method. + """ + self.key_kw['automountinformation'] = u'rw' + self.key_kw['description'] = u'new description' + (dn, res) = api.Command['automountkey_mod'](**self.key_kw) + assert res + assert_attr_equal(res, 'automountinformation', 'rw') + assert_attr_equal(res, 'description', 'new description') + + def test_a_automountmap_mod(self): + """ + Test the `xmlrpc.automountmap_mod` method. + """ + self.map_kw['description'] = u'new description' + (dn, res) = api.Command['automountmap_mod'](**self.map_kw) + assert res + assert_attr_equal(res, 'description', 'new description') + + def test_b_automountkey_del(self): + """ + Test the `xmlrpc.automountkey_del` method. + """ + delkey_kw={'automountmapname': self.mapname, 'automountkey': self.keyname} + res = api.Command['automountkey_del'](**delkey_kw) + assert res == True + + # Verify that it is gone + try: + api.Command['automountkey_show'](**delkey_kw) + except errors.NotFound: + pass + else: + assert False + + def test_c_automountmap_del(self): + """ + Test the `xmlrpc.automountmap_del` method. + """ + res = api.Command['automountmap_del'](self.mapname) + assert res == True + + # Verify that it is gone + try: + api.Command['automountmap_show'](self.mapname) + except errors.NotFound: + pass + else: + assert False + + def test_d_automountmap_del(self): + """ + Test that the `xmlrpc.automountmap_del` method removes all keys + """ + # Verify that the second key we added is gone + key_kw = {'automountmapname': self.mapname, 'automountkey': self.keyname2} + try: + api.Command['automountkey_show'](**key_kw) + except errors.NotFound: + pass + else: + assert False + + +class test_automount_indirect(XMLRPC_test): + """ + Test the `automount` plugin indirect map functionality. + """ + mapname = u'auto.home' + keyname = u'/home' + parentmap = u'auto.master' + description = u'Home directories' + map_kw = {'key': keyname, 'parentmap': parentmap, 'description': description} + + def test_1_automountmap_add_indirect(self): + """ + Test adding an indirect map. + """ + (dn, res) = api.Command['automountmap_add_indirect'](self.mapname, **self.map_kw) + assert res + assert_attr_equal(res, 'automountinformation', self.mapname) + + def test_2_automountmap_show(self): + """ + Test the `xmlrpc.automountmap_show` method. + """ + showkey_kw = {'automountmapname': self.parentmap, 'automountkey': self.keyname} + (dn, res) = api.Command['automountkey_show'](**showkey_kw) + assert res + assert_attr_equal(res, 'automountkey', self.keyname) + + def test_3_automountkey_del(self): + """ + Remove the indirect key /home. + """ + delkey_kw = {'automountmapname': self.parentmap, 'automountkey': self.keyname} + res = api.Command['automountkey_del'](**delkey_kw) + assert res == True + + # Verify that it is gone + try: + api.Command['automountkey_show'](**delkey_kw) + except errors.NotFound: + pass + else: + assert False + + def test_4_automountmap_del(self): + """ + Remove the indirect map for auto.home. + """ + res = api.Command['automountmap_del'](self.mapname) + assert res == True + + # Verify that it is gone + try: + api.Command['automountmap_show'](self.mapname) + except errors.NotFound: + pass + else: + assert False + + +class test_automount_indirect_no_parent(XMLRPC_test): + """ + Test the `automount` plugin Indirect map function. + """ + mapname = u'auto.home' + keyname = u'/home' + parentmap = u'auto.master' + description = u'Home directories' + map_kw = {'key': keyname, 'description': description} + + def test_1_automountmap_add_indirect(self): + """ + Test adding an indirect map with default parent. + """ + (dn, res) = api.Command['automountmap_add_indirect'](self.mapname, **self.map_kw) + assert res + assert_attr_equal(res, 'automountinformation', self.mapname) + + def test_2_automountkey_show(self): + """ + Test the `xmlrpc.automountkey_show` method with default parent. + """ + showkey_kw = {'automountmapname': self.parentmap, 'automountkey': self.keyname} + (dn, res) = api.Command['automountkey_show'](**showkey_kw) + assert res + assert_attr_equal(res, 'automountkey', self.keyname) + + def test_3_automountkey_del(self): + """ + Remove the indirect key /home. + """ + delkey_kw={'automountmapname': self.parentmap, 'automountkey': self.keyname} + res = api.Command['automountkey_del'](**delkey_kw) + assert res == True + + # Verify that it is gone + try: + api.Command['automountkey_show'](**delkey_kw) + except errors.NotFound: + pass + else: + assert False + + def test_4_automountmap_del(self): + """ + Remove the indirect map for auto.home. + """ + res = api.Command['automountmap_del'](self.mapname) + assert res == True + + # Verify that it is gone + try: + api.Command['automountmap_show'](self.mapname) + except errors.NotFound: + pass + else: + assert False + diff --git a/tests/test_xmlrpc/test_group_plugin.py b/tests/test_xmlrpc/test_group_plugin.py new file mode 100644 index 000000000..d509c1045 --- /dev/null +++ b/tests/test_xmlrpc/test_group_plugin.py @@ -0,0 +1,187 @@ +# Authors: +# Rob Crittenden +# Pavel Zuna +# +# Copyright (C) 2008 Red Hat +# see file 'COPYING' for use and warranty information +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; version 2 only +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# 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/group.py` module. +""" + +import sys +from xmlrpc_test import XMLRPC_test, assert_attr_equal +from ipalib import api +from ipalib import errors + + +class test_group(XMLRPC_test): + """ + Test the `group` plugin. + """ + cn = u'testgroup' + cn2 = u'testgroup2' + cnposix = u'posixgroup' + description = u'This is a test' + kw = {'description': description, 'cn': cn} + + def test_1_group_add(self): + """ + Test the `xmlrpc.group_add` method: testgroup. + """ + (dn, res) = api.Command['group_add'](**self.kw) + assert res + assert_attr_equal(res, 'description', self.description) + assert_attr_equal(res, 'cn', self.cn) + + def test_2_group_add(self): + """ + Test the `xmlrpc.group_add` method duplicate detection. + """ + try: + api.Command['group_add'](**self.kw) + except errors.DuplicateEntry: + pass + + def test_3_group_add(self): + """ + Test the `xmlrpc.group_add` method: testgroup2. + """ + self.kw['cn'] = self.cn2 + (dn, res) = api.Command['group_add'](**self.kw) + assert res + assert_attr_equal(res, 'description', self.description) + assert_attr_equal(res, 'cn', self.cn2) + + def test_3_group_add_member(self): + """ + Test the `xmlrpc.group_add_member` method. + """ + kw = {} + kw['groups'] = self.cn2 + (total, res) = api.Command['group_add_member'](self.cn, **kw) + assert total == 1 + + def test_4_group_add_member(self): + """ + Test the `xmlrpc.group_add_member` with a non-existent member + """ + kw = {} + kw['groups'] = u'notfound' + (total, res) = api.Command['group_add_member'](self.cn, **kw) + assert total == 0 + + def test_5_group_show(self): + """ + Test the `xmlrpc.group_show` method. + """ + (dn, res) = api.Command['group_show'](self.cn) + assert res + assert_attr_equal(res, 'description', self.description) + assert_attr_equal(res, 'cn', self.cn) + + def test_6_group_find(self): + """ + Test the `xmlrpc.group_find` method. + """ + (res, truncated) = api.Command['group_find'](cn=self.cn) + assert res + assert_attr_equal(res[0][1], 'description', self.description) + assert_attr_equal(res[0][1], 'cn', self.cn) + + def test_7_group_mod(self): + """ + Test the `xmlrpc.group_mod` method. + """ + modkw = self.kw + modkw['cn'] = self.cn + modkw['description'] = u'New description' + (dn, res) = api.Command['group_mod'](**modkw) + assert res + assert_attr_equal(res, 'description', 'New description') + # Ok, double-check that it was changed + (dn, res) = api.Command['group_show'](self.cn) + assert res + assert_attr_equal(res, 'description', 'New description') + assert_attr_equal(res, 'cn', self.cn) + + def test_8_group_mod(self): + """ + Test the `xmlrpc.group_mod` method, promote a posix group + """ + modkw = self.kw + modkw['cn'] = self.cn + modkw['posix'] = True + (dn, res) = api.Command['group_mod'](**modkw) + assert res + assert_attr_equal(res, 'description', 'New description') + assert_attr_equal(res, 'cn', self.cn) + # Ok, double-check that it was changed + (dn, res) = api.Command['group_show'](self.cn, all=True) + assert res + assert_attr_equal(res, 'description', 'New description') + assert_attr_equal(res, 'cn', self.cn) + assert res.get('gidnumber', '') + + def test_9_group_del_member(self): + """ + Test the `xmlrpc.group_del_member` method. + """ + kw = {} + kw['groups'] = self.cn2 + (total, res) = api.Command['group_del_member'](self.cn, **kw) + assert res + assert total == 1 + + def test_a_group_del_member(self): + """ + Test the `xmlrpc.group_del_member` method with non-member + """ + kw = {} + kw['groups'] = u'notfound' + # an error isn't thrown, the list of failed members is returned + (total, res) = api.Command['group_del_member'](self.cn, **kw) + assert total == 0 + + def test_b_group_del(self): + """ + Test the `xmlrpc.group_del` method: testgroup. + """ + res = api.Command['group_del'](self.cn) + assert res == True + + # Verify that it is gone + try: + api.Command['group_show'](self.cn) + except errors.NotFound: + pass + else: + assert False + + def test_c_group_del(self): + """ + Test the `xmlrpc.group_del` method: testgroup2. + """ + res = api.Command['group_del'](self.cn2) + assert res == True + + # Verify that it is gone + try: + api.Command['group_show'](self.cn2) + except errors.NotFound: + pass + else: + assert False + diff --git a/tests/test_xmlrpc/test_host_plugin.py b/tests/test_xmlrpc/test_host_plugin.py new file mode 100644 index 000000000..e64ba7aec --- /dev/null +++ b/tests/test_xmlrpc/test_host_plugin.py @@ -0,0 +1,122 @@ +# Authors: +# Rob Crittenden +# Pavel Zuna +# +# Copyright (C) 2008 Red Hat +# see file 'COPYING' for use and warranty information +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; version 2 only +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# 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/host.py` module. +""" + +import sys +from xmlrpc_test import XMLRPC_test, assert_attr_equal +from ipalib import api +from ipalib import errors + + +class test_host(XMLRPC_test): + """ + Test the `host` plugin. + """ + fqdn = u'ipatesthost.%s' % api.env.domain + description = u'Test host' + localityname = u'Undisclosed location' + kw = {'fqdn': fqdn, 'description': description, 'localityname': localityname} + + def test_1_host_add(self): + """ + Test the `xmlrpc.host_add` method. + """ + (dn, res) = api.Command['host_add'](**self.kw) + assert type(res) is dict + assert_attr_equal(res, 'description', self.description) + assert_attr_equal(res, 'fqdn', self.fqdn) + assert_attr_equal(res, 'localityname', self.localityname) + + def test_2_host_show(self): + """ + Test the `xmlrpc.host_show` method with all attributes. + """ + kw = {'fqdn': self.fqdn, 'all': True} + (dn, res) = api.Command['host_show'](**kw) + assert res + assert_attr_equal(res, 'description', self.description) + assert_attr_equal(res, 'fqdn', self.fqdn) + assert_attr_equal(res, 'l', self.localityname) + + def test_3_host_show(self): + """ + Test the `xmlrpc.host_show` method with default attributes. + """ + kw = {'fqdn': self.fqdn} + (dn, res) = api.Command['host_show'](**kw) + assert res + assert_attr_equal(res, 'description', self.description) + assert_attr_equal(res, 'fqdn', self.fqdn) + assert_attr_equal(res, 'localityname', self.localityname) + + def test_4_host_find(self): + """ + Test the `xmlrpc.host_find` method with all attributes. + """ + kw = {'fqdn': self.fqdn, 'all': True} + (res, truncated) = api.Command['host_find'](**kw) + assert res + assert_attr_equal(res[0][1], 'description', self.description) + assert_attr_equal(res[0][1], 'fqdn', self.fqdn) + assert_attr_equal(res[0][1], 'l', self.localityname) + + def test_5_host_find(self): + """ + Test the `xmlrpc.host_find` method with default attributes. + """ + (res, truncated) = api.Command['host_find'](self.fqdn) + assert res + assert_attr_equal(res[0][1], 'description', self.description) + assert_attr_equal(res[0][1], 'fqdn', self.fqdn) + assert_attr_equal(res[0][1], 'localityname', self.localityname) + + def test_6_host_mod(self): + """ + Test the `xmlrpc.host_mod` method. + """ + newdesc = u'Updated host' + modkw = {'fqdn': self.fqdn, 'description': newdesc} + (dn, res) = api.Command['host_mod'](**modkw) + assert res + assert_attr_equal(res, 'description', newdesc) + + # Ok, double-check that it was changed + (dn, res) = api.Command['host_show'](self.fqdn) + assert res + assert_attr_equal(res, 'description', newdesc) + assert_attr_equal(res, 'fqdn', self.fqdn) + + def test_7_host_del(self): + """ + Test the `xmlrpc.host_del` method. + """ + res = api.Command['host_del'](self.fqdn) + assert res == True + + # Verify that it is gone + try: + api.Command['host_show'](self.fqdn) + except errors.NotFound: + pass + else: + assert False + diff --git a/tests/test_xmlrpc/test_hostgroup_plugin.py b/tests/test_xmlrpc/test_hostgroup_plugin.py new file mode 100644 index 000000000..bea3b3d6d --- /dev/null +++ b/tests/test_xmlrpc/test_hostgroup_plugin.py @@ -0,0 +1,143 @@ +# Authors: +# Rob Crittenden +# Pavel Zuna +# +# Copyright (C) 2008 Red Hat +# see file 'COPYING' for use and warranty information +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; version 2 only +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# 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/hostgroup.py` module. +""" + +import sys +from xmlrpc_test import XMLRPC_test, assert_attr_equal +from ipalib import api +from ipalib import errors + + +class test_hostgroup(XMLRPC_test): + """ + Test the `hostgroup` plugin. + """ + cn = u'testgroup' + description = u'Test host group' + kw = {'cn': cn, 'description': description} + + host_fqdn = u'ipatesthost.%s' % api.env.domain + host_description = u'Test host' + host_localityname = u'Undisclosed location' + + def test_1_hostgroup_add(self): + """ + Test the `xmlrpc.hostgroup_add` method. + """ + (dn, res) = api.Command['hostgroup_add'](**self.kw) + assert res + assert_attr_equal(res, 'description', self.description) + assert_attr_equal(res, 'cn', self.cn) + + def test_2_host_add(self): + """ + Add a host to test add/remove member. + """ + kw = {'fqdn': self.host_fqdn, 'description': self.host_description, 'localityname': self.host_localityname} + (dn, res) = api.Command['host_add'](**kw) + assert res + assert_attr_equal(res, 'description', self.host_description) + assert_attr_equal(res, 'fqdn', self.host_fqdn) + + def test_3_hostgroup_add_member(self): + """ + Test the `xmlrpc.hostgroup_add_member` method. + """ + kw = {} + kw['hosts'] = self.host_fqdn + (total, res) = api.Command['hostgroup_add_member'](self.cn, **kw) + assert res[1].get('member', []) != [] + + def test_4_hostgroup_show(self): + """ + Test the `xmlrpc.hostgroup_show` method. + """ + (dn, res) = api.Command['hostgroup_show'](self.cn) + assert res + assert_attr_equal(res, 'description', self.description) + assert_attr_equal(res, 'cn', self.cn) + + def test_5_hostgroup_find(self): + """ + Test the `xmlrpc.hostgroup_find` method. + """ + (res, truncated) = api.Command['hostgroup_find'](cn=self.cn) + assert res + assert_attr_equal(res[0][1], 'description', self.description) + assert_attr_equal(res[0][1], 'cn', self.cn) + + def test_6_hostgroup_mod(self): + """ + Test the `xmlrpc.hostgroup_mod` method. + """ + newdesc = u'Updated host group' + modkw = {'cn': self.cn, 'description': newdesc} + (dn, res) = api.Command['hostgroup_mod'](**modkw) + assert res + assert_attr_equal(res, 'description', newdesc) + + # Ok, double-check that it was changed + (dn, res) = api.Command['hostgroup_show'](self.cn) + assert res + assert_attr_equal(res, 'description', newdesc) + assert_attr_equal(res, 'cn', self.cn) + + def test_7_hostgroup_del_member(self): + """ + Test the `xmlrpc.hostgroup_del_member` method. + """ + kw = {} + kw['hosts'] = self.host_fqdn + (total, res) = api.Command['hostgroup_del_member'](self.cn, **kw) + assert res + assert res[1].get('member', []) == [] + + def test_8_hostgroup_del(self): + """ + Test the `xmlrpc.hostgroup_del` method. + """ + res = api.Command['hostgroup_del'](self.cn) + assert res == True + + # Verify that it is gone + try: + api.Command['hostgroup_show'](self.cn) + except errors.NotFound: + pass + else: + assert False + + def test_9_host_del(self): + """ + Test the `xmlrpc.host_del` method. + """ + res = api.Command['host_del'](self.host_fqdn) + assert res == True + + # Verify that it is gone + try: + api.Command['host_show'](self.host_fqdn) + except errors.NotFound: + pass + else: + assert False + diff --git a/tests/test_xmlrpc/test_netgroup_plugin.py b/tests/test_xmlrpc/test_netgroup_plugin.py new file mode 100644 index 000000000..ff057306d --- /dev/null +++ b/tests/test_xmlrpc/test_netgroup_plugin.py @@ -0,0 +1,312 @@ +# Authors: +# Rob Crittenden +# Pavel Zuna +# +# Copyright (C) 2009 Red Hat +# see file 'COPYING' for use and warranty information +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; version 2 only +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# 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/netgroup.py` module. +""" + +import sys +from xmlrpc_test import XMLRPC_test, assert_attr_equal, assert_is_member +from ipalib import api +from ipalib import errors + + +class test_netgroup(XMLRPC_test): + """ + Test the `netgroup` plugin. + """ + ng_cn = u'ng1' + ng_description = u'Netgroup' + ng_kw = {'cn': ng_cn, 'description': ng_description, 'nisdomainname': u'example.com'} + + host_fqdn = u'ipatesthost.%s' % api.env.domain + host_description = u'Test host' + host_localityname = u'Undisclosed location' + host_kw = {'fqdn': host_fqdn, 'description': host_description, 'localityname': host_localityname} + + hg_cn = u'ng1' + hg_description = u'Netgroup' + hg_kw = {'cn': hg_cn, 'description': hg_description} + + user_uid = u'jexample' + user_givenname = u'Jim' + user_sn = u'Example' + user_home = u'/home/%s' % user_uid + user_kw = {'givenname': user_givenname,'sn': user_sn,'uid': user_uid,'homedirectory': user_home} + + group_cn = u'testgroup' + group_description = u'This is a test' + group_kw = {'description': group_description,'cn': group_cn} + + def test_1_netgroup_add(self): + """ + Test the `xmlrpc.netgroup_add` method. + """ + (dn, res) = api.Command['netgroup_add'](**self.ng_kw) + assert res + assert_attr_equal(res, 'description', self.ng_description) + assert_attr_equal(res, 'cn', self.ng_cn) + + def test_2_add_data(self): + """ + Add the data needed to do additional testing. + """ + # Add a host + (dn, res) = api.Command['host_add'](**self.host_kw) + assert res + assert_attr_equal(res, 'description', self.host_description) + assert_attr_equal(res, 'fqdn', self.host_fqdn) + + # Add a hostgroup + (dn, res) = api.Command['hostgroup_add'](**self.hg_kw) + assert res + assert_attr_equal(res, 'description', self.hg_description) + assert_attr_equal(res, 'cn', self.hg_cn) + + # Add a user + (dn, res) = api.Command['user_add'](**self.user_kw) + assert res + assert_attr_equal(res, 'givenname', self.user_givenname) + assert_attr_equal(res, 'uid', self.user_uid) + + # Add a group + (dn, res) = api.Command['group_add'](**self.group_kw) + assert res + assert_attr_equal(res, 'description', self.group_description) + assert_attr_equal(res, 'cn', self.group_cn) + + def test_3_netgroup_add_member(self): + """ + Test the `xmlrpc.netgroup_add_member` method. + """ + kw = {} + kw['hosts'] = self.host_fqdn + (total, res) = api.Command['netgroup_add_member'](self.ng_cn, **kw) + assert total == 1 + assert_is_member(res[1], 'fqdn=%s' % self.host_fqdn) + + kw = {} + kw['hostgroups'] = self.hg_cn + (total, res) = api.Command['netgroup_add_member'](self.ng_cn, **kw) + assert total == 1 + assert_is_member(res[1], 'cn=%s' % self.hg_cn) + + kw = {} + kw['users'] = self.user_uid + (total, res) = api.Command['netgroup_add_member'](self.ng_cn, **kw) + assert total == 1 + assert_is_member(res[1], 'uid=%s' % self.user_uid) + + kw = {} + kw['groups'] = self.group_cn + (total, res) = api.Command['netgroup_add_member'](self.ng_cn, **kw) + assert total == 1 + assert_is_member(res[1], 'cn=%s' % self.group_cn) + + def test_4_netgroup_add_member(self): + """ + Test the `xmlrpc.netgroup_add_member` method again to test dupes. + """ + kw = {} + kw['hosts'] = self.host_fqdn + (total, res) = api.Command['netgroup_add_member'](self.ng_cn, **kw) + assert total == 0 + + kw = {} + kw['hostgroups'] = self.hg_cn + (total, res) = api.Command['netgroup_add_member'](self.ng_cn, **kw) + assert total == 0 + + kw = {} + kw['users'] = self.user_uid + res = api.Command['netgroup_add_member'](self.ng_cn, **kw) + assert total == 0 + + kw = {} + kw['groups'] = self.group_cn + res = api.Command['netgroup_add_member'](self.ng_cn, **kw) + assert total == 0 + + def test_5_netgroup_add_member(self): + """ + Test adding external hosts. + """ + kw = {} + kw['hosts'] = u'nosuchhost' + (total, res) = api.Command['netgroup_add_member'](self.ng_cn, **kw) + assert total == 1 + + (dn, res) = api.Command['netgroup_show'](self.ng_cn) + assert res + assert_is_member(res, 'nosuchhost', 'externalhost') + + def test_6_netgroup_show(self): + """ + Test the `xmlrpc.netgroup_show` method. + """ + (dn, res) = api.Command['netgroup_show'](self.ng_cn) + assert res + assert_attr_equal(res, 'description', self.ng_description) + assert_attr_equal(res, 'cn', self.ng_cn) + assert_is_member(res, 'fqdn=%s' % self.host_fqdn) + assert_is_member(res, 'cn=%s' % self.hg_cn) + assert_is_member(res, 'uid=%s' % self.user_uid) + assert_is_member(res, 'cn=%s' % self.group_cn) + + def test_7_netgroup_find(self): + """ + Test the `xmlrpc.hostgroup_find` method. + """ + (res, truncated) = api.Command.netgroup_find(self.ng_cn) + assert res + assert_attr_equal(res[0][1], 'description', self.ng_description) + assert_attr_equal(res[0][1], 'cn', self.ng_cn) + + def test_8_netgroup_mod(self): + """ + Test the `xmlrpc.hostgroup_mod` method. + """ + newdesc = u'Updated host group' + modkw = {'cn': self.ng_cn, 'description': newdesc} + (dn, res) = api.Command['netgroup_mod'](**modkw) + assert res + assert_attr_equal(res, 'description', newdesc) + + # Ok, double-check that it was changed + (dn, res) = api.Command['netgroup_show'](self.ng_cn) + assert res + assert_attr_equal(res, 'description', newdesc) + assert_attr_equal(res, 'cn', self.ng_cn) + + def test_9_netgroup_del_member(self): + """ + Test the `xmlrpc.hostgroup_del_member` method. + """ + kw = {} + kw['hosts'] = self.host_fqdn + (total, res) = api.Command['netgroup_del_member'](self.ng_cn, **kw) + assert total == 1 + + kw = {} + kw['hostgroups'] = self.hg_cn + (total, res) = api.Command['netgroup_del_member'](self.ng_cn, **kw) + assert total == 1 + + kw = {} + kw['users'] = self.user_uid + (total, res) = api.Command['netgroup_del_member'](self.ng_cn, **kw) + assert total == 1 + + kw = {} + kw['groups'] = self.group_cn + (total, res) = api.Command['netgroup_del_member'](self.ng_cn, **kw) + assert total == 1 + + def test_a_netgroup_del_member(self): + """ + Test the `xmlrpc.netgroup_del_member` method again to test not found. + """ + kw = {} + kw['hosts'] = self.host_fqdn + (total, res) = api.Command['netgroup_del_member'](self.ng_cn, **kw) + assert total == 0 + + kw = {} + kw['hostgroups'] = self.hg_cn + (total, res) = api.Command['netgroup_del_member'](self.ng_cn, **kw) + assert total == 0 + + kw = {} + kw['users'] = self.user_uid + (dn, res) = api.Command['netgroup_show'](self.ng_cn, all=True) + (total, res) = api.Command['netgroup_del_member'](self.ng_cn, **kw) + assert total == 0 + + kw = {} + kw['groups'] = self.group_cn + (total, res) = api.Command['netgroup_del_member'](self.ng_cn, **kw) + assert total == 0 + + def test_b_netgroup_del(self): + """ + Test the `xmlrpc.netgroup_del` method. + """ + res = api.Command['netgroup_del'](self.ng_cn) + assert res == True + + # Verify that it is gone + try: + api.Command['netgroup_show'](self.ng_cn) + except errors.NotFound: + pass + else: + assert False + + def test_c_del_data(self): + """ + Remove the test data we added. + """ + # Remove the host + res = api.Command['host_del'](self.host_fqdn) + assert res == True + + # Verify that it is gone + try: + api.Command['host_show'](self.host_fqdn) + except errors.NotFound: + pass + else: + assert False + + # Remove the hostgroup + res = api.Command['hostgroup_del'](self.hg_cn) + assert res == True + + # Verify that it is gone + try: + api.Command['hostgroup_show'](self.hg_cn) + except errors.NotFound: + pass + else: + assert False + + # Remove the user + res = api.Command['user_del'](self.user_uid) + assert res == True + + # Verify that it is gone + try: + api.Command['user_show'](self.user_uid) + except errors.NotFound: + pass + else: + assert False + + # Remove the group + res = api.Command['group_del'](self.group_cn) + assert res == True + + # Verify that it is gone + try: + api.Command['group_show'](self.group_cn) + except errors.NotFound: + pass + else: + assert False + diff --git a/tests/test_xmlrpc/test_rolegroup_plugin.py b/tests/test_xmlrpc/test_rolegroup_plugin.py new file mode 100644 index 000000000..8ca796e6a --- /dev/null +++ b/tests/test_xmlrpc/test_rolegroup_plugin.py @@ -0,0 +1,143 @@ +# Authors: +# Rob Crittenden +# Pavel Zuna +# +# Copyright (C) 2009 Red Hat +# see file 'COPYING' for use and warranty information +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; version 2 only +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# 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/rolegroup.py` module. +""" + +import sys +from xmlrpc_test import XMLRPC_test, assert_attr_equal, assert_is_member +from ipalib import api +from ipalib import errors + + +class test_rolegroup(XMLRPC_test): + """ + Test the `rolegroup` plugin. + """ + cn = u'testgroup' + description = u'Test role group' + kw = {'cn': cn, 'description': description} + + rolegroup_cn = u'ipatestgroup' + rolegroup_description = u'Test group for rolegroups' + + def test_1_rolegroup_add(self): + """ + Test the `xmlrpc.rolegroup_add` method. + """ + (dn, res) = api.Command['rolegroup_add'](**self.kw) + assert res + assert_attr_equal(res, 'description', self.description) + assert_attr_equal(res, 'cn', self.cn) + + def test_2_add_group(self): + """ + Add a group to test add/remove member. + """ + kw = {'cn': self.rolegroup_cn, 'description': self.rolegroup_description} + (dn, res) = api.Command['group_add'](**kw) + assert res + assert_attr_equal(res, 'description', self.rolegroup_description) + assert_attr_equal(res, 'cn', self.rolegroup_cn) + + def test_3_rolegroup_add_member(self): + """ + Test the `xmlrpc.rolegroup_add_member` method. + """ + kw = {} + kw['groups'] = self.rolegroup_cn + (total, res) = api.Command['rolegroup_add_member'](self.cn, **kw) + assert total == 1 + + def test_4_rolegroup_show(self): + """ + Test the `xmlrpc.rolegroup_show` method. + """ + (dn, res) = api.Command['rolegroup_show'](self.cn) + assert res + assert_attr_equal(res, 'description', self.description) + assert_attr_equal(res, 'cn', self.cn) + assert_is_member(res, 'cn=%s' % self.rolegroup_cn) + + def test_5_rolegroup_find(self): + """ + Test the `xmlrpc.rolegroup_find` method. + """ + (res, truncated) = api.Command['rolegroup_find'](self.cn) + assert res + assert_attr_equal(res[0][1], 'description', self.description) + assert_attr_equal(res[0][1], 'cn', self.cn) + assert_is_member(res[0][1], 'cn=%s' % self.rolegroup_cn) + + def test_6_rolegroup_mod(self): + """ + Test the `xmlrpc.rolegroup_mod` method. + """ + newdesc = u'Updated role group' + modkw = {'cn': self.cn, 'description': newdesc} + (dn, res) = api.Command['rolegroup_mod'](**modkw) + assert res + assert_attr_equal(res, 'description', newdesc) + + # Ok, double-check that it was changed + (dn, res) = api.Command['rolegroup_show'](self.cn) + assert res + assert_attr_equal(res, 'description', newdesc) + assert_attr_equal(res, 'cn', self.cn) + + def test_7_rolegroup_del_member(self): + """ + Test the `xmlrpc.rolegroup_del_member` method. + """ + kw = {} + kw['groups'] = self.rolegroup_cn + (total, res) = api.Command['rolegroup_del_member'](self.cn, **kw) + assert total == 1 + + def test_8_rolegroup_del(self): + """ + Test the `xmlrpc.rolegroup_del` method. + """ + res = api.Command['rolegroup_del'](self.cn) + assert res == True + + # Verify that it is gone + try: + api.Command['rolegroup_show'](self.cn) + except errors.NotFound: + pass + else: + assert False + + def test_9_del_group(self): + """ + Remove the group we created for member testing. + """ + res = api.Command['group_del'](self.rolegroup_cn) + assert res == True + + # Verify that it is gone + try: + api.Command['group_show'](self.rolegroup_cn) + except errors.NotFound: + pass + else: + assert False + diff --git a/tests/test_xmlrpc/test_service_plugin.py b/tests/test_xmlrpc/test_service_plugin.py new file mode 100644 index 000000000..7a7608a80 --- /dev/null +++ b/tests/test_xmlrpc/test_service_plugin.py @@ -0,0 +1,113 @@ +# Authors: +# Rob Crittenden +# Pavel Zuna +# +# Copyright (C) 2008 Red Hat +# see file 'COPYING' for use and warranty information +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; version 2 only +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# 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/service.py` module. +""" + +import sys +from xmlrpc_test import XMLRPC_test, assert_attr_equal +from ipalib import api +from ipalib import errors + + +class test_service(XMLRPC_test): + """ + Test the `service` plugin. + """ + principal = u'HTTP/ipatest.%s@%s' % (api.env.domain, api.env.realm) + hostprincipal = u'host/ipatest.%s@%s' % (api.env.domain, api.env.realm) + kw = {'krbprincipalname': principal} + + def test_1_service_add(self): + """ + Test adding a HTTP principal using the `xmlrpc.service_add` method. + """ + (dn, res) = api.Command['service_add'](**self.kw) + assert res + assert_attr_equal(res, 'krbprincipalname', self.principal) + + def test_2_service_add(self): + """ + Test adding a host principal using `xmlrpc.service_add`. Host + services are not allowed. + """ + kw = {'krbprincipalname': self.hostprincipal} + try: + api.Command['service_add'](**kw) + except errors.HostService: + pass + else: + assert False + + def test_3_service_add(self): + """ + Test adding a malformed principal ('foo'). + """ + kw = {'krbprincipalname': u'foo'} + try: + api.Command['service_add'](**kw) + except errors.MalformedServicePrincipal: + pass + else: + assert False + + def test_4_service_add(self): + """ + Test adding a malformed principal ('HTTP/foo@FOO.NET'). + """ + kw = {'krbprincipalname': u'HTTP/foo@FOO.NET'} + try: + api.Command['service_add'](**kw) + except errors.RealmMismatch: + pass + else: + assert False + + def test_5_service_show(self): + """ + Test the `xmlrpc.service_show` method. + """ + (dn, res) = api.Command['service_show'](self.principal) + assert res + assert_attr_equal(res, 'krbprincipalname', self.principal) + + def test_6_service_find(self): + """ + Test the `xmlrpc.service_find` method. + """ + (res, truncated) = api.Command['service_find'](self.principal) + assert res + assert_attr_equal(res[0][1], 'krbprincipalname', self.principal) + + def test_7_service_del(self): + """ + Test the `xmlrpc.service_del` method. + """ + res = api.Command['service_del'](self.principal) + assert res == True + + # Verify that it is gone + try: + api.Command['service_show'](self.principal) + except errors.NotFound: + pass + else: + assert False + diff --git a/tests/test_xmlrpc/test_taskgroup_plugin.py b/tests/test_xmlrpc/test_taskgroup_plugin.py new file mode 100644 index 000000000..b1e811c76 --- /dev/null +++ b/tests/test_xmlrpc/test_taskgroup_plugin.py @@ -0,0 +1,174 @@ +# Authors: +# Rob Crittenden +# Pavel Zuna +# +# Copyright (C) 2009 Red Hat +# see file 'COPYING' for use and warranty information +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; version 2 only +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# 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/taskgroup.py` module. +""" + +import sys +from xmlrpc_test import XMLRPC_test, assert_attr_equal, assert_is_member +from ipalib import api +from ipalib import errors + + +class test_taskgroup(XMLRPC_test): + """ + Test the `taskgroup` plugin. + """ + cn = u'testgroup' + description = u'Test task group' + kw = {'cn': cn, 'description': description} + + taskgroup_cn = u'ipatestgroup' + taskgroup_description = u'Test group for taskgroups' + + rolegroup_cn = u'iparolegroup' + rolegroup_description = u'Test rolegroup for taskgroups' + + def test_1_taskgroup_add(self): + """ + Test the `xmlrpc.taskgroup_add` method. + """ + (dn, res) = api.Command['taskgroup_add'](**self.kw) + assert res + assert_attr_equal(res, 'description', self.description) + assert_attr_equal(res, 'cn', self.cn) + + def test_2_add_rolegroup(self): + """ + Add a rolegroup to test add/remove member. + """ + kw={'cn': self.rolegroup_cn, 'description': self.rolegroup_description} + (dn, res) = api.Command['rolegroup_add'](**kw) + assert res + assert_attr_equal(res, 'description', self.rolegroup_description) + assert_attr_equal(res, 'cn', self.rolegroup_cn) + + def test_3_add_taskgroup(self): + """ + Add a group to test add/remove member. + """ + kw = {'cn': self.taskgroup_cn, 'description': self.taskgroup_description} + (dn, res) = api.Command['group_add'](**kw) + assert res + assert_attr_equal(res, 'description', self.taskgroup_description) + assert_attr_equal(res, 'cn', self.taskgroup_cn) + + def test_4_taskgroup_add_member(self): + """ + Test the `xmlrpc.taskgroup_add_member` method. + """ + kw = {} + kw['groups'] = self.taskgroup_cn + kw['rolegroups'] = self.rolegroup_cn + (total, res) = api.Command['taskgroup_add_member'](self.cn, **kw) + assert total == 2 + + def test_5_taskgroup_show(self): + """ + Test the `xmlrpc.taskgroup_show` method. + """ + (dn, res) = api.Command['taskgroup_show'](self.cn, all=True) + assert res + assert_attr_equal(res, 'description', self.description) + assert_attr_equal(res, 'cn', self.cn) + assert_is_member(res, 'cn=%s' % self.taskgroup_cn) + assert_is_member(res, 'cn=%s' % self.rolegroup_cn) + + def test_6_taskgroup_find(self): + """ + Test the `xmlrpc.taskgroup_find` method. + """ + (res, truncated) = api.Command['taskgroup_find'](self.cn) + assert res + assert_attr_equal(res[0][1], 'description', self.description) + assert_attr_equal(res[0][1], 'cn', self.cn) + assert_is_member(res[0][1], 'cn=%s' % self.taskgroup_cn) + assert_is_member(res[0][1], 'cn=%s' % self.rolegroup_cn) + + def test_7_taskgroup_mod(self): + """ + Test the `xmlrpc.taskgroup_mod` method. + """ + newdesc = u'Updated task group' + modkw = {'cn': self.cn, 'description': newdesc} + (dn, res) = api.Command['taskgroup_mod'](**modkw) + assert res + assert_attr_equal(res, 'description', newdesc) + + # Ok, double-check that it was changed + (dn, res) = api.Command['taskgroup_show'](self.cn) + assert res + assert_attr_equal(res, 'description', newdesc) + assert_attr_equal(res, 'cn', self.cn) + + def test_8_taskgroup_del_member(self): + """ + Test the `xmlrpc.taskgroup_remove_member` method. + """ + kw = {} + kw['groups'] = self.taskgroup_cn + (total, res) = api.Command['taskgroup_del_member'](self.cn, **kw) + assert total == 1 + + def test_9_taskgroup_del(self): + """ + Test the `xmlrpc.taskgroup_del` method. + """ + res = api.Command['taskgroup_del'](self.cn) + assert res == True + + # Verify that it is gone + try: + api.Command['taskgroup_show'](self.cn) + except errors.NotFound: + pass + else: + assert False + + def test_a_del_taskgroup(self): + """ + Remove the group we created for member testing. + """ + res = api.Command['group_del'](self.taskgroup_cn) + assert res == True + + # Verify that it is gone + try: + api.Command['group_show'](self.taskgroup_cn) + except errors.NotFound: + pass + else: + assert False + + def test_b_del_rolegroup(self): + """ + Remove the rolegroup we created for member testing. + """ + res = api.Command['rolegroup_del'](self.rolegroup_cn) + assert res == True + + # Verify that it is gone + try: + api.Command['rolegroup_show'](self.rolegroup_cn) + except errors.NotFound: + pass + else: + assert False + diff --git a/tests/test_xmlrpc/test_user_plugin.py b/tests/test_xmlrpc/test_user_plugin.py new file mode 100644 index 000000000..3bc8177a3 --- /dev/null +++ b/tests/test_xmlrpc/test_user_plugin.py @@ -0,0 +1,145 @@ +# Authors: +# Rob Crittenden +# Pavel Zuna +# +# Copyright (C) 2008 Red Hat +# see file 'COPYING' for use and warranty information +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; version 2 only +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# 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) + + 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 + -- cgit