diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2009-12-15 13:36:14 -0700 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2009-12-16 15:54:55 -0700 |
commit | 8ae0f9c8aadeacb16142198b65e368d2aa7926f4 (patch) | |
tree | ed2500b42ae60d1cd953acdc5454278328ccd2e1 /tests/test_xmlrpc/test_hostgroup_plugin.py | |
parent | c334ec45849100b454bf775ba2ecaa05c6106546 (diff) | |
download | freeipa-8ae0f9c8aadeacb16142198b65e368d2aa7926f4.tar.gz freeipa-8ae0f9c8aadeacb16142198b65e368d2aa7926f4.tar.xz freeipa-8ae0f9c8aadeacb16142198b65e368d2aa7926f4.zip |
host and hostgroup summary messages, declarative tests; fix tests for 'dn'
Diffstat (limited to 'tests/test_xmlrpc/test_hostgroup_plugin.py')
-rw-r--r-- | tests/test_xmlrpc/test_hostgroup_plugin.py | 336 |
1 files changed, 220 insertions, 116 deletions
diff --git a/tests/test_xmlrpc/test_hostgroup_plugin.py b/tests/test_xmlrpc/test_hostgroup_plugin.py index 7fa227a28..76a55cca9 100644 --- a/tests/test_xmlrpc/test_hostgroup_plugin.py +++ b/tests/test_xmlrpc/test_hostgroup_plugin.py @@ -2,7 +2,7 @@ # Rob Crittenden <rcritten@redhat.com> # Pavel Zuna <pzuna@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,121 +17,225 @@ # 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. +Test the `ipalib.plugins.hostgroup` 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, 'raw': True} - - 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. - """ - entry = api.Command['hostgroup_add'](**self.kw)['result'] - assert_attr_equal(entry, 'description', self.description) - assert_attr_equal(entry, 'cn', self.cn) - assert_attr_equal(entry, 'objectclass', 'ipaobject') - - 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, 'raw': True} - entry = api.Command['host_add'](**kw)['result'] - assert_attr_equal(entry, 'description', self.host_description) - assert_attr_equal(entry, 'fqdn', self.host_fqdn) - - def test_3_hostgroup_add_member(self): - """ - Test the `xmlrpc.hostgroup_add_member` method. - """ - kw = {'raw': True} - kw['host'] = self.host_fqdn - ret = api.Command['hostgroup_add_member'](self.cn, **kw) - assert ret['result']['member'] != [] - assert ret['completed'] == 1 - - def test_4_hostgroup_show(self): - """ - Test the `xmlrpc.hostgroup_show` method. - """ - entry = api.Command['hostgroup_show'](self.cn, raw=True)['result'] - assert_attr_equal(entry, 'description', self.description) - assert_attr_equal(entry, 'cn', self.cn) - - def test_5_hostgroup_find(self): - """ - Test the `xmlrpc.hostgroup_find` method. - """ - ret = api.Command['hostgroup_find'](cn=self.cn, raw=True) - assert ret['truncated'] is False - entries = ret['result'] - assert_attr_equal(entries[0], 'description', self.description) - assert_attr_equal(entries[0], '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, 'raw': True} - entry = api.Command['hostgroup_mod'](**modkw)['result'] - assert_attr_equal(entry, 'description', newdesc) - - # Ok, double-check that it was changed - entry = api.Command['hostgroup_show'](self.cn, raw=True)['result'] - assert_attr_equal(entry, 'description', newdesc) - assert_attr_equal(entry, 'cn', self.cn) - - def test_7_hostgroup_remove_member(self): - """ - Test the `xmlrpc.hostgroup_remove_member` method. - """ - kw = {'raw': True} - kw['host'] = self.host_fqdn - ret = api.Command['hostgroup_remove_member'](self.cn, **kw) - assert ret['completed'] == 1 - - def test_8_hostgroup_del(self): - """ - Test the `xmlrpc.hostgroup_del` method. - """ - assert api.Command['hostgroup_del'](self.cn)['result'] is 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. - """ - assert api.Command['host_del'](self.host_fqdn)['result'] is True - - # Verify that it is gone - try: - api.Command['host_show'](self.host_fqdn) - except errors.NotFound: - pass - else: - assert False +from ipalib import api, errors +from tests.test_xmlrpc.xmlrpc_test import Declarative +from tests.test_xmlrpc import objectclasses + + +fqdn1 = u'testhost1.%s' % api.env.domain + + +class test_hostgroup(Declarative): + + cleanup_commands = [ + ('hostgroup_del', [u'testhostgroup1'], {}), + ('host_del', [fqdn1], {}), + ] + + tests=[ + + dict( + desc='Try to retrieve non-existent testhostgroup1', + command=('hostgroup_show', [u'testhostgroup1'], {}), + expected=errors.NotFound(reason='no such entry'), + ), + + + dict( + desc='Try to update non-existent testhostgroup1', + command=('hostgroup_mod', [u'testhostgroup1'], + dict(description=u'Updated hostgroup 1') + ), + expected=errors.NotFound(reason='no such entry'), + ), + + + dict( + desc='Try to delete non-existent testhostgroup1', + command=('hostgroup_del', [u'testhostgroup1'], {}), + expected=errors.NotFound(reason='no such entry'), + ), + + + dict( + desc='Create hostgroup testhostgroup1', + command=('hostgroup_add', [u'testhostgroup1'], + dict(description=u'Test hostgroup 1') + ), + expected=dict( + value=u'testhostgroup1', + summary=u'Added hostgroup "testhostgroup1"', + result=dict( + cn=(u'testhostgroup1',), + objectclass=objectclasses.hostgroup, + description=(u'Test hostgroup 1',), + ), + ), + ignore_values=['ipauniqueid', 'dn'], + ), + + + dict( + desc='Try to create duplicate testhostgroup1', + command=('hostgroup_add', [u'testhostgroup1'], + dict(description=u'Test hostgroup 1') + ), + expected=errors.DuplicateEntry(), + ), + + + dict( + desc='Create host %r' % fqdn1, + command=('host_add', [fqdn1], + dict( + description=u'Test host 1', + localityname=u'Undisclosed location 1', + ), + ), + expected=dict( + value=fqdn1, + summary=u'Added host "%s"' % fqdn1, + result=dict( + cn=(fqdn1,), # FIXME: we should only return fqdn + fqdn=(fqdn1,), + description=(u'Test host 1',), + localityname=(u'Undisclosed location 1',), + krbprincipalname=(u'host/%s@%s' % (fqdn1, api.env.realm),), + serverhostname=(u'testhost1',), + objectclass=objectclasses.host, + ), + ), + ignore_values=['ipauniqueid', 'dn'], + ), + + + dict( + desc=u'Add %r to testhostgroup1' % fqdn1, + command=( + 'hostgroup_add_member', [u'testhostgroup1'], dict(host=fqdn1) + ), + expected=dict( + completed=1, + failed=dict( + member=dict( + host=tuple(), + hostgroup=tuple(), + ), + ), + result={ + 'member host': (fqdn1,), + }, + ), + ), + + + dict( + desc='Retrieve testhostgroup1', + command=('hostgroup_show', [u'testhostgroup1'], {}), + expected=dict( + value=u'testhostgroup1', + summary=None, + result={ + 'member host': (u'testhost1.example.com',), + 'cn': (u'testhostgroup1',), + 'description': (u'Test hostgroup 1',) + }, + ), + ignore_values=['dn'], + ), + + + dict( + desc='Search for testhostgroup1', + command=('hostgroup_find', [], dict(cn=u'testhostgroup1')), + expected=dict( + count=1, + truncated=False, + summary=u'1 hostgroup matched', + result=( + { + 'member host': (u'testhost1.example.com',), + 'cn': (u'testhostgroup1',), + 'description': (u'Test hostgroup 1',), + }, + ), + ), + ), + + + dict( + desc='Update testhostgroup1', + command=('hostgroup_mod', [u'testhostgroup1'], + dict(description=u'Updated hostgroup 1') + ), + expected=dict( + value=u'testhostgroup1', + summary=u'Modified hostgroup "testhostgroup1"', + result=dict( + description=(u'Updated hostgroup 1',), + ), + ), + ), + + + dict( + desc='Retrieve testhostgroup1 to verify update', + command=('hostgroup_show', [u'testhostgroup1'], {}), + expected=dict( + value=u'testhostgroup1', + summary=None, + result={ + 'member host': (u'testhost1.example.com',), + 'cn': (u'testhostgroup1',), + 'description': (u'Updated hostgroup 1',) + }, + ), + ignore_values=['dn'], + ), + + + dict( + desc='Remove %s from testhostgroup1', + command=('hostgroup_remove_member', [u'testhostgroup1'], + dict(host=fqdn1) + ), + expected=dict( + failed=dict( + member=dict( + host=tuple(), + hostgroup=tuple(), + ), + ), + completed=1, + result={}, + ), + ), + + + dict( + desc='Delete testhostgroup1', + command=('hostgroup_del', [u'testhostgroup1'], {}), + expected=dict( + value=u'testhostgroup1', + summary=u'Deleted hostgroup "testhostgroup1"', + result=True, + ), + ), + + + dict( + desc='Delete %s' % fqdn1, + command=('host_del', [fqdn1], {}), + expected=dict( + value=fqdn1, + summary=u'Deleted host "%s"' % fqdn1, + result=True, + ), + ) + + ] |