Fix unit tests for plugins using baseldap classes.

This commit is contained in:
Pavel Zuna 2009-08-27 15:55:19 +02:00 committed by Rob Crittenden
parent 1e48662b9b
commit e01b1b8f99
11 changed files with 231 additions and 277 deletions

View File

@ -245,8 +245,11 @@ class textui(backend.Backend):
>>> ui.print_attribute(attr, u'dc=example,dc=com')
dn: dc=example,dc=com
>>> attr = 'objectClass'
>>> ui.print_attribute(attr, [u'top', u'someClass'])
>>> ui.print_attribute(attr, [u'top', u'someClass'], one_value_per_line=False)
objectClass: top, someClass
>>> ui.print_attribute(attr, [u'top', u'someClass'])
objectClass: top
objectClass: someClass
"""
assert isinstance(attr, basestring)
if not isinstance(value, (list, tuple)):

View File

@ -52,140 +52,6 @@ class CrudChecker(ClassChecker):
return api
class test_Add(CrudChecker):
"""
Test the `ipalib.crud.Add` class.
"""
_cls = crud.Add
def test_get_args(self):
"""
Test the `ipalib.crud.Add.get_args` method.
"""
api = self.get_api()
assert list(api.Method.user_verb.args) == ['uid']
assert api.Method.user_verb.args.uid.required is True
api = self.get_api(args=('extra?',))
assert list(api.Method.user_verb.args) == ['uid', 'extra']
assert api.Method.user_verb.args.uid.required is True
assert api.Method.user_verb.args.extra.required is False
def test_get_options(self):
"""
Test the `ipalib.crud.Add.get_options` method.
"""
api = self.get_api()
assert list(api.Method.user_verb.options) == \
['givenname', 'sn', 'initials']
for param in api.Method.user_verb.options():
assert param.required is True
api = self.get_api(options=('extra?',))
assert list(api.Method.user_verb.options) == \
['givenname', 'sn', 'initials', 'extra']
assert api.Method.user_verb.options.extra.required is False
class test_Get(CrudChecker):
"""
Test the `ipalib.crud.Get` class.
"""
_cls = crud.Get
def test_get_args(self):
"""
Test the `ipalib.crud.Get.get_args` method.
"""
api = self.get_api()
assert list(api.Method.user_verb.args) == ['uid']
assert api.Method.user_verb.args.uid.required is True
def test_get_options(self):
"""
Test the `ipalib.crud.Get.get_options` method.
"""
api = self.get_api()
assert list(api.Method.user_verb.options) == []
assert len(api.Method.user_verb.options) == 0
class test_Del(CrudChecker):
"""
Test the `ipalib.crud.Del` class.
"""
_cls = crud.Del
def test_get_args(self):
"""
Test the `ipalib.crud.Del.get_args` method.
"""
api = self.get_api()
assert list(api.Method.user_verb.args) == ['uid']
assert api.Method.user_verb.args.uid.required is True
def test_get_options(self):
"""
Test the `ipalib.crud.Del.get_options` method.
"""
api = self.get_api()
assert list(api.Method.user_verb.options) == []
assert len(api.Method.user_verb.options) == 0
class test_Mod(CrudChecker):
"""
Test the `ipalib.crud.Mod` class.
"""
_cls = crud.Mod
def test_get_args(self):
"""
Test the `ipalib.crud.Mod.get_args` method.
"""
api = self.get_api()
assert list(api.Method.user_verb.args) == ['uid']
assert api.Method.user_verb.args.uid.required is True
def test_get_options(self):
"""
Test the `ipalib.crud.Mod.get_options` method.
"""
api = self.get_api()
assert list(api.Method.user_verb.options) == \
['givenname', 'sn', 'initials']
for param in api.Method.user_verb.options():
assert param.required is False
class test_Find(CrudChecker):
"""
Test the `ipalib.crud.Find` class.
"""
_cls = crud.Find
def test_get_args(self):
"""
Test the `ipalib.crud.Find.get_args` method.
"""
api = self.get_api()
assert list(api.Method.user_verb.args) == ['uid']
assert api.Method.user_verb.args.uid.required is True
def test_get_options(self):
"""
Test the `ipalib.crud.Find.get_options` method.
"""
api = self.get_api()
assert list(api.Method.user_verb.options) == \
['givenname', 'sn', 'initials']
for param in api.Method.user_verb.options():
assert param.required is False
class test_CrudBackend(ClassChecker):
"""
Test the `ipalib.crud.CrudBackend` class.

View File

@ -703,7 +703,6 @@ class test_Object(ClassChecker):
o = example1()
o.set_api(api)
assert o.primary_key is None
assert o.params_minus_pk is None
# Test with 1 primary key:
class example2(self.cls):

View File

@ -29,6 +29,7 @@ from tests.util import dummy_ugettext, assert_equal
from tests.data import binary_bytes, utf8_bytes, unicode_str
from ipalib import parameters, request, errors, config
from ipalib.constants import TYPE_ERROR, CALLABLE_ERROR, NULLS
from ipalib.errors import ValidationError
class test_DefaultFrom(ClassChecker):
@ -445,11 +446,11 @@ class test_Param(ClassChecker):
assert str(e) == 'value: empty tuple must be converted to None'
# Test with wrong (scalar) type:
e = raises(TypeError, o.validate, (None, None, 42, None))
assert str(e) == TYPE_ERROR % ('value[2]', NoneType, 42, int)
e = raises(ValidationError, o.validate, (None, None, 42, None))
assert str(e) == 'invalid %s' % (TYPE_ERROR % ('\'my_param\'', NoneType, 42, int))
o = self.cls('my_param')
e = raises(TypeError, o.validate, 'Hello')
assert str(e) == TYPE_ERROR % ('value', NoneType, 'Hello', str)
e = raises(ValidationError, o.validate, 'Hello')
assert str(e) == 'invalid %s' % (TYPE_ERROR % ('\'my_param\'', NoneType, 'Hello', str))
class Example(self.cls):
type = int
@ -511,10 +512,10 @@ class test_Param(ClassChecker):
o = MyParam('my_param', okay)
# Test that TypeError is appropriately raised:
e = raises(TypeError, o._validate_scalar, 0)
assert str(e) == TYPE_ERROR % ('value', bool, 0, int)
e = raises(TypeError, o._validate_scalar, 'Hi', index=4)
assert str(e) == TYPE_ERROR % ('value[4]', bool, 'Hi', str)
e = raises(ValidationError, o._validate_scalar, 0)
assert str(e) == 'invalid %s' % (TYPE_ERROR % ('\'my_param\'', bool, 0, int))
e = raises(ValidationError, o._validate_scalar, 'Hi', index=4)
assert str(e) == 'invalid %s' % (TYPE_ERROR % ('\'my_param\'', bool, 'Hi', str))
e = raises(TypeError, o._validate_scalar, True, index=3.0)
assert str(e) == TYPE_ERROR % ('index', int, 3.0, float)

View File

@ -31,14 +31,24 @@ class test_automount(XMLRPC_test):
"""
Test the `automount` plugin.
"""
locname = u'testlocation'
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}
loc_kw = {'cn': locname}
map_kw = {'cn': locname, 'automountmapname': mapname, 'description': description, 'raw': True}
key_kw = {'cn': locname, 'automountmapname': mapname, 'automountkey': keyname, 'automountinformation': info, 'raw': True}
key_kw2 = {'cn': locname, 'automountmapname': mapname, 'automountkey': keyname2, 'automountinformation': info, 'raw': True}
def test_0_automountlocation_add(self):
"""
Test adding a location `xmlrpc.automountlocation_add` method.
"""
(dn, res) = api.Command['automountlocation_add'](**self.loc_kw)
assert res
assert_attr_equal(res, 'cn', self.locname)
def test_1_automountmap_add(self):
"""
@ -79,7 +89,7 @@ class test_automount(XMLRPC_test):
"""
Test the `xmlrpc.automountmap_show` method.
"""
(dn, res) = api.Command['automountmap_show'](self.mapname)
(dn, res) = api.Command['automountmap_show'](self.locname, self.mapname, raw=True)
assert res
assert_attr_equal(res, 'automountmapname', self.mapname)
@ -87,7 +97,7 @@ class test_automount(XMLRPC_test):
"""
Test the `xmlrpc.automountmap_find` method.
"""
(res, truncated) = api.Command['automountmap_find'](self.mapname)
(res, truncated) = api.Command['automountmap_find'](self.locname, self.mapname, raw=True)
assert res
assert_attr_equal(res[0][1], 'automountmapname', self.mapname)
@ -95,7 +105,7 @@ class test_automount(XMLRPC_test):
"""
Test the `xmlrpc.automountkey_show` method.
"""
showkey_kw={'automountmapname': self.mapname, 'automountkey': self.keyname}
showkey_kw={'cn': self.locname, 'automountmapname': self.mapname, 'automountkey': self.keyname, 'raw': True}
(dn, res) = api.Command['automountkey_show'](**showkey_kw)
assert res
assert_attr_equal(res, 'automountkey', self.keyname)
@ -105,7 +115,7 @@ class test_automount(XMLRPC_test):
"""
Test the `xmlrpc.automountkey_find` method.
"""
(res, truncated) = api.Command['automountkey_find'](self.mapname)
(res, truncated) = api.Command['automountkey_find'](self.locname, self.mapname, raw=True)
assert res
assert len(res) == 2
assert_attr_equal(res[1][1], 'automountkey', self.keyname)
@ -135,7 +145,7 @@ class test_automount(XMLRPC_test):
"""
Test the `xmlrpc.automountkey_del` method.
"""
delkey_kw={'automountmapname': self.mapname, 'automountkey': self.keyname}
delkey_kw={'cn': self.locname, 'automountmapname': self.mapname, 'automountkey': self.keyname, 'raw': True}
res = api.Command['automountkey_del'](**delkey_kw)
assert res == True
@ -147,16 +157,16 @@ class test_automount(XMLRPC_test):
else:
assert False
def test_c_automountmap_del(self):
def test_c_automountlocation_del(self):
"""
Test the `xmlrpc.automountmap_del` method.
Test the `xmlrpc.automountlocation_del` method.
"""
res = api.Command['automountmap_del'](self.mapname)
res = api.Command['automountlocation_del'](self.locname)
assert res == True
# Verify that it is gone
try:
api.Command['automountmap_show'](self.mapname)
api.Command['automountlocation_show'](self.locname)
except errors.NotFound:
pass
else:
@ -164,10 +174,10 @@ class test_automount(XMLRPC_test):
def test_d_automountmap_del(self):
"""
Test that the `xmlrpc.automountmap_del` method removes all keys
Test that the `xmlrpc.automountlocation_del` method removes all maps and keys
"""
# Verify that the second key we added is gone
key_kw = {'automountmapname': self.mapname, 'automountkey': self.keyname2}
key_kw = {'cn': self.locname, 'automountmapname': self.mapname, 'automountkey': self.keyname2, 'raw': True}
try:
api.Command['automountkey_show'](**key_kw)
except errors.NotFound:
@ -180,26 +190,34 @@ class test_automount_indirect(XMLRPC_test):
"""
Test the `automount` plugin indirect map functionality.
"""
locname = u'testlocation'
mapname = u'auto.home'
keyname = u'/home'
parentmap = u'auto.master'
description = u'Home directories'
map_kw = {'key': keyname, 'parentmap': parentmap, 'description': description}
map_kw = {'key': keyname, 'parentmap': parentmap, 'description': description, 'raw': True}
def test_0_automountlocation_add(self):
"""
Test adding a location.
"""
(dn, res) = api.Command['automountlocation_add'](self.locname, raw=True)
assert res
assert_attr_equal(res, 'cn', self.locname)
def test_1_automountmap_add_indirect(self):
"""
Test adding an indirect map.
"""
(dn, res) = api.Command['automountmap_add_indirect'](self.mapname, **self.map_kw)
(dn, res) = api.Command['automountmap_add_indirect'](self.locname, self.mapname, **self.map_kw)
assert res
assert_attr_equal(res, 'automountinformation', self.mapname)
assert_attr_equal(res, 'automountmapname', 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)
(dn, res) = api.Command['automountkey_show'](self.locname, self.parentmap, self.keyname, raw=True)
assert res
assert_attr_equal(res, 'automountkey', self.keyname)
@ -207,7 +225,7 @@ class test_automount_indirect(XMLRPC_test):
"""
Remove the indirect key /home.
"""
delkey_kw = {'automountmapname': self.parentmap, 'automountkey': self.keyname}
delkey_kw = {'cn': self.locname, 'automountmapname': self.parentmap, 'automountkey': self.keyname}
res = api.Command['automountkey_del'](**delkey_kw)
assert res == True
@ -223,12 +241,27 @@ class test_automount_indirect(XMLRPC_test):
"""
Remove the indirect map for auto.home.
"""
res = api.Command['automountmap_del'](self.mapname)
res = api.Command['automountmap_del'](self.locname, self.mapname)
assert res == True
# Verify that it is gone
try:
api.Command['automountmap_show'](self.mapname)
api.Command['automountmap_show'](self.locname, self.mapname)
except errors.NotFound:
pass
else:
assert False
def test_5_automountlocation_del(self):
"""
Remove the location.
"""
res = api.Command['automountlocation_del'](self.locname)
assert res == True
# Verity that it is gone
try:
api.Command['automountlocation_show'](self.locname)
except errors.NotFound:
pass
else:
@ -239,25 +272,35 @@ class test_automount_indirect_no_parent(XMLRPC_test):
"""
Test the `automount` plugin Indirect map function.
"""
locname = u'testlocation'
mapname = u'auto.home'
keyname = u'/home'
parentmap = u'auto.master'
description = u'Home directories'
map_kw = {'key': keyname, 'description': description}
map_kw = {'key': keyname, 'description': description, 'raw': True}
def test_0_automountlocation_add(self):
"""
Test adding a location.
"""
(dn, res) = api.Command['automountlocation_add'](self.locname, raw=True)
assert res
assert_attr_equal(res, 'cn', self.locname)
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)
(dn, res) = api.Command['automountmap_add_indirect'](self.locname, self.mapname, **self.map_kw)
assert res
assert_attr_equal(res, 'automountinformation', self.mapname)
assert_attr_equal(res, 'automountmapname', 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}
showkey_kw = {'cn': self.locname, 'automountmapname': self.parentmap, 'automountkey': self.keyname, 'raw': True}
(dn, res) = api.Command['automountkey_show'](**showkey_kw)
assert res
assert_attr_equal(res, 'automountkey', self.keyname)
@ -266,7 +309,7 @@ class test_automount_indirect_no_parent(XMLRPC_test):
"""
Remove the indirect key /home.
"""
delkey_kw={'automountmapname': self.parentmap, 'automountkey': self.keyname}
delkey_kw={'cn': self.locname, 'automountmapname': self.parentmap, 'automountkey': self.keyname}
res = api.Command['automountkey_del'](**delkey_kw)
assert res == True
@ -282,12 +325,27 @@ class test_automount_indirect_no_parent(XMLRPC_test):
"""
Remove the indirect map for auto.home.
"""
res = api.Command['automountmap_del'](self.mapname)
res = api.Command['automountmap_del'](self.locname, self.mapname)
assert res == True
# Verify that it is gone
try:
api.Command['automountmap_show'](self.mapname)
api.Command['automountmap_show'](self.locname, self.mapname)
except errors.NotFound:
pass
else:
assert False
def test_5_automountlocation_del(self):
"""
Remove the location.
"""
res = api.Command['automountlocation_del'](self.locname)
assert res == True
# Verity that it is gone
try:
api.Command['automountlocation_show'](self.locname)
except errors.NotFound:
pass
else:

View File

@ -35,7 +35,7 @@ class test_group(XMLRPC_test):
cn2 = u'testgroup2'
cnposix = u'posixgroup'
description = u'This is a test'
kw = {'description': description, 'cn': cn}
kw = {'description': description, 'cn': cn, 'raw': True}
def test_1_group_add(self):
"""
@ -70,26 +70,28 @@ class test_group(XMLRPC_test):
"""
Test the `xmlrpc.group_add_member` method.
"""
kw = {}
kw['groups'] = self.cn2
kw = {'raw': True}
kw['group'] = self.cn2
(total, failed, res) = api.Command['group_add_member'](self.cn, **kw)
assert total == 1
assert total == 1, '%r %r %r' % (total, failed, res)
def test_4_group_add_member(self):
"""
Test the `xmlrpc.group_add_member` with a non-existent member
"""
kw = {}
kw['groups'] = u'notfound'
kw = {'raw': True}
kw['group'] = u'notfound'
(total, failed, res) = api.Command['group_add_member'](self.cn, **kw)
assert total == 0
assert 'notfound' in failed
assert 'member' in failed
assert 'group' in failed['member']
assert 'notfound' in failed['member']['group']
def test_5_group_show(self):
"""
Test the `xmlrpc.group_show` method.
"""
(dn, res) = api.Command['group_show'](self.cn)
(dn, res) = api.Command['group_show'](self.cn, raw=True)
assert res
assert_attr_equal(res, 'description', self.description)
assert_attr_equal(res, 'cn', self.cn)
@ -98,7 +100,7 @@ class test_group(XMLRPC_test):
"""
Test the `xmlrpc.group_find` method.
"""
(res, truncated) = api.Command['group_find'](cn=self.cn)
(res, truncated) = api.Command['group_find'](cn=self.cn, raw=True)
assert res
assert_attr_equal(res[0][1], 'description', self.description)
assert_attr_equal(res[0][1], 'cn', self.cn)
@ -126,12 +128,14 @@ class test_group(XMLRPC_test):
modkw = self.kw
modkw['cn'] = self.cn
modkw['posix'] = True
modkw['all'] = True
modkw['raw'] = 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)
(dn, res) = api.Command['group_show'](self.cn, all=True, raw=True)
assert res
assert_attr_equal(res, 'description', 'New description')
assert_attr_equal(res, 'cn', self.cn)
@ -141,8 +145,8 @@ class test_group(XMLRPC_test):
"""
Test the `xmlrpc.group_remove_member` method.
"""
kw = {}
kw['groups'] = self.cn2
kw = {'raw': True}
kw['group'] = self.cn2
(total, failed, res) = api.Command['group_remove_member'](self.cn, **kw)
assert res
assert total == 1
@ -151,12 +155,14 @@ class test_group(XMLRPC_test):
"""
Test the `xmlrpc.group_remove_member` method with non-member
"""
kw = {}
kw['groups'] = u'notfound'
kw = {'raw': True}
kw['group'] = u'notfound'
# an error isn't thrown, the list of failed members is returned
(total, failed, res) = api.Command['group_remove_member'](self.cn, **kw)
assert total == 0
assert 'notfound' in failed
assert 'member' in failed
assert 'group' in failed['member']
assert 'notfound' in failed['member']['group']
def test_b_group_del(self):
"""

View File

@ -34,7 +34,7 @@ class test_host(XMLRPC_test):
fqdn = u'ipatesthost.%s' % api.env.domain
description = u'Test host'
localityname = u'Undisclosed location'
kw = {'fqdn': fqdn, 'description': description, 'localityname': localityname}
kw = {'fqdn': fqdn, 'description': description, 'localityname': localityname, 'raw': True}
def test_1_host_add(self):
"""
@ -51,8 +51,10 @@ class test_host(XMLRPC_test):
"""
Test the `xmlrpc.host_show` method with all attributes.
"""
kw = {'fqdn': self.fqdn, 'all': True}
kw = {'fqdn': self.fqdn, 'all': True, 'raw': True}
(dn, res) = api.Command['host_show'](**kw)
print res
print '%r' % res
assert res
assert_attr_equal(res, 'description', self.description)
assert_attr_equal(res, 'fqdn', self.fqdn)
@ -62,7 +64,7 @@ class test_host(XMLRPC_test):
"""
Test the `xmlrpc.host_show` method with default attributes.
"""
kw = {'fqdn': self.fqdn}
kw = {'fqdn': self.fqdn, 'raw': True}
(dn, res) = api.Command['host_show'](**kw)
assert res
assert_attr_equal(res, 'description', self.description)
@ -73,7 +75,7 @@ class test_host(XMLRPC_test):
"""
Test the `xmlrpc.host_find` method with all attributes.
"""
kw = {'fqdn': self.fqdn, 'all': True}
kw = {'fqdn': self.fqdn, 'all': True, 'raw': True}
(res, truncated) = api.Command['host_find'](**kw)
assert res
assert_attr_equal(res[0][1], 'description', self.description)
@ -84,7 +86,7 @@ class test_host(XMLRPC_test):
"""
Test the `xmlrpc.host_find` method with default attributes.
"""
(res, truncated) = api.Command['host_find'](self.fqdn)
(res, truncated) = api.Command['host_find'](self.fqdn, raw=True)
assert res
assert_attr_equal(res[0][1], 'description', self.description)
assert_attr_equal(res[0][1], 'fqdn', self.fqdn)
@ -95,13 +97,13 @@ class test_host(XMLRPC_test):
Test the `xmlrpc.host_mod` method.
"""
newdesc = u'Updated host'
modkw = {'fqdn': self.fqdn, 'description': newdesc}
modkw = {'fqdn': self.fqdn, 'description': newdesc, 'raw': True}
(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)
(dn, res) = api.Command['host_show'](self.fqdn, raw=True)
assert res
assert_attr_equal(res, 'description', newdesc)
assert_attr_equal(res, 'fqdn', self.fqdn)

View File

@ -33,7 +33,7 @@ class test_hostgroup(XMLRPC_test):
"""
cn = u'testgroup'
description = u'Test host group'
kw = {'cn': cn, 'description': description}
kw = {'cn': cn, 'description': description, 'raw': True}
host_fqdn = u'ipatesthost.%s' % api.env.domain
host_description = u'Test host'
@ -53,7 +53,7 @@ class test_hostgroup(XMLRPC_test):
"""
Add a host to test add/remove member.
"""
kw = {'fqdn': self.host_fqdn, 'description': self.host_description, 'localityname': self.host_localityname}
kw = {'fqdn': self.host_fqdn, 'description': self.host_description, 'localityname': self.host_localityname, 'raw': True}
(dn, res) = api.Command['host_add'](**kw)
assert res
assert_attr_equal(res, 'description', self.host_description)
@ -63,16 +63,16 @@ class test_hostgroup(XMLRPC_test):
"""
Test the `xmlrpc.hostgroup_add_member` method.
"""
kw = {}
kw['hosts'] = self.host_fqdn
kw = {'raw': True}
kw['host'] = self.host_fqdn
(total, failed, res) = api.Command['hostgroup_add_member'](self.cn, **kw)
assert res[1].get('member', []) != []
assert res[1].get('member', []) != [], '%r %r %r' % (total, failed, res)
def test_4_hostgroup_show(self):
"""
Test the `xmlrpc.hostgroup_show` method.
"""
(dn, res) = api.Command['hostgroup_show'](self.cn)
(dn, res) = api.Command['hostgroup_show'](self.cn, raw=True)
assert res
assert_attr_equal(res, 'description', self.description)
assert_attr_equal(res, 'cn', self.cn)
@ -81,8 +81,10 @@ class test_hostgroup(XMLRPC_test):
"""
Test the `xmlrpc.hostgroup_find` method.
"""
(res, truncated) = api.Command['hostgroup_find'](cn=self.cn)
assert res
(res, truncated) = api.Command['hostgroup_find'](cn=self.cn, raw=True)
print res
print '%r' % res
assert res, '%r' % res
assert_attr_equal(res[0][1], 'description', self.description)
assert_attr_equal(res[0][1], 'cn', self.cn)
@ -91,13 +93,13 @@ class test_hostgroup(XMLRPC_test):
Test the `xmlrpc.hostgroup_mod` method.
"""
newdesc = u'Updated host group'
modkw = {'cn': self.cn, 'description': newdesc}
modkw = {'cn': self.cn, 'description': newdesc, 'raw': True}
(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)
(dn, res) = api.Command['hostgroup_show'](self.cn, raw=True)
assert res
assert_attr_equal(res, 'description', newdesc)
assert_attr_equal(res, 'cn', self.cn)
@ -106,8 +108,8 @@ class test_hostgroup(XMLRPC_test):
"""
Test the `xmlrpc.hostgroup_remove_member` method.
"""
kw = {}
kw['hosts'] = self.host_fqdn
kw = {'raw': True}
kw['host'] = self.host_fqdn
(total, failed, res) = api.Command['hostgroup_remove_member'](self.cn, **kw)
assert res
assert res[1].get('member', []) == []

View File

@ -33,22 +33,22 @@ class test_netgroup(XMLRPC_test):
"""
ng_cn = u'ng1'
ng_description = u'Netgroup'
ng_kw = {'cn': ng_cn, 'description': ng_description, 'nisdomainname': u'example.com'}
ng_kw = {'cn': ng_cn, 'description': ng_description, 'nisdomainname': u'example.com', 'raw': True}
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}
host_kw = {'fqdn': host_fqdn, 'description': host_description, 'localityname': host_localityname, 'raw': True}
hg_cn = u'ng1'
hg_description = u'Netgroup'
hg_kw = {'cn': hg_cn, 'description': hg_description}
hg_kw = {'cn': hg_cn, 'description': hg_description, 'raw': True}
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}
user_kw = {'givenname': user_givenname,'sn': user_sn,'uid': user_uid,'homedirectory': user_home, 'raw': True}
group_cn = u'testgroup'
group_description = u'This is a test'
@ -95,26 +95,26 @@ class test_netgroup(XMLRPC_test):
"""
Test the `xmlrpc.netgroup_add_member` method.
"""
kw = {}
kw['hosts'] = self.host_fqdn
kw = {'raw': True}
kw['host'] = self.host_fqdn
(total, failed, 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
kw = {'raw': True}
kw['hostgroup'] = self.hg_cn
(total, failed, 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
kw = {'raw': True}
kw['user'] = self.user_uid
(total, failed, 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
kw = {'raw': True}
kw['group'] = self.group_cn
(total, failed, res) = api.Command['netgroup_add_member'](self.ng_cn, **kw)
assert total == 1
assert_is_member(res[1], 'cn=%s' % self.group_cn)
@ -123,48 +123,57 @@ class test_netgroup(XMLRPC_test):
"""
Test the `xmlrpc.netgroup_add_member` method again to test dupes.
"""
kw = {}
kw['hosts'] = self.host_fqdn
kw = {'raw': True}
kw['host'] = self.host_fqdn
(total, failed, res) = api.Command['netgroup_add_member'](self.ng_cn, **kw)
assert total == 0
assert self.host_fqdn in failed
assert 'member' in failed
assert 'host' in failed['member']
assert self.host_fqdn in failed['member']['host']
kw = {}
kw['hostgroups'] = self.hg_cn
kw = {'raw': True}
kw['hostgroup'] = self.hg_cn
(total, failed, res) = api.Command['netgroup_add_member'](self.ng_cn, **kw)
assert total == 0
assert self.hg_cn in failed
assert 'member' in failed
assert 'hostgroup' in failed['member']
assert self.hg_cn in failed['member']['hostgroup']
kw = {}
kw['users'] = self.user_uid
kw = {'raw': True}
kw['user'] = self.user_uid
(total, failed, res) = api.Command['netgroup_add_member'](self.ng_cn, **kw)
assert total == 0
assert self.user_uid in failed
assert 'member' in failed
assert 'user' in failed['member']
assert self.user_uid in failed['member']['user']
kw = {}
kw['groups'] = self.group_cn
kw = {'raw': True}
kw['group'] = self.group_cn
(total, failed, res) = api.Command['netgroup_add_member'](self.ng_cn, **kw)
assert total == 0
assert self.group_cn in failed
assert 'member' in failed
assert 'group' in failed['member']
assert self.group_cn in failed['member']['group']
def test_5_netgroup_add_member(self):
"""
Test adding external hosts.
"""
kw = {}
kw['hosts'] = u'nosuchhost'
kw = {'raw': True}
kw['host'] = u'nosuchhost'
(total, failed, res) = api.Command['netgroup_add_member'](self.ng_cn, **kw)
assert total == 1
assert total == 1, '%r %r %r' % (total, failed, res)
(dn, res) = api.Command['netgroup_show'](self.ng_cn)
(dn, res) = api.Command['netgroup_show'](self.ng_cn, all=True, raw=True)
assert res
print 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, all=True)
(dn, res) = api.Command['netgroup_show'](self.ng_cn, all=True, raw=True)
assert res
assert_attr_equal(res, 'description', self.ng_description)
assert_attr_equal(res, 'cn', self.ng_cn)
@ -178,7 +187,7 @@ class test_netgroup(XMLRPC_test):
"""
Test the `xmlrpc.hostgroup_find` method.
"""
(res, truncated) = api.Command.netgroup_find(self.ng_cn)
(res, truncated) = api.Command.netgroup_find(self.ng_cn, raw=True)
assert res
assert_attr_equal(res[0][1], 'description', self.ng_description)
assert_attr_equal(res[0][1], 'cn', self.ng_cn)
@ -188,13 +197,13 @@ class test_netgroup(XMLRPC_test):
Test the `xmlrpc.hostgroup_mod` method.
"""
newdesc = u'Updated host group'
modkw = {'cn': self.ng_cn, 'description': newdesc}
modkw = {'cn': self.ng_cn, 'description': newdesc, 'raw': True}
(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)
(dn, res) = api.Command['netgroup_show'](self.ng_cn, raw=True)
assert res
assert_attr_equal(res, 'description', newdesc)
assert_attr_equal(res, 'cn', self.ng_cn)
@ -203,23 +212,23 @@ class test_netgroup(XMLRPC_test):
"""
Test the `xmlrpc.hostgroup_remove_member` method.
"""
kw = {}
kw['hosts'] = self.host_fqdn
kw = {'raw': True}
kw['host'] = self.host_fqdn
(total, failed, res) = api.Command['netgroup_remove_member'](self.ng_cn, **kw)
assert total == 1
kw = {}
kw['hostgroups'] = self.hg_cn
kw = {'raw': True}
kw['hostgroup'] = self.hg_cn
(total, failed, res) = api.Command['netgroup_remove_member'](self.ng_cn, **kw)
assert total == 1
kw = {}
kw['users'] = self.user_uid
kw = {'raw': True}
kw['user'] = self.user_uid
(total, failed, res) = api.Command['netgroup_remove_member'](self.ng_cn, **kw)
assert total == 1
kw = {}
kw['groups'] = self.group_cn
kw = {'raw': True}
kw['group'] = self.group_cn
(total, failed, res) = api.Command['netgroup_remove_member'](self.ng_cn, **kw)
assert total == 1
@ -227,30 +236,38 @@ class test_netgroup(XMLRPC_test):
"""
Test the `xmlrpc.netgroup_remove_member` method again to test not found.
"""
kw = {}
kw['hosts'] = self.host_fqdn
kw = {'raw': True}
kw['host'] = self.host_fqdn
(total, failed, res) = api.Command['netgroup_remove_member'](self.ng_cn, **kw)
assert total == 0
assert self.host_fqdn in failed
assert 'member' in failed
assert 'host' in failed['member']
assert self.host_fqdn in failed['member']['host']
kw = {}
kw['hostgroups'] = self.hg_cn
kw = {'raw': True}
kw['hostgroup'] = self.hg_cn
(total, failed, res) = api.Command['netgroup_remove_member'](self.ng_cn, **kw)
assert total == 0
assert self.hg_cn in failed
assert 'member' in failed
assert 'hostgroup' in failed['member']
assert self.hg_cn in failed['member']['hostgroup']
kw = {}
kw['users'] = self.user_uid
kw = {'raw': True}
kw['user'] = self.user_uid
(dn, res) = api.Command['netgroup_show'](self.ng_cn, all=True)
(total, failed, res) = api.Command['netgroup_remove_member'](self.ng_cn, **kw)
assert total == 0
assert self.user_uid in failed
assert 'member' in failed
assert 'user' in failed['member']
assert self.user_uid in failed['member']['user']
kw = {}
kw['groups'] = self.group_cn
kw = {'raw': True}
kw['group'] = self.group_cn
(total, failed, res) = api.Command['netgroup_remove_member'](self.ng_cn, **kw)
assert total == 0
assert self.group_cn in failed
assert 'member' in failed
assert 'group' in failed['member']
assert self.group_cn in failed['member']['group']
def test_b_netgroup_del(self):
"""

View File

@ -33,7 +33,7 @@ class test_rolegroup(XMLRPC_test):
"""
cn = u'testgroup'
description = u'Test role group'
kw = {'cn': cn, 'description': description}
kw = {'cn': cn, 'description': description, 'raw': True}
rolegroup_cn = u'ipatestgroup'
rolegroup_description = u'Test group for rolegroups'
@ -52,7 +52,7 @@ class test_rolegroup(XMLRPC_test):
"""
Add a group to test add/remove member.
"""
kw = {'cn': self.rolegroup_cn, 'description': self.rolegroup_description}
kw = {'cn': self.rolegroup_cn, 'description': self.rolegroup_description, 'raw': True}
(dn, res) = api.Command['group_add'](**kw)
assert res
assert_attr_equal(res, 'description', self.rolegroup_description)
@ -63,7 +63,7 @@ class test_rolegroup(XMLRPC_test):
Test the `xmlrpc.rolegroup_add_member` method.
"""
kw = {}
kw['groups'] = self.rolegroup_cn
kw['group'] = self.rolegroup_cn
(total, failed, res) = api.Command['rolegroup_add_member'](self.cn, **kw)
assert total == 1
@ -71,7 +71,7 @@ class test_rolegroup(XMLRPC_test):
"""
Test the `xmlrpc.rolegroup_show` method.
"""
(dn, res) = api.Command['rolegroup_show'](self.cn)
(dn, res) = api.Command['rolegroup_show'](self.cn, all=True, raw=True)
assert res
assert_attr_equal(res, 'description', self.description)
assert_attr_equal(res, 'cn', self.cn)
@ -81,7 +81,7 @@ class test_rolegroup(XMLRPC_test):
"""
Test the `xmlrpc.rolegroup_find` method.
"""
(res, truncated) = api.Command['rolegroup_find'](self.cn)
(res, truncated) = api.Command['rolegroup_find'](self.cn, all=True, raw=True)
assert res
assert_attr_equal(res[0][1], 'description', self.description)
assert_attr_equal(res[0][1], 'cn', self.cn)
@ -92,13 +92,13 @@ class test_rolegroup(XMLRPC_test):
Test the `xmlrpc.rolegroup_mod` method.
"""
newdesc = u'Updated role group'
modkw = {'cn': self.cn, 'description': newdesc}
modkw = {'cn': self.cn, 'description': newdesc, 'raw': True}
(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)
(dn, res) = api.Command['rolegroup_show'](self.cn, raw=True)
assert res
assert_attr_equal(res, 'description', newdesc)
assert_attr_equal(res, 'cn', self.cn)
@ -108,7 +108,7 @@ class test_rolegroup(XMLRPC_test):
Test the `xmlrpc.rolegroup_remove_member` method.
"""
kw = {}
kw['groups'] = self.rolegroup_cn
kw['group'] = self.rolegroup_cn
(total, failed, res) = api.Command['rolegroup_remove_member'](self.cn, **kw)
assert total == 1

View File

@ -33,7 +33,7 @@ class test_taskgroup(XMLRPC_test):
"""
cn = u'testgroup'
description = u'Test task group'
kw = {'cn': cn, 'description': description}
kw = {'cn': cn, 'description': description, 'raw': True}
taskgroup_cn = u'ipatestgroup'
taskgroup_description = u'Test group for taskgroups'
@ -55,7 +55,7 @@ class test_taskgroup(XMLRPC_test):
"""
Add a rolegroup to test add/remove member.
"""
kw={'cn': self.rolegroup_cn, 'description': self.rolegroup_description}
kw={'cn': self.rolegroup_cn, 'description': self.rolegroup_description, 'raw': True}
(dn, res) = api.Command['rolegroup_add'](**kw)
assert res
assert_attr_equal(res, 'description', self.rolegroup_description)
@ -65,7 +65,7 @@ class test_taskgroup(XMLRPC_test):
"""
Add a group to test add/remove member.
"""
kw = {'cn': self.taskgroup_cn, 'description': self.taskgroup_description}
kw = {'cn': self.taskgroup_cn, 'description': self.taskgroup_description, 'raw': True}
(dn, res) = api.Command['group_add'](**kw)
assert res
assert_attr_equal(res, 'description', self.taskgroup_description)
@ -76,8 +76,8 @@ class test_taskgroup(XMLRPC_test):
Test the `xmlrpc.taskgroup_add_member` method.
"""
kw = {}
kw['groups'] = self.taskgroup_cn
kw['rolegroups'] = self.rolegroup_cn
kw['group'] = self.taskgroup_cn
kw['rolegroup'] = self.rolegroup_cn
(total, failed, res) = api.Command['taskgroup_add_member'](self.cn, **kw)
assert total == 2
@ -85,7 +85,7 @@ class test_taskgroup(XMLRPC_test):
"""
Test the `xmlrpc.taskgroup_show` method.
"""
(dn, res) = api.Command['taskgroup_show'](self.cn, all=True)
(dn, res) = api.Command['taskgroup_show'](self.cn, all=True, raw=True)
assert res
assert_attr_equal(res, 'description', self.description)
assert_attr_equal(res, 'cn', self.cn)
@ -96,7 +96,7 @@ class test_taskgroup(XMLRPC_test):
"""
Test the `xmlrpc.taskgroup_find` method.
"""
(res, truncated) = api.Command['taskgroup_find'](self.cn)
(res, truncated) = api.Command['taskgroup_find'](self.cn, all=True, raw=True)
assert res
assert_attr_equal(res[0][1], 'description', self.description)
assert_attr_equal(res[0][1], 'cn', self.cn)
@ -108,13 +108,13 @@ class test_taskgroup(XMLRPC_test):
Test the `xmlrpc.taskgroup_mod` method.
"""
newdesc = u'Updated task group'
modkw = {'cn': self.cn, 'description': newdesc}
modkw = {'cn': self.cn, 'description': newdesc, 'raw': True}
(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)
(dn, res) = api.Command['taskgroup_show'](self.cn, raw=True)
assert res
assert_attr_equal(res, 'description', newdesc)
assert_attr_equal(res, 'cn', self.cn)
@ -124,7 +124,7 @@ class test_taskgroup(XMLRPC_test):
Test the `xmlrpc.taskgroup_remove_member` method.
"""
kw = {}
kw['groups'] = self.taskgroup_cn
kw['group'] = self.taskgroup_cn
(total, failed, res) = api.Command['taskgroup_remove_member'](self.cn, **kw)
assert total == 1