Fixed some of the test_xmlrpc unit tests

This commit is contained in:
Jason Gerard DeRose 2009-01-28 23:21:17 -07:00 committed by Rob Crittenden
parent 5717c9d668
commit 0211c76cd0
9 changed files with 61 additions and 61 deletions

View File

@ -605,15 +605,15 @@ class NotFound(ExecutionError):
For example: For example:
>>> raise NotFound(msg='Entry not found') >>> raise NotFound()
Traceback (most recent call last): Traceback (most recent call last):
... ...
NotFound: Entry not found NotFound: entry not found
""" """
errno = 4001 errno = 4001
format = _('%(msg)s') format = _('entry not found')
class DuplicateEntry(ExecutionError): class DuplicateEntry(ExecutionError):
""" """

View File

@ -26,7 +26,7 @@ This wraps the python-ldap bindings.
import ldap as _ldap import ldap as _ldap
from ipalib import api from ipalib import api
from ipalib import errors from ipalib import errors2
from ipalib.crud import CrudBackend from ipalib.crud import CrudBackend
from ipaserver import servercore, ipaldap from ipaserver import servercore, ipaldap
import krbV import krbV

View File

@ -270,7 +270,7 @@ def search(base, filter, attributes, timelimit=1, sizelimit=3000):
results = context.ldap.conn.getListAsync(base, ldap.SCOPE_SUBTREE, results = context.ldap.conn.getListAsync(base, ldap.SCOPE_SUBTREE,
filter, attributes, 0, None, None, timelimit, sizelimit) filter, attributes, 0, None, None, timelimit, sizelimit)
except ldap.NO_SUCH_OBJECT: except ldap.NO_SUCH_OBJECT:
raise errors2.NotFound raise errors2.NotFound()
counter = results[0] counter = results[0]
entries = [counter] entries = [counter]
@ -317,7 +317,7 @@ def get_ipa_config():
config = get_sub_entry("cn=etc," + api.env.basedn, searchfilter) config = get_sub_entry("cn=etc," + api.env.basedn, searchfilter)
except ldap.NO_SUCH_OBJECT, e: except ldap.NO_SUCH_OBJECT, e:
# FIXME # FIXME
raise errors2.NotFound raise errors2.NotFound()
return config return config
@ -409,12 +409,12 @@ def add_member_to_group(member_dn, group_dn, memberattr='member'):
group = get_entry_by_dn(group_dn, None) group = get_entry_by_dn(group_dn, None)
if group is None: if group is None:
raise errors2.NotFound raise errors2.NotFound()
# check to make sure member_dn exists # check to make sure member_dn exists
member_entry = get_base_entry(member_dn, "(objectClass=*)", ['dn','objectclass']) member_entry = get_base_entry(member_dn, "(objectClass=*)", ['dn','objectclass'])
if not member_entry: if not member_entry:
raise errors2.NotFound raise errors2.NotFound()
# Add the new member to the group member attribute # Add the new member to the group member attribute
members = group.get(memberattr, []) members = group.get(memberattr, [])
@ -433,7 +433,7 @@ def remove_member_from_group(member_dn, group_dn, memberattr='member'):
group = get_entry_by_dn(group_dn, None) group = get_entry_by_dn(group_dn, None)
if group is None: if group is None:
raise errors2.NotFound raise errors2.NotFound()
""" """
if group.get('cn') == "admins": if group.get('cn') == "admins":
member = get_entry_by_dn(member_dn, ['dn','uid']) member = get_entry_by_dn(member_dn, ['dn','uid'])

View File

@ -24,16 +24,16 @@ Test the `ipalib/plugins/f_group` module.
import sys import sys
from xmlrpc_test import XMLRPC_test from xmlrpc_test import XMLRPC_test
from ipalib import api from ipalib import api
from ipalib import errors from ipalib import errors2
class test_Group(XMLRPC_test): class test_Group(XMLRPC_test):
""" """
Test the `f_group` plugin. Test the `f_group` plugin.
""" """
cn='testgroup' cn = u'testgroup'
cn2='testgroup2' cn2 = u'testgroup2'
description='This is a test' description = u'This is a test'
kw={'description':description,'cn':cn} kw={'description':description,'cn':cn}
def test_add(self): def test_add(self):
@ -109,7 +109,7 @@ class test_Group(XMLRPC_test):
""" """
modkw = self.kw modkw = self.kw
modkw['cn'] = self.cn modkw['cn'] = self.cn
modkw['description'] = 'New description' modkw['description'] = u'New description'
res = api.Command['group_mod'](**modkw) res = api.Command['group_mod'](**modkw)
assert res assert res
assert res.get('description','') == 'New description' assert res.get('description','') == 'New description'

View File

@ -31,9 +31,9 @@ class test_Host(XMLRPC_test):
""" """
Test the `f_host` plugin. Test the `f_host` plugin.
""" """
cn='ipaexample.%s' % api.env.domain cn = api.env.host.decode('UTF-8')
description='Test host' description = u'Test host'
localityname='Undisclosed location' localityname = u'Undisclosed location'
kw={'cn': cn, 'description': description, 'localityname': localityname} kw={'cn': cn, 'description': description, 'localityname': localityname}
def test_add(self): def test_add(self):
@ -41,10 +41,10 @@ class test_Host(XMLRPC_test):
Test the `xmlrpc.host_add` method. Test the `xmlrpc.host_add` method.
""" """
res = api.Command['host_add'](**self.kw) res = api.Command['host_add'](**self.kw)
assert res assert type(res) is dict
assert res.get('description','') == self.description assert res['description'] == self.description
assert res.get('cn','') == self.cn assert res['cn'] == self.cn
assert res.get('l','') == self.localityname assert res['l'] == self.localityname
def test_doshow_all(self): def test_doshow_all(self):
""" """
@ -95,7 +95,7 @@ class test_Host(XMLRPC_test):
""" """
Test the `xmlrpc.host_mod` method. Test the `xmlrpc.host_mod` method.
""" """
newdesc='Updated host' newdesc = u'Updated host'
modkw={'cn': self.cn, 'description': newdesc} modkw={'cn': self.cn, 'description': newdesc}
res = api.Command['host_mod'](**modkw) res = api.Command['host_mod'](**modkw)
assert res assert res

View File

@ -31,13 +31,13 @@ class test_Host(XMLRPC_test):
""" """
Test the `f_hostgroup` plugin. Test the `f_hostgroup` plugin.
""" """
cn='testgroup' cn=u'testgroup'
description='Test host group' description=u'Test host group'
kw={'cn': cn, 'description': description} kw={'cn': cn, 'description': description}
host_cn='ipaexample.%s' % api.env.domain host_cn = api.env.host.decode('UTF-8')
host_description='Test host' host_description = u'Test host'
host_localityname='Undisclosed location' host_localityname = u'Undisclosed location'
def test_add(self): def test_add(self):
""" """
@ -83,7 +83,7 @@ class test_Host(XMLRPC_test):
""" """
res = api.Command['hostgroup_find'](self.cn) res = api.Command['hostgroup_find'](self.cn)
assert res assert res
assert len(res) == 2 assert len(res) == 2, res
assert res[1].get('description','') == self.description assert res[1].get('description','') == self.description
assert res[1].get('cn','') == self.cn assert res[1].get('cn','') == self.cn
assert res[1].get('member','').startswith('cn=%s' % self.host_cn) assert res[1].get('member','').startswith('cn=%s' % self.host_cn)
@ -92,7 +92,7 @@ class test_Host(XMLRPC_test):
""" """
Test the `xmlrpc.hostgroup_mod` method. Test the `xmlrpc.hostgroup_mod` method.
""" """
newdesc='Updated host group' newdesc=u'Updated host group'
modkw={'cn': self.cn, 'description': newdesc} modkw={'cn': self.cn, 'description': newdesc}
res = api.Command['hostgroup_mod'](**modkw) res = api.Command['hostgroup_mod'](**modkw)
assert res assert res

View File

@ -24,7 +24,7 @@ Test the `ipalib/plugins/f_netgroup` module.
import sys import sys
from xmlrpc_test import XMLRPC_test from xmlrpc_test import XMLRPC_test
from ipalib import api from ipalib import api
from ipalib import errors from ipalib import errors2
def is_member_of(members, candidate): def is_member_of(members, candidate):
@ -41,27 +41,27 @@ class test_Netgroup(XMLRPC_test):
""" """
Test the `f_netgroup` plugin. Test the `f_netgroup` plugin.
""" """
ng_cn='ng1' ng_cn=u'ng1'
ng_description='Netgroup' ng_description=u'Netgroup'
ng_kw={'cn': ng_cn, 'description': ng_description} ng_kw={'cn': ng_cn, 'description': ng_description}
host_cn='ipaexample.%s' % api.env.domain host_cn = api.env.host.decode('UTF-8')
host_description='Test host' host_description=u'Test host'
host_localityname='Undisclosed location' host_localityname=u'Undisclosed location'
host_kw={'cn': host_cn, 'description': host_description, 'localityname': host_localityname} host_kw={'cn': host_cn, 'description': host_description, 'localityname': host_localityname}
hg_cn='ng1' hg_cn=u'ng1'
hg_description='Netgroup' hg_description=u'Netgroup'
hg_kw={'cn': hg_cn, 'description': hg_description} hg_kw={'cn': hg_cn, 'description': hg_description}
user_uid='jexample' user_uid=u'jexample'
user_givenname='Jim' user_givenname=u'Jim'
user_sn='Example' user_sn=u'Example'
user_home='/home/%s' % user_uid 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}
group_cn='testgroup' group_cn = u'testgroup'
group_description='This is a test' group_description = u'This is a test'
group_kw={'description':group_description,'cn':group_cn} group_kw={'description':group_description,'cn':group_cn}
def test_add(self): def test_add(self):
@ -87,7 +87,7 @@ class test_Netgroup(XMLRPC_test):
# Add a hostgroup # Add a hostgroup
res = api.Command['hostgroup_add'](**self.hg_kw) res = api.Command['hostgroup_add'](**self.hg_kw)
assert res assert res
assert res.get('description','') == self.hg_description assert res.get('description', '') == self.hg_description
assert res.get('cn','') == self.hg_cn assert res.get('cn','') == self.hg_cn
# Add a user # Add a user
@ -155,7 +155,7 @@ class test_Netgroup(XMLRPC_test):
Test adding external hosts Test adding external hosts
""" """
kw={} kw={}
kw['hosts'] = "nosuchhost" kw['hosts'] = u"nosuchhost"
res = api.Command['netgroup_add_member'](self.ng_cn, **kw) res = api.Command['netgroup_add_member'](self.ng_cn, **kw)
assert res == tuple() assert res == tuple()
res = api.Command['netgroup_show'](self.ng_cn) res = api.Command['netgroup_show'](self.ng_cn)
@ -179,9 +179,9 @@ class test_Netgroup(XMLRPC_test):
""" """
Test the `xmlrpc.hostgroup_find` method. Test the `xmlrpc.hostgroup_find` method.
""" """
res = api.Command['netgroup_find'](self.ng_cn) res = api.Command.netgroup_find(self.ng_cn)
assert res assert res
assert len(res) == 2 assert len(res) == 2, repr(res)
assert res[1].get('description','') == self.ng_description assert res[1].get('description','') == self.ng_description
assert res[1].get('cn','') == self.ng_cn assert res[1].get('cn','') == self.ng_cn
@ -189,7 +189,7 @@ class test_Netgroup(XMLRPC_test):
""" """
Test the `xmlrpc.hostgroup_mod` method. Test the `xmlrpc.hostgroup_mod` method.
""" """
newdesc='Updated host group' newdesc=u'Updated host group'
modkw={'cn': self.ng_cn, 'description': newdesc} modkw={'cn': self.ng_cn, 'description': newdesc}
res = api.Command['netgroup_mod'](**modkw) res = api.Command['netgroup_mod'](**modkw)
assert res assert res

View File

@ -24,15 +24,15 @@ Test the `ipalib/plugins/f_service` module.
import sys import sys
from xmlrpc_test import XMLRPC_test from xmlrpc_test import XMLRPC_test
from ipalib import api from ipalib import api
from ipalib import errors from ipalib import errors2
class test_Service(XMLRPC_test): class test_Service(XMLRPC_test):
""" """
Test the `f_service` plugin. Test the `f_service` plugin.
""" """
principal='HTTP/ipatest.%s@%s' % (api.env.domain, api.env.realm) principal=u'HTTP/ipatest.%s@%s' % (api.env.domain, api.env.realm)
hostprincipal='host/ipatest.%s@%s' % (api.env.domain, api.env.realm) hostprincipal=u'host/ipatest.%s@%s' % (api.env.domain, api.env.realm)
kw={'principal':principal} kw={'principal':principal}
def test_add(self): def test_add(self):
@ -60,7 +60,7 @@ class test_Service(XMLRPC_test):
""" """
Test adding a malformed principal ('foo'). Test adding a malformed principal ('foo').
""" """
kw={'principal':'foo'} kw={'principal': u'foo'}
try: try:
res = api.Command['service_add'](**kw) res = api.Command['service_add'](**kw)
except errors2.MalformedServicePrincipal: except errors2.MalformedServicePrincipal:
@ -72,7 +72,7 @@ class test_Service(XMLRPC_test):
""" """
Test adding a malformed principal ('HTTP/foo@FOO.NET'). Test adding a malformed principal ('HTTP/foo@FOO.NET').
""" """
kw={'principal':'HTTP/foo@FOO.NET'} kw={'principal': u'HTTP/foo@FOO.NET'}
try: try:
res = api.Command['service_add'](**kw) res = api.Command['service_add'](**kw)
except errors2.RealmMismatch: except errors2.RealmMismatch:

View File

@ -24,18 +24,18 @@ Test the `ipalib/plugins/f_user` module.
import sys import sys
from xmlrpc_test import XMLRPC_test from xmlrpc_test import XMLRPC_test
from ipalib import api from ipalib import api
from ipalib import errors from ipalib import errors2
class test_User(XMLRPC_test): class test_User(XMLRPC_test):
""" """
Test the `f_user` plugin. Test the `f_user` plugin.
""" """
uid='jexample' uid=u'jexample'
givenname='Jim' givenname=u'Jim'
sn='Example' sn=u'Example'
home='/home/%s' % uid home=u'/home/%s' % uid
principalname='%s@%s' % (uid, api.env.realm) principalname=u'%s@%s' % (uid, api.env.realm)
kw={'givenname':givenname,'sn':sn,'uid':uid,'homedirectory':home} kw={'givenname':givenname,'sn':sn,'uid':uid,'homedirectory':home}
def test_add(self): def test_add(self):
@ -117,7 +117,7 @@ class test_User(XMLRPC_test):
Test the `xmlrpc.user_mod` method. Test the `xmlrpc.user_mod` method.
""" """
modkw = self.kw modkw = self.kw
modkw['givenname'] = 'Finkle' modkw['givenname'] = u'Finkle'
res = api.Command['user_mod'](**modkw) res = api.Command['user_mod'](**modkw)
assert res assert res
assert res.get('givenname','') == 'Finkle' assert res.get('givenname','') == 'Finkle'
@ -126,7 +126,7 @@ class test_User(XMLRPC_test):
# Ok, double-check that it was changed # Ok, double-check that it was changed
res = api.Command['user_show'](self.uid) res = api.Command['user_show'](self.uid)
assert res assert res
assert res.get('givenname','') == 'Finkle' assert res.get('givenname','') == u'Finkle'
assert res.get('sn','') == self.sn assert res.get('sn','') == self.sn
assert res.get('uid','') == self.uid assert res.get('uid','') == self.uid