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_host_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_host_plugin.py')
-rw-r--r-- | tests/test_xmlrpc/test_host_plugin.py | 325 |
1 files changed, 225 insertions, 100 deletions
diff --git a/tests/test_xmlrpc/test_host_plugin.py b/tests/test_xmlrpc/test_host_plugin.py index 009e98eb6..dab96c94c 100644 --- a/tests/test_xmlrpc/test_host_plugin.py +++ b/tests/test_xmlrpc/test_host_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,105 +17,230 @@ # 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. +Test the `ipalib.plugins.host` 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, 'raw': True} - - def test_1_host_add(self): - """ - Test the `xmlrpc.host_add` method. - """ - res = api.Command['host_add'](**self.kw)['result'] - 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) - assert_attr_equal(res, 'objectclass', 'ipaobject') - - def test_2_host_show(self): - """ - Test the `xmlrpc.host_show` method with all attributes. - """ - kw = {'fqdn': self.fqdn, 'all': True, 'raw': True} - res = api.Command['host_show'](**kw)['result'] - 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, 'raw': True} - res = api.Command['host_show'](**kw)['result'] - 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, 'raw': True} - res = api.Command['host_find'](**kw)['result'] - assert res - assert_attr_equal(res[0], 'description', self.description) - assert_attr_equal(res[0], 'fqdn', self.fqdn) - assert_attr_equal(res[0], 'l', self.localityname) - - def test_5_host_find(self): - """ - Test the `xmlrpc.host_find` method with default attributes. - """ - res = api.Command['host_find'](self.fqdn, raw=True)['result'] - assert res - assert_attr_equal(res[0], 'description', self.description) - assert_attr_equal(res[0], 'fqdn', self.fqdn) - assert_attr_equal(res[0], '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, 'raw': True} - res = api.Command['host_mod'](**modkw)['result'] - assert res - assert_attr_equal(res, 'description', newdesc) - - # Ok, double-check that it was changed - res = api.Command['host_show'](self.fqdn, raw=True)['result'] - 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. - """ - assert api.Command['host_del'](self.fqdn)['result'] is True - - # Verify that it is gone - try: - api.Command['host_show'](self.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_host(Declarative): + + cleanup_commands = [ + ('host_del', [fqdn1], {}), + ] + + tests = [ + + dict( + desc='Try to retrieve non-existent %r' % fqdn1, + command=('host_show', [fqdn1], {}), + expected=errors.NotFound(reason='no such entry'), + ), + + + dict( + desc='Try to update non-existent %r' % fqdn1, + command=('host_mod', [fqdn1], dict(description=u'Nope')), + expected=errors.NotFound(reason='no such entry'), + ), + + + dict( + desc='Try to delete non-existent %r' % fqdn1, + command=('host_del', [fqdn1], {}), + expected=errors.NotFound(reason='no such entry'), + ), + + + dict( + desc='Create %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='Try to create duplicate %r' % fqdn1, + command=('host_add', [fqdn1], + dict( + description=u'Test host 1', + localityname=u'Undisclosed location 1', + ), + ), + expected=errors.DuplicateEntry(), + ), + + + dict( + desc='Retrieve %r' % fqdn1, + command=('host_show', [fqdn1], {}), + expected=dict( + value=fqdn1, + summary=None, + result=dict( + fqdn=(fqdn1,), + description=(u'Test host 1',), + localityname=(u'Undisclosed location 1',), + ), + ), + ignore_values=['dn'], + ), + + + dict( + desc='Retrieve %r with all=True' % fqdn1, + command=('host_show', [fqdn1], dict(all=True)), + expected=dict( + value=fqdn1, + summary=None, + result=dict( + cn=(fqdn1,), + fqdn=(fqdn1,), + description=(u'Test host 1',), + # FIXME: Why is 'localalityname' returned as 'l' with --all? + # It is intuitive for --all to return additional attributes, + # but not to return existing attributes under different + # names. + l=(u'Undisclosed location 1',), + krbprincipalname=(u'host/%s@%s' % (fqdn1, api.env.realm),), + serverhostname=(u'testhost1',), + objectclass=objectclasses.host, + ), + ), + ignore_values=['dn', 'ipauniqueid'], + ), + + + dict( + desc='Search for %r' % fqdn1, + command=('host_find', [fqdn1], {}), + expected=dict( + count=1, + truncated=False, + summary=u'1 host matched', + result=( + dict( + fqdn=(fqdn1,), + description=(u'Test host 1',), + localityname=(u'Undisclosed location 1',), + ), + ), + ), + ), + + + dict( + desc='Search for %r with all=True' % fqdn1, + command=('host_find', [fqdn1], dict(all=True)), + expected=dict( + count=1, + truncated=False, + summary=u'1 host matched', + result=( + dict( + cn=(fqdn1,), + fqdn=(fqdn1,), + description=(u'Test host 1',), + # FIXME: Why is 'localalityname' returned as 'l' with --all? + # It is intuitive for --all to return additional attributes, + # but not to return existing attributes under different + # names. + l=(u'Undisclosed location 1',), + krbprincipalname=(u'host/%s@%s' % (fqdn1, api.env.realm),), + serverhostname=(u'testhost1',), + objectclass=objectclasses.host, + ), + ), + ), + # FIXME: With --all, host_show() returns the 'dn', but host_find() + # doesn't. + ignore_values=['ipauniqueid'], + ), + + + dict( + desc='Update %r' % fqdn1, + command=('host_mod', [fqdn1], dict(description=u'Updated host 1')), + expected=dict( + value=fqdn1, + summary=u'Modified host "%s"' % fqdn1, + result=dict( + description=(u'Updated host 1',), + ), + ), + ), + + + dict( + desc='Retrieve %r to verify update' % fqdn1, + command=('host_show', [fqdn1], {}), + expected=dict( + value=fqdn1, + summary=None, + result=dict( + fqdn=(fqdn1,), + description=(u'Updated host 1',), + localityname=(u'Undisclosed location 1',), + ), + ), + ignore_values=['dn'], + ), + + + dict( + desc='Delete %r' % fqdn1, + command=('host_del', [fqdn1], {}), + expected=dict( + value=fqdn1, + summary=u'Deleted host "%s"' % fqdn1, + result=True, + ), + ), + + + dict( + desc='Try to retrieve non-existent %r' % fqdn1, + command=('host_show', [fqdn1], {}), + expected=errors.NotFound(reason='no such entry'), + ), + + + dict( + desc='Try to update non-existent %r' % fqdn1, + command=('host_mod', [fqdn1], dict(description=u'Nope')), + expected=errors.NotFound(reason='no such entry'), + ), + + + dict( + desc='Try to delete non-existent %r' % fqdn1, + command=('host_del', [fqdn1], {}), + expected=errors.NotFound(reason='no such entry'), + ), + + ] |