Fix unicode failures in Env tests and dn failures in XML-RPC tests

This commit is contained in:
Rob Crittenden 2010-02-22 14:29:26 -05:00
parent 0700f4d7ca
commit 766757e4d4
10 changed files with 55 additions and 54 deletions

View File

@ -754,7 +754,7 @@ For example:
>>> api.register(motd)
>>> api.finalize()
>>> api.Command.motd()
{'result': 'Hello, world!'}
{'result': u'Hello, world!'}
Also see the `plugable.API.bootstrap_with_global_options()` method.

View File

@ -54,17 +54,17 @@ class Env(object):
>>> env = Env()
>>> env.attr = 'I was set as an attribute.'
>>> env.attr
'I was set as an attribute.'
u'I was set as an attribute.'
>>> env['attr'] # Also retrieve as a dictionary item
'I was set as an attribute.'
u'I was set as an attribute.'
Or you can set a variable as a dictionary item:
>>> env['item'] = 'I was set as a dictionary item.'
>>> env['item']
'I was set as a dictionary item.'
u'I was set as a dictionary item.'
>>> env.item # Also retrieve as an attribute
'I was set as a dictionary item.'
u'I was set as a dictionary item.'
The variable names must be valid lower-case Python identifiers that neither
start nor end with an underscore. If your variable name doesn't meet these
@ -101,7 +101,7 @@ class Env(object):
>>> env.not_false = 'false' # Not equal to repr(False)!
>>> env.not_false
'false'
u'false'
If an ``str`` value looks like an integer, it's automatically converted to
the ``int`` type. Likewise, if an ``str`` value looks like a floating-point
@ -119,7 +119,7 @@ class Env(object):
>>> env.message = ' Hello! ' # Surrounded by double spaces
>>> env.message
'Hello!'
u'Hello!'
>>> env.number = ' 42 ' # Still converted to an int
>>> env.number
42
@ -140,7 +140,7 @@ class Env(object):
>>> env.date = 'Second'
Traceback (most recent call last):
...
AttributeError: cannot override Env.date value 'First' with 'Second'
AttributeError: cannot override Env.date value u'First' with 'Second'
An `Env` instance can be *locked*, after which no further variables can be
set. Trying to set variables on a locked `Env` instance will also raise
@ -400,7 +400,7 @@ class Env(object):
>>> env = Env()
>>> env.home = '/people/joe'
>>> env._join('home', 'Music', 'favourites')
'/people/joe/Music/favourites'
u'/people/joe/Music/favourites'
"""
if key in self and self[key] is not None:
return path.join(self[key], *parts)

View File

@ -301,7 +301,7 @@ class HasParam(Plugin):
>>> bar = Env(context='bar')
>>> another = Env(context='another')
>>> (foo.context, bar.context, another.context)
('foo', 'bar', 'another')
(u'foo', u'bar', u'another')
>>> list(eg._filter_param_by_context('args', foo))
[Str('foo_only', include=['foo']), Str('not_bar', exclude=['bar']), Str('both')]
>>> list(eg._filter_param_by_context('args', bar))

View File

@ -39,8 +39,8 @@ from ipalib import config, constants, base
# raw: the value being set (possibly a string repr)
# value: the expected value after the lightweight conversion
good_vars = (
('a_string', 'Hello world!', 'Hello world!'),
('trailing_whitespace', ' value ', 'value'),
('a_string', u'Hello world!', u'Hello world!'),
('trailing_whitespace', u' value ', u'value'),
('an_int', 42, 42),
('int_repr', ' 42 ', 42),
('a_float', 3.14, 3.14),
@ -54,16 +54,16 @@ good_vars = (
('empty', '', None),
# These verify that the implied conversion is case-sensitive:
('not_true', ' true ', 'true'),
('not_false', ' false ', 'false'),
('not_none', ' none ', 'none'),
('not_true', u' true ', u'true'),
('not_false', u' false ', u'false'),
('not_none', u' none ', u'none'),
)
bad_names = (
('CamelCase', 'value'),
('_leading_underscore', 'value'),
('trailing_underscore_', 'value'),
('CamelCase', u'value'),
('_leading_underscore', u'value'),
('trailing_underscore_', u'value'),
)
@ -253,7 +253,7 @@ class test_Env(ClassChecker):
Test the `ipalib.config.Env.__getitem__` method.
"""
o = self.cls()
value = 'some value'
value = u'some value'
o.key = value
assert o.key is value
assert o['key'] is value
@ -300,7 +300,7 @@ class test_Env(ClassChecker):
assert len(o) == 0
for i in xrange(1, 11):
key = 'key%d' % i
value = 'value %d' % i
value = u'value %d' % i
o[key] = value
assert o[key] is value
assert len(o) == i
@ -321,16 +321,16 @@ class test_Env(ClassChecker):
Test the `ipalib.config.Env._merge` method.
"""
group1 = (
('key1', 'value 1'),
('key2', 'value 2'),
('key3', 'value 3'),
('key4', 'value 4'),
('key1', u'value 1'),
('key2', u'value 2'),
('key3', u'value 3'),
('key4', u'value 4'),
)
group2 = (
('key0', 'Value 0'),
('key2', 'Value 2'),
('key4', 'Value 4'),
('key5', 'Value 5'),
('key0', u'Value 0'),
('key2', u'Value 2'),
('key4', u'Value 4'),
('key5', u'Value 5'),
)
o = self.cls()
assert o._merge(**dict(group1)) == (4, 4)
@ -599,7 +599,7 @@ class test_Env(ClassChecker):
# Check that **lastchance works
(o, home) = self.finalize_core(None)
key = 'just_one_more_key'
value = 'with one more value'
value = u'with one more value'
lastchance = {key: value}
assert key not in o
assert o._isdone('_finalize') is False

View File

@ -176,7 +176,7 @@ class test_group(Declarative):
truncated=False,
result=[
dict(
#dn=u'cn=%s,cn=groups,cn=accounts,%s' % (group1, api.env.basedn),
dn=u'cn=%s,cn=groups,cn=accounts,%s' % (group1, api.env.basedn),
cn=[group1],
description=[u'New desc 1'],
gidnumber=[fuzzy_digits],
@ -293,7 +293,7 @@ class test_group(Declarative):
truncated=False,
result=[
dict(
#dn=u'cn=%s,cn=groups,cn=accounts,%s' % (group2, api.env.basedn),
dn=u'cn=%s,cn=groups,cn=accounts,%s' % (group2, api.env.basedn),
cn=[group2],
description=[u'New desc 2'],
),
@ -312,32 +312,32 @@ class test_group(Declarative):
truncated=False,
result=[
{
#'dn': u'cn=admins,cn=groups,cn=accounts,%s' % api.env.basedn,
'dn': u'cn=admins,cn=groups,cn=accounts,%s' % api.env.basedn,
'member_user': [u'admin'],
'gidnumber': [fuzzy_digits],
'cn': [u'admins'],
'description': [u'Account administrators group'],
},
{
#'dn': u'cn=ipausers,cn=groups,cn=accounts,%s' % api.env.basedn,
'dn': u'cn=ipausers,cn=groups,cn=accounts,%s' % api.env.basedn,
'gidnumber': [fuzzy_digits],
'cn': [u'ipausers'],
'description': [u'Default group for all users'],
},
{
#'dn': u'cn=editors,cn=groups,cn=accounts,%s' % api.env.basedn,
'dn': u'cn=editors,cn=groups,cn=accounts,%s' % api.env.basedn,
'gidnumber': [fuzzy_digits],
'cn': [u'editors'],
'description': [u'Limited admins who can edit other users'],
},
dict(
#dn=u'cn=%s,cn=groups,cn=accounts,%s' % (group1, api.env.basedn),
dn=u'cn=%s,cn=groups,cn=accounts,%s' % (group1, api.env.basedn),
cn=[group1],
description=[u'New desc 1'],
gidnumber=[fuzzy_digits],
),
dict(
#dn=u'cn=%s,cn=groups,cn=accounts,%s' % (group2, api.env.basedn),
dn=u'cn=%s,cn=groups,cn=accounts,%s' % (group2, api.env.basedn),
cn=[group2],
description=[u'New desc 2'],
),

View File

@ -148,7 +148,7 @@ class test_host(Declarative):
summary=u'1 host matched',
result=[
dict(
#dn=dn1,
dn=dn1,
fqdn=[fqdn1],
description=[u'Test host 1'],
l=[u'Undisclosed location 1'],
@ -168,6 +168,7 @@ class test_host(Declarative):
summary=u'1 host matched',
result=[
dict(
dn=dn1,
cn=[fqdn1],
fqdn=[fqdn1],
description=[u'Test host 1'],

View File

@ -165,7 +165,7 @@ class test_hostgroup(Declarative):
summary=u'1 hostgroup matched',
result=[
{
#'dn': dn1,
'dn': dn1,
'member_host': [u'testhost1.%s' % api.env.domain],
'cn': [hostgroup1],
'description': [u'Test hostgroup 1'],

View File

@ -184,7 +184,7 @@ class test_rolegroup(Declarative):
summary=u'1 rolegroup matched',
result=[
{
#'dn': rolegroup1_dn,
'dn': rolegroup1_dn,
'cn': [rolegroup1],
'description': [u'rolegroup desc 1'],
'member_group': [group1],
@ -203,7 +203,7 @@ class test_rolegroup(Declarative):
summary=u'1 rolegroup matched',
result=[
{
#'dn': rolegroup1_dn,
'dn': rolegroup1_dn,
'cn': [rolegroup1],
'description': [u'rolegroup desc 1'],
'member_group': [group1],
@ -240,7 +240,7 @@ class test_rolegroup(Declarative):
summary=u'1 rolegroup matched',
result=[
{
#'dn': rolegroup1_dn,
'dn': rolegroup1_dn,
'cn': [rolegroup1],
'description': [u'rolegroup desc 1'],
'member_group': [group1],
@ -259,13 +259,13 @@ class test_rolegroup(Declarative):
summary=u'2 rolegroups matched',
result=[
{
#'dn': rolegroup1_dn,
'dn': rolegroup1_dn,
'cn': [rolegroup1],
'description': [u'rolegroup desc 1'],
'member_group': [group1],
},
{
#'dn': rolegroup2_dn,
'dn': rolegroup2_dn,
'cn': [rolegroup2],
'description': [u'rolegroup desc 2'],
},
@ -396,7 +396,7 @@ class test_rolegroup(Declarative):
summary=u'1 rolegroup matched',
result=[
{
#'dn': rolegroup2_dn,
'dn': rolegroup2_dn,
'cn': [rolegroup2],
'description': [u'rolegroup desc 2'],
},

View File

@ -206,7 +206,7 @@ class test_taskgroup(Declarative):
summary=u'1 taskgroup matched',
result=[
{
#'dn': taskgroup1_dn,
'dn': taskgroup1_dn,
'cn': [taskgroup1],
'description': [u'Test desc 1'],
'member_rolegroup': [rolegroup1],
@ -226,7 +226,7 @@ class test_taskgroup(Declarative):
summary=u'1 taskgroup matched',
result=[
{
#'dn': taskgroup1_dn,
'dn': taskgroup1_dn,
'cn': [taskgroup1],
'description': [u'Test desc 1'],
'member_rolegroup': [rolegroup1],
@ -264,7 +264,7 @@ class test_taskgroup(Declarative):
summary=u'1 taskgroup matched',
result=[
{
#'dn': taskgroup1_dn,
'dn': taskgroup1_dn,
'cn': [taskgroup1],
'description': [u'Test desc 1'],
'member_rolegroup': [rolegroup1],
@ -284,14 +284,14 @@ class test_taskgroup(Declarative):
summary=u'2 taskgroups matched',
result=[
{
#'dn': taskgroup1_dn,
'dn': taskgroup1_dn,
'cn': [taskgroup1],
'description': [u'Test desc 1'],
'member_rolegroup': [rolegroup1],
'member_group': [group1],
},
{
#'dn': taskgroup2_dn,
'dn': taskgroup2_dn,
'cn': [taskgroup2],
'description': [u'Test desc 2'],
},
@ -401,7 +401,7 @@ class test_taskgroup(Declarative):
summary=u'1 taskgroup matched',
result=[
{
#'dn': taskgroup2_dn,
'dn': taskgroup2_dn,
'cn': [taskgroup2],
'description': [u'Test desc 2'],
},

View File

@ -123,7 +123,7 @@ class test_user(Declarative):
expected=dict(
result=[
{
#'dn': u'uid=user1,cn=users,cn=accounts,' + api.env.basedn,
'dn': u'uid=tuser1,cn=users,cn=accounts,' + api.env.basedn,
'cn': [u'Test User1'],
'gecos': [user1],
'givenname': [u'Test'],
@ -153,7 +153,7 @@ class test_user(Declarative):
expected=dict(
result=[
dict(
#dn=u'uid=tuser1,cn=users,cn=accounts,' + api.env.basedn,
dn=u'uid=tuser1,cn=users,cn=accounts,' + api.env.basedn,
givenname=[u'Test'],
homedirectory=[u'/home/tuser1'],
loginshell=[u'/bin/sh'],
@ -177,7 +177,7 @@ class test_user(Declarative):
expected=dict(
result=[
dict(
#dn=u'uid=admin,cn=users,cn=accounts,' + api.env.basedn,
dn=u'uid=admin,cn=users,cn=accounts,' + api.env.basedn,
homedirectory=[u'/home/admin'],
loginshell=[u'/bin/bash'],
sn=[u'Administrator'],
@ -185,7 +185,7 @@ class test_user(Declarative):
memberof_group=[u'admins'],
),
dict(
#dn=u'uid=tuser1,cn=users,cn=accounts,' + api.env.basedn,
dn=u'uid=tuser1,cn=users,cn=accounts,' + api.env.basedn,
givenname=[u'Test'],
homedirectory=[u'/home/tuser1'],
loginshell=[u'/bin/sh'],