Imported Debian patch 4.0.5-6~numeezy
This commit is contained in:
committed by
Mario Fetka
parent
c44de33144
commit
10dfc9587b
@@ -21,18 +21,13 @@
|
||||
"""
|
||||
Test the `ipalib.aci` module.
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
from ipalib.aci import ACI
|
||||
|
||||
import pytest
|
||||
|
||||
pytestmark = pytest.mark.tier0
|
||||
|
||||
def check_aci_parsing(source, expected):
|
||||
a = ACI(source)
|
||||
print('ACI was: ', a)
|
||||
print('Expected:', expected)
|
||||
print 'ACI was: ', a
|
||||
print 'Expected:', expected
|
||||
assert str(ACI(source)) == expected
|
||||
|
||||
def test_aci_parsing_1():
|
||||
@@ -45,7 +40,7 @@ def test_aci_parsing_1_with_aci_keyword():
|
||||
|
||||
def test_aci_parsing_2():
|
||||
check_aci_parsing('(target="ldap:///uid=bjensen,dc=example,dc=com")(targetattr=*) (version 3.0;acl "aci1";allow (write) userdn="ldap:///self";)',
|
||||
'(target = "ldap:///uid=bjensen,dc=example,dc=com")(targetattr = "*")(version 3.0;acl "aci1";allow (write) userdn = "ldap:///self";)')
|
||||
'(targetattr = "*")(target = "ldap:///uid=bjensen,dc=example,dc=com")(version 3.0;acl "aci1";allow (write) userdn = "ldap:///self";)')
|
||||
|
||||
def test_aci_parsing_3():
|
||||
check_aci_parsing(' (targetattr = "givenName || sn || cn || displayName || title || initials || loginShell || gecos || homePhone || mobile || pager || facsimileTelephoneNumber || telephoneNumber || street || roomNumber || l || st || postalCode || manager || secretary || description || carLicense || labeledURI || inetUserHTTPURL || seeAlso || employeeType || businessCategory || ou")(version 3.0;acl "Self service";allow (write) userdn = "ldap:///self";)',
|
||||
@@ -57,11 +52,11 @@ def test_aci_parsing_4():
|
||||
|
||||
def test_aci_parsing_5():
|
||||
check_aci_parsing('(targetattr=member)(target="ldap:///cn=ipausers,cn=groups,cn=accounts,dc=example,dc=com")(version 3.0;acl "add_user_to_default_group";allow (write) groupdn="ldap:///cn=add_user_to_default_group,cn=taskgroups,dc=example,dc=com";)',
|
||||
'(target = "ldap:///cn=ipausers,cn=groups,cn=accounts,dc=example,dc=com")(targetattr = "member")(version 3.0;acl "add_user_to_default_group";allow (write) groupdn = "ldap:///cn=add_user_to_default_group,cn=taskgroups,dc=example,dc=com";)')
|
||||
'(targetattr = "member")(target = "ldap:///cn=ipausers,cn=groups,cn=accounts,dc=example,dc=com")(version 3.0;acl "add_user_to_default_group";allow (write) groupdn = "ldap:///cn=add_user_to_default_group,cn=taskgroups,dc=example,dc=com";)')
|
||||
|
||||
def test_aci_parsing_6():
|
||||
check_aci_parsing('(targetattr!=member)(targe="ldap:///cn=ipausers,cn=groups,cn=accounts,dc=example,dc=com")(version 3.0;acl "add_user_to_default_group";allow (write) groupdn="ldap:///cn=add_user_to_default_group,cn=taskgroups,dc=example,dc=com";)',
|
||||
'(targe = "ldap:///cn=ipausers,cn=groups,cn=accounts,dc=example,dc=com")(targetattr != "member")(version 3.0;acl "add_user_to_default_group";allow (write) groupdn = "ldap:///cn=add_user_to_default_group,cn=taskgroups,dc=example,dc=com";)')
|
||||
'(targetattr != "member")(targe = "ldap:///cn=ipausers,cn=groups,cn=accounts,dc=example,dc=com")(version 3.0;acl "add_user_to_default_group";allow (write) groupdn = "ldap:///cn=add_user_to_default_group,cn=taskgroups,dc=example,dc=com";)')
|
||||
|
||||
def test_aci_parsing_7():
|
||||
check_aci_parsing('(targetattr = "userPassword || krbPrincipalKey || sambaLMPassword || sambaNTPassword || passwordHistory")(version 3.0; acl "change_password"; allow (write) groupdn = "ldap:///cn=change_password,cn=taskgroups,dc=example,dc=com";)',
|
||||
@@ -81,7 +76,7 @@ def make_test_aci():
|
||||
|
||||
def test_aci_equality():
|
||||
a = make_test_aci()
|
||||
print(a)
|
||||
print a
|
||||
|
||||
b = ACI()
|
||||
b.name ="foo"
|
||||
@@ -90,7 +85,7 @@ def test_aci_equality():
|
||||
b.set_bindrule_operator("=")
|
||||
b.set_bindrule_expression("\"ldap:///cn=foo,cn=groups,cn=accounts,dc=example,dc=com\"")
|
||||
b.permissions = ['add','read','write']
|
||||
print(b)
|
||||
print b
|
||||
|
||||
assert a.isequal(b)
|
||||
assert a == b
|
||||
@@ -99,8 +94,8 @@ def test_aci_equality():
|
||||
|
||||
def check_aci_inequality(b):
|
||||
a = make_test_aci()
|
||||
print(a)
|
||||
print(b)
|
||||
print a
|
||||
print b
|
||||
|
||||
assert not a.isequal(b)
|
||||
assert not a == b
|
||||
|
||||
@@ -20,11 +20,6 @@
|
||||
"""
|
||||
Test the `ipalib.backend` module.
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
# FIXME: Pylint errors
|
||||
# pylint: disable=no-member
|
||||
# pylint: disable=maybe-no-member
|
||||
|
||||
import threading
|
||||
from ipatests.util import ClassChecker, raises, create_test_api
|
||||
@@ -34,9 +29,7 @@ from ipalib.frontend import Command
|
||||
from ipalib import backend, plugable, errors, base
|
||||
from ipapython.version import API_VERSION
|
||||
|
||||
import pytest
|
||||
|
||||
pytestmark = pytest.mark.tier0
|
||||
|
||||
class test_Backend(ClassChecker):
|
||||
"""
|
||||
@@ -74,13 +67,12 @@ class test_Connectible(ClassChecker):
|
||||
Test the `ipalib.backend.Connectible.connect` method.
|
||||
"""
|
||||
# Test that connection is created:
|
||||
api = 'the api instance'
|
||||
class example(self.cls):
|
||||
def create_connection(self, *args, **kw):
|
||||
object.__setattr__(self, 'args', args)
|
||||
object.__setattr__(self, 'kw', kw)
|
||||
return 'The connection.'
|
||||
o = example(api, shared_instance=True)
|
||||
o = example()
|
||||
args = ('Arg1', 'Arg2', 'Arg3')
|
||||
kw = dict(key1='Val1', key2='Val2', key3='Val3')
|
||||
assert not hasattr(context, 'example')
|
||||
@@ -92,11 +84,10 @@ class test_Connectible(ClassChecker):
|
||||
assert conn.conn == 'The connection.'
|
||||
assert conn.disconnect == o.disconnect
|
||||
|
||||
# Test that Exception is raised if already connected:
|
||||
m = "{0} is already connected ({1} in {2})"
|
||||
e = raises(Exception, o.connect, *args, **kw)
|
||||
assert str(e) == m.format(
|
||||
'example', o.id, threading.currentThread().getName())
|
||||
# Test that StandardError is raised if already connected:
|
||||
m = "connect: 'context.%s' already exists in thread %r"
|
||||
e = raises(StandardError, o.connect, *args, **kw)
|
||||
assert str(e) == m % ('example', threading.currentThread().getName())
|
||||
|
||||
# Double check that it works after deleting context.example:
|
||||
del context.example
|
||||
@@ -106,11 +97,10 @@ class test_Connectible(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.backend.Connectible.create_connection` method.
|
||||
"""
|
||||
api = 'the api instance'
|
||||
class example(self.cls):
|
||||
pass
|
||||
for klass in (self.cls, example):
|
||||
o = klass(api, shared_instance=True)
|
||||
o = klass()
|
||||
e = raises(NotImplementedError, o.create_connection)
|
||||
assert str(e) == '%s.create_connection()' % klass.__name__
|
||||
|
||||
@@ -118,15 +108,13 @@ class test_Connectible(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.backend.Connectible.disconnect` method.
|
||||
"""
|
||||
api = 'the api instance'
|
||||
class example(self.cls):
|
||||
destroy_connection = Disconnect()
|
||||
o = example(api, shared_instance=True)
|
||||
o = example()
|
||||
|
||||
m = "{0} is not connected ({1} in {2})"
|
||||
e = raises(Exception, o.disconnect)
|
||||
assert str(e) == m.format(
|
||||
'example', o.id, threading.currentThread().getName())
|
||||
m = "disconnect: 'context.%s' does not exist in thread %r"
|
||||
e = raises(StandardError, o.disconnect)
|
||||
assert str(e) == m % ('example', threading.currentThread().getName())
|
||||
|
||||
context.example = 'The connection.'
|
||||
assert o.disconnect() is None
|
||||
@@ -136,11 +124,10 @@ class test_Connectible(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.backend.Connectible.destroy_connection` method.
|
||||
"""
|
||||
api = 'the api instance'
|
||||
class example(self.cls):
|
||||
pass
|
||||
for klass in (self.cls, example):
|
||||
o = klass(api, shared_instance=True)
|
||||
o = klass()
|
||||
e = raises(NotImplementedError, o.destroy_connection)
|
||||
assert str(e) == '%s.destroy_connection()' % klass.__name__
|
||||
|
||||
@@ -148,11 +135,10 @@ class test_Connectible(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.backend.Connectible.isconnected` method.
|
||||
"""
|
||||
api = 'the api instance'
|
||||
class example(self.cls):
|
||||
pass
|
||||
for klass in (self.cls, example):
|
||||
o = klass(api, shared_instance=True)
|
||||
o = klass()
|
||||
assert o.isconnected() is False
|
||||
conn = 'whatever'
|
||||
setattr(context, klass.__name__, conn)
|
||||
@@ -163,15 +149,14 @@ class test_Connectible(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.backend.Connectible.conn` property.
|
||||
"""
|
||||
api = 'the api instance'
|
||||
msg = '{0} is not connected ({1} in {2})'
|
||||
msg = 'no context.%s in thread %r'
|
||||
class example(self.cls):
|
||||
pass
|
||||
for klass in (self.cls, example):
|
||||
o = klass(api, shared_instance=True)
|
||||
o = klass()
|
||||
e = raises(AttributeError, getattr, o, 'conn')
|
||||
assert str(e) == msg.format(
|
||||
klass.__name__, o.id, threading.currentThread().getName()
|
||||
assert str(e) == msg % (
|
||||
klass.__name__, threading.currentThread().getName()
|
||||
)
|
||||
conn = Connection('The connection.', Disconnect())
|
||||
setattr(context, klass.__name__, conn)
|
||||
@@ -197,7 +182,7 @@ class test_Executioner(ClassChecker):
|
||||
def execute(self, *args, **options):
|
||||
assert type(args[1]) is tuple
|
||||
return dict(result=args + (options,))
|
||||
api.add_plugin(echo)
|
||||
api.register(echo)
|
||||
|
||||
class good(Command):
|
||||
def execute(self, **options):
|
||||
@@ -205,12 +190,12 @@ class test_Executioner(ClassChecker):
|
||||
name='nurse',
|
||||
error=u'Not naughty!',
|
||||
)
|
||||
api.add_plugin(good)
|
||||
api.register(good)
|
||||
|
||||
class bad(Command):
|
||||
def execute(self, **options):
|
||||
raise ValueError('This is private.')
|
||||
api.add_plugin(bad)
|
||||
api.register(bad)
|
||||
|
||||
class with_name(Command):
|
||||
"""
|
||||
@@ -219,21 +204,22 @@ class test_Executioner(ClassChecker):
|
||||
takes_options = 'name'
|
||||
def execute(self, **options):
|
||||
return dict(result=options['name'].upper())
|
||||
api.add_plugin(with_name)
|
||||
api.register(with_name)
|
||||
|
||||
api.finalize()
|
||||
o = self.cls(api)
|
||||
o = self.cls()
|
||||
o.set_api(api)
|
||||
o.finalize()
|
||||
|
||||
# Test that CommandError is raised:
|
||||
conn = Connection('The connection.', Disconnect('someconn'))
|
||||
context.someconn = conn
|
||||
print(str(list(context.__dict__)))
|
||||
print str(context.__dict__.keys())
|
||||
e = raises(errors.CommandError, o.execute, 'nope')
|
||||
assert e.name == 'nope'
|
||||
assert conn.disconnect.called is True # Make sure destroy_context() was called
|
||||
print(str(list(context.__dict__)))
|
||||
assert list(context.__dict__) == []
|
||||
print str(context.__dict__.keys())
|
||||
assert context.__dict__.keys() == []
|
||||
|
||||
# Test with echo command:
|
||||
arg1 = unicode_str
|
||||
@@ -244,15 +230,15 @@ class test_Executioner(ClassChecker):
|
||||
|
||||
conn = Connection('The connection.', Disconnect('someconn'))
|
||||
context.someconn = conn
|
||||
print(o.execute('echo', arg1, arg2, **options))
|
||||
print(dict(
|
||||
print o.execute('echo', arg1, arg2, **options)
|
||||
print dict(
|
||||
result=(arg1, arg2, options)
|
||||
))
|
||||
)
|
||||
assert o.execute('echo', arg1, arg2, **options) == dict(
|
||||
result=(arg1, arg2, options)
|
||||
)
|
||||
assert conn.disconnect.called is True # Make sure destroy_context() was called
|
||||
assert list(context.__dict__) == []
|
||||
assert context.__dict__.keys() == []
|
||||
|
||||
conn = Connection('The connection.', Disconnect('someconn'))
|
||||
context.someconn = conn
|
||||
@@ -260,7 +246,7 @@ class test_Executioner(ClassChecker):
|
||||
result=(arg1, arg2, options)
|
||||
)
|
||||
assert conn.disconnect.called is True # Make sure destroy_context() was called
|
||||
assert list(context.__dict__) == []
|
||||
assert context.__dict__.keys() == []
|
||||
|
||||
# Test with good command:
|
||||
conn = Connection('The connection.', Disconnect('someconn'))
|
||||
@@ -269,14 +255,14 @@ class test_Executioner(ClassChecker):
|
||||
assert e.name == 'nurse'
|
||||
assert e.error == u'Not naughty!'
|
||||
assert conn.disconnect.called is True # Make sure destroy_context() was called
|
||||
assert list(context.__dict__) == []
|
||||
assert context.__dict__.keys() == []
|
||||
|
||||
# Test with bad command:
|
||||
conn = Connection('The connection.', Disconnect('someconn'))
|
||||
context.someconn = conn
|
||||
e = raises(errors.InternalError, o.execute, 'bad')
|
||||
assert conn.disconnect.called is True # Make sure destroy_context() was called
|
||||
assert list(context.__dict__) == []
|
||||
assert context.__dict__.keys() == []
|
||||
|
||||
# Test with option 'name':
|
||||
conn = Connection('The connection.', Disconnect('someconn'))
|
||||
|
||||
@@ -21,20 +21,11 @@
|
||||
Test the `ipalib.base` module.
|
||||
"""
|
||||
|
||||
import six
|
||||
import pytest
|
||||
|
||||
from ipatests.util import ClassChecker, raises
|
||||
from ipalib.constants import NAME_REGEX, NAME_ERROR
|
||||
from ipalib.constants import TYPE_ERROR, SET_ERROR, DEL_ERROR, OVERRIDE_ERROR
|
||||
from ipalib import base
|
||||
|
||||
if six.PY3:
|
||||
unicode = str
|
||||
|
||||
|
||||
pytestmark = pytest.mark.tier0
|
||||
|
||||
|
||||
class test_ReadOnly(ClassChecker):
|
||||
"""
|
||||
@@ -187,14 +178,8 @@ def test_check_name():
|
||||
]
|
||||
for name in okay:
|
||||
assert name is f(name)
|
||||
if six.PY2:
|
||||
bad_type = unicode
|
||||
bad_value = unicode(name)
|
||||
else:
|
||||
bad_type = bytes
|
||||
bad_value = name.encode('ascii')
|
||||
e = raises(TypeError, f, bad_value)
|
||||
assert str(e) == TYPE_ERROR % ('name', str, bad_value, bad_type)
|
||||
e = raises(TypeError, f, unicode(name))
|
||||
assert str(e) == TYPE_ERROR % ('name', str, unicode(name), unicode)
|
||||
for name in nope:
|
||||
e = raises(ValueError, f, name)
|
||||
assert str(e) == NAME_ERROR % (NAME_REGEX, name)
|
||||
@@ -224,7 +209,7 @@ class test_NameSpace(ClassChecker):
|
||||
_cls = base.NameSpace
|
||||
|
||||
def new(self, count, sort=True):
|
||||
members = tuple(DummyMember(i) for i in range(count, 0, -1))
|
||||
members = tuple(DummyMember(i) for i in xrange(count, 0, -1))
|
||||
assert len(members) == count
|
||||
o = self.cls(members, sort=sort)
|
||||
return (o, members)
|
||||
@@ -320,12 +305,12 @@ class test_NameSpace(ClassChecker):
|
||||
e = raises(KeyError, o.__getitem__, 'nope')
|
||||
|
||||
# Test int indexes:
|
||||
for i in range(cnt):
|
||||
for i in xrange(cnt):
|
||||
assert o[i] is members[i]
|
||||
e = raises(IndexError, o.__getitem__, cnt)
|
||||
|
||||
# Test negative int indexes:
|
||||
for i in range(1, cnt + 1):
|
||||
for i in xrange(1, cnt + 1):
|
||||
assert o[-i] is members[-i]
|
||||
e = raises(IndexError, o.__getitem__, -(cnt + 1))
|
||||
|
||||
|
||||
@@ -23,9 +23,6 @@ Test the `ipalib.errors` module.
|
||||
|
||||
from ipalib.capabilities import capabilities, client_has_capability
|
||||
|
||||
import pytest
|
||||
|
||||
pytestmark = pytest.mark.tier0
|
||||
|
||||
def test_client_has_capability():
|
||||
assert capabilities['messages'] == u'2.52'
|
||||
|
||||
@@ -24,9 +24,6 @@ Test the `ipalib.cli` module.
|
||||
from ipatests.util import raises, get_api, ClassChecker
|
||||
from ipalib import cli, plugable, frontend, backend
|
||||
|
||||
import pytest
|
||||
|
||||
pytestmark = pytest.mark.tier0
|
||||
|
||||
class test_textui(ClassChecker):
|
||||
_cls = cli.textui
|
||||
@@ -35,8 +32,7 @@ class test_textui(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.cli.textui.max_col_width` method.
|
||||
"""
|
||||
api = 'the api instance'
|
||||
o = self.cls(api)
|
||||
o = self.cls()
|
||||
e = raises(TypeError, o.max_col_width, 'hello')
|
||||
assert str(e) == 'rows: need %r or %r; got %r' % (list, tuple, 'hello')
|
||||
rows = [
|
||||
@@ -94,7 +90,7 @@ class DummyAPI(object):
|
||||
Command = property(__get_cmd)
|
||||
|
||||
def __cmd_iter(self, cnt):
|
||||
for i in range(cnt):
|
||||
for i in xrange(cnt):
|
||||
yield DummyCommand(get_cmd_name(i))
|
||||
|
||||
def finalize(self):
|
||||
|
||||
@@ -34,9 +34,6 @@ from ipalib.constants import NAME_REGEX, NAME_ERROR
|
||||
from ipalib import config, constants, base
|
||||
from ipaplatform.paths import paths
|
||||
|
||||
import pytest
|
||||
|
||||
pytestmark = pytest.mark.tier0
|
||||
|
||||
# Valid environment variables in (key, raw, value) tuples:
|
||||
# key: the name of the environment variable
|
||||
@@ -169,7 +166,7 @@ class test_Env(ClassChecker):
|
||||
assert o.__islocked__() is False
|
||||
o.__lock__()
|
||||
assert o.__islocked__() is True
|
||||
e = raises(Exception, o.__lock__)
|
||||
e = raises(StandardError, o.__lock__)
|
||||
assert str(e) == 'Env.__lock__() already called'
|
||||
|
||||
# Also test with base.lock() function:
|
||||
@@ -301,7 +298,7 @@ class test_Env(ClassChecker):
|
||||
"""
|
||||
o = self.cls()
|
||||
assert len(o) == 0
|
||||
for i in range(1, 11):
|
||||
for i in xrange(1, 11):
|
||||
key = 'key%d' % i
|
||||
value = u'value %d' % i
|
||||
o[key] = value
|
||||
@@ -348,7 +345,7 @@ class test_Env(ClassChecker):
|
||||
expected.update(dict(group1))
|
||||
assert list(o) == sorted(expected)
|
||||
assert expected['key2'] == 'value 2' # And not 'Value 2'
|
||||
for (key, value) in expected.items():
|
||||
for (key, value) in expected.iteritems():
|
||||
assert getattr(o, key) is value
|
||||
assert o[key] is value
|
||||
assert o._merge(**expected) == (0, 6)
|
||||
@@ -393,7 +390,7 @@ class test_Env(ClassChecker):
|
||||
for (k, v) in orig.items():
|
||||
assert o[k] is v
|
||||
assert list(o) == sorted(keys + ('key0', 'key1', 'key2', 'key3', 'config_loaded'))
|
||||
for i in range(4):
|
||||
for i in xrange(4):
|
||||
assert o['key%d' % i] == ('var%d' % i)
|
||||
keys = tuple(o)
|
||||
|
||||
@@ -432,7 +429,7 @@ class test_Env(ClassChecker):
|
||||
assert o._isdone('_bootstrap') is False
|
||||
o._bootstrap(**overrides)
|
||||
assert o._isdone('_bootstrap') is True
|
||||
e = raises(Exception, o._bootstrap)
|
||||
e = raises(StandardError, o._bootstrap)
|
||||
assert str(e) == 'Env._bootstrap() already called'
|
||||
return (o, home)
|
||||
|
||||
@@ -515,7 +512,7 @@ class test_Env(ClassChecker):
|
||||
assert key in o
|
||||
|
||||
# Check that it can't be called twice:
|
||||
e = raises(Exception, o._finalize_core)
|
||||
e = raises(StandardError, o._finalize_core)
|
||||
assert str(e) == 'Env._finalize_core() already called'
|
||||
|
||||
return (o, home)
|
||||
@@ -589,7 +586,7 @@ class test_Env(ClassChecker):
|
||||
assert o._isdone('_finalize') is True
|
||||
|
||||
# Check that it can't be called twice:
|
||||
e = raises(Exception, o._finalize)
|
||||
e = raises(StandardError, o._finalize)
|
||||
assert str(e) == 'Env._finalize() already called'
|
||||
|
||||
# Check that _finalize() calls __lock__()
|
||||
@@ -597,7 +594,7 @@ class test_Env(ClassChecker):
|
||||
assert o.__islocked__() is False
|
||||
o._finalize()
|
||||
assert o.__islocked__() is True
|
||||
e = raises(Exception, o.__lock__)
|
||||
e = raises(StandardError, o.__lock__)
|
||||
assert str(e) == 'Env.__lock__() already called'
|
||||
|
||||
# Check that **lastchance works
|
||||
|
||||
@@ -25,9 +25,6 @@ from ipatests.util import read_only, raises, get_api, ClassChecker
|
||||
from ipalib import crud, frontend, plugable, config
|
||||
from ipalib.parameters import Str
|
||||
|
||||
import pytest
|
||||
|
||||
pytestmark = pytest.mark.tier0
|
||||
|
||||
class CrudChecker(ClassChecker):
|
||||
"""
|
||||
@@ -50,8 +47,8 @@ class CrudChecker(ClassChecker):
|
||||
class user_verb(self.cls):
|
||||
takes_args = args
|
||||
takes_options = options
|
||||
api.add_plugin(user)
|
||||
api.add_plugin(user_verb)
|
||||
api.register(user)
|
||||
api.register(user_verb)
|
||||
api.finalize()
|
||||
return api
|
||||
|
||||
@@ -205,11 +202,10 @@ class test_CrudBackend(ClassChecker):
|
||||
return ldap
|
||||
|
||||
def check_method(self, name, *args):
|
||||
api = 'the api instance'
|
||||
o = self.cls(api)
|
||||
o = self.cls()
|
||||
e = raises(NotImplementedError, getattr(o, name), *args)
|
||||
assert str(e) == 'CrudBackend.%s()' % name
|
||||
sub = self.subcls(api)
|
||||
sub = self.subcls()
|
||||
e = raises(NotImplementedError, getattr(sub, name), *args)
|
||||
assert str(e) == 'ldap.%s()' % name
|
||||
|
||||
|
||||
@@ -21,26 +21,14 @@
|
||||
Test the `ipalib.errors` module.
|
||||
"""
|
||||
|
||||
# FIXME: Pylint errors
|
||||
# pylint: disable=no-member
|
||||
|
||||
import re
|
||||
import inspect
|
||||
import pytest
|
||||
|
||||
import six
|
||||
|
||||
from ipatests.util import assert_equal, raises
|
||||
from ipalib import errors, text
|
||||
from ipaplatform.paths import paths
|
||||
from ipalib.constants import TYPE_ERROR
|
||||
|
||||
if six.PY3:
|
||||
unicode = str
|
||||
|
||||
|
||||
pytestmark = pytest.mark.tier0
|
||||
|
||||
|
||||
class PrivateExceptionTester(object):
|
||||
_klass = None
|
||||
@@ -49,21 +37,21 @@ class PrivateExceptionTester(object):
|
||||
def __get_klass(self):
|
||||
if self.__klass is None:
|
||||
self.__klass = self._klass
|
||||
assert issubclass(self.__klass, Exception)
|
||||
assert issubclass(self.__klass, StandardError)
|
||||
assert issubclass(self.__klass, errors.PrivateError)
|
||||
assert not issubclass(self.__klass, errors.PublicError)
|
||||
return self.__klass
|
||||
klass = property(__get_klass)
|
||||
|
||||
def new(self, **kw):
|
||||
for (key, value) in kw.items():
|
||||
for (key, value) in kw.iteritems():
|
||||
assert not hasattr(self.klass, key), key
|
||||
inst = self.klass(**kw)
|
||||
assert isinstance(inst, Exception)
|
||||
assert isinstance(inst, StandardError)
|
||||
assert isinstance(inst, errors.PrivateError)
|
||||
assert isinstance(inst, self.klass)
|
||||
assert not isinstance(inst, errors.PublicError)
|
||||
for (key, value) in kw.items():
|
||||
for (key, value) in kw.iteritems():
|
||||
assert getattr(inst, key) is value
|
||||
assert str(inst) == self.klass.format % kw
|
||||
assert inst.message == str(inst)
|
||||
@@ -207,7 +195,7 @@ class PublicExceptionTester(object):
|
||||
def __get_klass(self):
|
||||
if self.__klass is None:
|
||||
self.__klass = self._klass
|
||||
assert issubclass(self.__klass, Exception)
|
||||
assert issubclass(self.__klass, StandardError)
|
||||
assert issubclass(self.__klass, errors.PublicError)
|
||||
assert not issubclass(self.__klass, errors.PrivateError)
|
||||
assert type(self.__klass.errno) is int
|
||||
@@ -217,18 +205,18 @@ class PublicExceptionTester(object):
|
||||
|
||||
def new(self, format=None, message=None, **kw):
|
||||
# Test that TypeError is raised if message isn't unicode:
|
||||
e = raises(TypeError, self.klass, message=b'The message')
|
||||
assert str(e) == TYPE_ERROR % ('message', unicode, b'The message', bytes)
|
||||
e = raises(TypeError, self.klass, message='The message')
|
||||
assert str(e) == TYPE_ERROR % ('message', unicode, 'The message', str)
|
||||
|
||||
# Test the instance:
|
||||
for (key, value) in kw.items():
|
||||
for (key, value) in kw.iteritems():
|
||||
assert not hasattr(self.klass, key), key
|
||||
inst = self.klass(format=format, message=message, **kw)
|
||||
for required_class in self.required_classes:
|
||||
assert isinstance(inst, required_class)
|
||||
assert isinstance(inst, self.klass)
|
||||
assert not isinstance(inst, errors.PrivateError)
|
||||
for (key, value) in kw.items():
|
||||
for (key, value) in kw.iteritems():
|
||||
assert getattr(inst, key) is value
|
||||
return inst
|
||||
|
||||
@@ -238,7 +226,7 @@ class test_PublicError(PublicExceptionTester):
|
||||
Test the `ipalib.errors.PublicError` exception.
|
||||
"""
|
||||
_klass = errors.PublicError
|
||||
required_classes = Exception, errors.PublicError
|
||||
required_classes = StandardError, errors.PublicError
|
||||
|
||||
def test_init(self):
|
||||
message = u'The translated, interpolated message'
|
||||
@@ -265,9 +253,9 @@ class test_PublicError(PublicExceptionTester):
|
||||
assert inst.key1 is val1
|
||||
assert inst.key2 is val2
|
||||
|
||||
# Test with format=None, message=bytes
|
||||
e = raises(TypeError, self.klass, message=b'the message', **kw)
|
||||
assert str(e) == TYPE_ERROR % ('message', unicode, b'the message', bytes)
|
||||
# Test with format=None, message=str
|
||||
e = raises(TypeError, self.klass, message='the message', **kw)
|
||||
assert str(e) == TYPE_ERROR % ('message', unicode, 'the message', str)
|
||||
|
||||
# Test with format=None, message=None
|
||||
e = raises(ValueError, self.klass, **kw)
|
||||
@@ -338,7 +326,8 @@ class test_PublicError(PublicExceptionTester):
|
||||
# this expression checks if each word of instructions
|
||||
# exists in a string as a separate line, with right order
|
||||
regexp = re.compile('(?ims).*' +
|
||||
''.join('(%s).*' % (x) for x in instructions) +
|
||||
''.join(map(lambda x: '(%s).*' % (x),
|
||||
instructions)) +
|
||||
'$')
|
||||
inst = subclass(instructions=instructions, **kw)
|
||||
assert inst.format is subclass.format
|
||||
@@ -378,8 +367,8 @@ class BaseMessagesTest(object):
|
||||
|
||||
class test_PublicErrors(object):
|
||||
message_list = errors.public_errors
|
||||
errno_range = list(range(900, 5999))
|
||||
required_classes = (Exception, errors.PublicError)
|
||||
errno_range = xrange(900, 5999)
|
||||
required_classes = (StandardError, errors.PublicError)
|
||||
texts = errors._texts
|
||||
|
||||
def extratest(self, cls):
|
||||
|
||||
@@ -21,14 +21,8 @@
|
||||
Test the `ipalib.frontend` module.
|
||||
"""
|
||||
|
||||
# FIXME: Pylint errors
|
||||
# pylint: disable=no-member
|
||||
import pytest
|
||||
|
||||
import six
|
||||
|
||||
from ipatests.util import raises, read_only
|
||||
from ipatests.util import ClassChecker, create_test_api
|
||||
from ipatests.util import raises, getitem, no_set, no_del, read_only
|
||||
from ipatests.util import check_TypeError, ClassChecker, create_test_api
|
||||
from ipatests.util import assert_equal
|
||||
from ipalib.constants import TYPE_ERROR
|
||||
from ipalib.base import NameSpace
|
||||
@@ -37,13 +31,6 @@ from ipalib import output, messages
|
||||
from ipalib.parameters import Str
|
||||
from ipapython.version import API_VERSION
|
||||
|
||||
if six.PY3:
|
||||
unicode = str
|
||||
|
||||
|
||||
pytestmark = pytest.mark.tier0
|
||||
|
||||
|
||||
def test_RULE_FLAG():
|
||||
assert frontend.RULE_FLAG == 'validation_rule'
|
||||
|
||||
@@ -99,32 +86,31 @@ class test_HasParam(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.frontend.HasParam._get_param_iterable` method.
|
||||
"""
|
||||
api = 'the api instance'
|
||||
class WithTuple(self.cls):
|
||||
takes_stuff = ('one', 'two')
|
||||
o = WithTuple(api)
|
||||
o = WithTuple()
|
||||
assert o._get_param_iterable('stuff') is WithTuple.takes_stuff
|
||||
|
||||
junk = ('three', 'four')
|
||||
class WithCallable(self.cls):
|
||||
def takes_stuff(self):
|
||||
return junk
|
||||
o = WithCallable(api)
|
||||
o = WithCallable()
|
||||
assert o._get_param_iterable('stuff') is junk
|
||||
|
||||
class WithParam(self.cls):
|
||||
takes_stuff = parameters.Str('five')
|
||||
o = WithParam(api)
|
||||
o = WithParam()
|
||||
assert o._get_param_iterable('stuff') == (WithParam.takes_stuff,)
|
||||
|
||||
class WithStr(self.cls):
|
||||
takes_stuff = 'six'
|
||||
o = WithStr(api)
|
||||
o = WithStr()
|
||||
assert o._get_param_iterable('stuff') == ('six',)
|
||||
|
||||
class Wrong(self.cls):
|
||||
takes_stuff = ['seven', 'eight']
|
||||
o = Wrong(api)
|
||||
o = Wrong()
|
||||
e = raises(TypeError, o._get_param_iterable, 'stuff')
|
||||
assert str(e) == '%s.%s must be a tuple, callable, or spec; got %r' % (
|
||||
'Wrong', 'takes_stuff', Wrong.takes_stuff
|
||||
@@ -134,7 +120,6 @@ class test_HasParam(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.frontend.HasParam._filter_param_by_context` method.
|
||||
"""
|
||||
api = 'the api instance'
|
||||
class Example(self.cls):
|
||||
def get_stuff(self):
|
||||
return (
|
||||
@@ -144,7 +129,7 @@ class test_HasParam(ClassChecker):
|
||||
parameters.Str('four', exclude='server'),
|
||||
parameters.Str('five', exclude=['whatever', 'cli']),
|
||||
)
|
||||
o = Example(api)
|
||||
o = Example()
|
||||
|
||||
# Test when env is None:
|
||||
params = list(o._filter_param_by_context('stuff'))
|
||||
@@ -173,7 +158,7 @@ class test_HasParam(ClassChecker):
|
||||
# Test with no get_stuff:
|
||||
class Missing(self.cls):
|
||||
pass
|
||||
o = Missing(api)
|
||||
o = Missing()
|
||||
gen = o._filter_param_by_context('stuff')
|
||||
e = raises(NotImplementedError, list, gen)
|
||||
assert str(e) == 'Missing.get_stuff()'
|
||||
@@ -181,7 +166,7 @@ class test_HasParam(ClassChecker):
|
||||
# Test when get_stuff is not callable:
|
||||
class NotCallable(self.cls):
|
||||
get_stuff = ('one', 'two')
|
||||
o = NotCallable(api)
|
||||
o = NotCallable()
|
||||
gen = o._filter_param_by_context('stuff')
|
||||
e = raises(TypeError, list, gen)
|
||||
assert str(e) == '%s.%s must be a callable; got %r' % (
|
||||
@@ -231,14 +216,10 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Helper method used to test args and options.
|
||||
"""
|
||||
class api(object):
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
class example(self.cls):
|
||||
takes_args = args
|
||||
takes_options = options
|
||||
o = example(api)
|
||||
o = example()
|
||||
o.finalize()
|
||||
return o
|
||||
|
||||
@@ -253,8 +234,7 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.frontend.Command.get_args` method.
|
||||
"""
|
||||
api = 'the api instance'
|
||||
assert list(self.cls(api).get_args()) == []
|
||||
assert list(self.cls().get_args()) == []
|
||||
args = ('login', 'stuff')
|
||||
o = self.get_instance(args=args)
|
||||
assert tuple(o.get_args()) == args
|
||||
@@ -263,8 +243,7 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.frontend.Command.get_options` method.
|
||||
"""
|
||||
api = 'the api instance'
|
||||
options = list(self.cls(api).get_options())
|
||||
options = list(self.cls().get_options())
|
||||
assert len(options) == 1
|
||||
assert options[0].name == 'version'
|
||||
options = ('verbose', 'debug')
|
||||
@@ -277,11 +256,8 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Test the ``ipalib.frontend.Command.args`` instance attribute.
|
||||
"""
|
||||
class api(object):
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
o = self.cls(api)
|
||||
assert self.cls().args is None
|
||||
o = self.cls()
|
||||
o.finalize()
|
||||
assert type(o.args) is plugable.NameSpace
|
||||
assert len(o.args) == 0
|
||||
@@ -298,14 +274,9 @@ class test_Command(ClassChecker):
|
||||
assert ns.source.multivalue is False
|
||||
|
||||
# Test TypeError:
|
||||
if six.PY2:
|
||||
e = raises(TypeError, self.get_instance, args=(u'whatever',))
|
||||
assert str(e) == TYPE_ERROR % (
|
||||
'spec', (str, parameters.Param), u'whatever', unicode)
|
||||
else:
|
||||
e = raises(TypeError, self.get_instance, args=(b'whatever',))
|
||||
assert str(e) == TYPE_ERROR % (
|
||||
'spec', (str, parameters.Param), b'whatever', bytes)
|
||||
e = raises(TypeError, self.get_instance, args=(u'whatever',))
|
||||
assert str(e) == TYPE_ERROR % (
|
||||
'spec', (str, parameters.Param), u'whatever', unicode)
|
||||
|
||||
# Test ValueError, required after optional:
|
||||
e = raises(ValueError, self.get_instance, args=('arg1?', 'arg2'))
|
||||
@@ -334,11 +305,8 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Test the ``ipalib.frontend.Command.options`` instance attribute.
|
||||
"""
|
||||
class api(object):
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
o = self.cls(api)
|
||||
assert self.cls().options is None
|
||||
o = self.cls()
|
||||
o.finalize()
|
||||
assert type(o.options) is plugable.NameSpace
|
||||
assert len(o.options) == 1
|
||||
@@ -358,11 +326,8 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Test the ``ipalib.frontend.Command.output`` instance attribute.
|
||||
"""
|
||||
class api(object):
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
inst = self.cls(api)
|
||||
inst = self.cls()
|
||||
assert inst.output is None
|
||||
inst.finalize()
|
||||
assert type(inst.output) is plugable.NameSpace
|
||||
assert list(inst.output) == ['result']
|
||||
@@ -372,10 +337,9 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Test the ``ipalib.frontend.Command._iter_output`` instance attribute.
|
||||
"""
|
||||
api = 'the api instance'
|
||||
class Example(self.cls):
|
||||
pass
|
||||
inst = Example(api)
|
||||
inst = Example()
|
||||
|
||||
inst.has_output = tuple()
|
||||
assert list(inst._iter_output()) == []
|
||||
@@ -406,11 +370,6 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.frontend.Command.soft_validate` method.
|
||||
"""
|
||||
class api(object):
|
||||
env = config.Env(context='cli')
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
class user_add(frontend.Command):
|
||||
takes_args = parameters.Str('uid',
|
||||
normalizer=lambda value: value.lower(),
|
||||
@@ -419,7 +378,8 @@ class test_Command(ClassChecker):
|
||||
|
||||
takes_options = ('givenname', 'sn')
|
||||
|
||||
cmd = user_add(api)
|
||||
cmd = user_add()
|
||||
cmd.env = config.Env(context='cli')
|
||||
cmd.finalize()
|
||||
assert list(cmd.params) == ['givenname', 'sn', 'uid', 'version']
|
||||
ret = cmd.soft_validate({})
|
||||
@@ -435,33 +395,25 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.frontend.Command.convert` method.
|
||||
"""
|
||||
class api(object):
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
kw = dict(
|
||||
option0=u'1.5',
|
||||
option1=u'7',
|
||||
)
|
||||
o = self.subcls(api)
|
||||
o = self.subcls()
|
||||
o.finalize()
|
||||
for (key, value) in o.convert(**kw).items():
|
||||
for (key, value) in o.convert(**kw).iteritems():
|
||||
assert_equal(unicode(kw[key]), value)
|
||||
|
||||
def test_normalize(self):
|
||||
"""
|
||||
Test the `ipalib.frontend.Command.normalize` method.
|
||||
"""
|
||||
class api(object):
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
kw = dict(
|
||||
option0=u'OPTION0',
|
||||
option1=u'OPTION1',
|
||||
)
|
||||
norm = dict((k, v.lower()) for (k, v) in kw.items())
|
||||
sub = self.subcls(api)
|
||||
sub = self.subcls()
|
||||
sub.finalize()
|
||||
assert sub.normalize(**kw) == norm
|
||||
|
||||
@@ -489,9 +441,10 @@ class test_Command(ClassChecker):
|
||||
|
||||
(api, home) = create_test_api()
|
||||
api.finalize()
|
||||
o = my_cmd(api)
|
||||
o = my_cmd()
|
||||
o.set_api(api)
|
||||
o.finalize()
|
||||
e = o(**kw) # pylint: disable=not-callable
|
||||
e = o(**kw)
|
||||
assert type(e) is dict
|
||||
assert 'result' in e
|
||||
assert 'option2' in e['result']
|
||||
@@ -501,13 +454,9 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.frontend.Command.validate` method.
|
||||
"""
|
||||
class api(object):
|
||||
env = config.Env(context='cli')
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
|
||||
sub = self.subcls(api)
|
||||
sub = self.subcls()
|
||||
sub.env = config.Env(context='cli')
|
||||
sub.finalize()
|
||||
|
||||
# Check with valid values
|
||||
@@ -539,8 +488,7 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.frontend.Command.execute` method.
|
||||
"""
|
||||
api = 'the api instance'
|
||||
o = self.cls(api)
|
||||
o = self.cls()
|
||||
e = raises(NotImplementedError, o.execute)
|
||||
assert str(e) == 'Command.execute()'
|
||||
|
||||
@@ -617,7 +565,8 @@ class test_Command(ClassChecker):
|
||||
|
||||
(api, home) = create_test_api()
|
||||
api.finalize()
|
||||
o = my_cmd(api)
|
||||
o = my_cmd()
|
||||
o.set_api(api)
|
||||
o.finalize()
|
||||
e = o.run(*args, **kw)
|
||||
assert type(e) is dict
|
||||
@@ -656,22 +605,18 @@ class test_Command(ClassChecker):
|
||||
# Test in server context:
|
||||
(api, home) = create_test_api(in_server=True)
|
||||
api.finalize()
|
||||
o = my_cmd(api)
|
||||
if six.PY2:
|
||||
assert o.run.__func__ is self.cls.run.__func__
|
||||
else:
|
||||
assert o.run.__func__ is self.cls.run
|
||||
o = my_cmd()
|
||||
o.set_api(api)
|
||||
assert o.run.im_func is self.cls.run.im_func
|
||||
out = o.run(*args, **kw)
|
||||
assert ('execute', args, kw) == out
|
||||
|
||||
# Test in non-server context
|
||||
(api, home) = create_test_api(in_server=False)
|
||||
api.finalize()
|
||||
o = my_cmd(api)
|
||||
if six.PY2:
|
||||
assert o.run.__func__ is self.cls.run.__func__
|
||||
else:
|
||||
assert o.run.__func__ is self.cls.run
|
||||
o = my_cmd()
|
||||
o.set_api(api)
|
||||
assert o.run.im_func is self.cls.run.im_func
|
||||
assert ('forward', args, kw) == o.run(*args, **kw)
|
||||
|
||||
def test_messages(self):
|
||||
@@ -702,35 +647,27 @@ class test_Command(ClassChecker):
|
||||
# Test in server context:
|
||||
(api, home) = create_test_api(in_server=True)
|
||||
api.finalize()
|
||||
o = my_cmd(api)
|
||||
if six.PY2:
|
||||
assert o.run.__func__ is self.cls.run.__func__
|
||||
else:
|
||||
assert o.run.__func__ is self.cls.run
|
||||
o = my_cmd()
|
||||
o.set_api(api)
|
||||
assert o.run.im_func is self.cls.run.im_func
|
||||
assert {'name': 'execute', 'messages': expected} == o.run(*args, **kw)
|
||||
|
||||
# Test in non-server context
|
||||
(api, home) = create_test_api(in_server=False)
|
||||
api.finalize()
|
||||
o = my_cmd(api)
|
||||
if six.PY2:
|
||||
assert o.run.__func__ is self.cls.run.__func__
|
||||
else:
|
||||
assert o.run.__func__ is self.cls.run
|
||||
o = my_cmd()
|
||||
o.set_api(api)
|
||||
assert o.run.im_func is self.cls.run.im_func
|
||||
assert {'name': 'forward', 'messages': expected} == o.run(*args, **kw)
|
||||
|
||||
def test_validate_output_basic(self):
|
||||
"""
|
||||
Test the `ipalib.frontend.Command.validate_output` method.
|
||||
"""
|
||||
class api(object):
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
class Example(self.cls):
|
||||
has_output = ('foo', 'bar', 'baz')
|
||||
|
||||
inst = Example(api)
|
||||
inst = Example()
|
||||
inst.finalize()
|
||||
|
||||
# Test with wrong type:
|
||||
@@ -765,17 +702,13 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Test `ipalib.frontend.Command.validate_output` per-type validation.
|
||||
"""
|
||||
class api(object):
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
|
||||
class Complex(self.cls):
|
||||
has_output = (
|
||||
output.Output('foo', int),
|
||||
output.Output('bar', list),
|
||||
)
|
||||
inst = Complex(api)
|
||||
inst = Complex()
|
||||
inst.finalize()
|
||||
|
||||
wrong = dict(foo=17.9, bar=[18])
|
||||
@@ -794,10 +727,6 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Test `ipalib.frontend.Command.validate_output` nested validation.
|
||||
"""
|
||||
class api(object):
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
|
||||
class Subclass(output.ListOfEntries):
|
||||
pass
|
||||
@@ -808,7 +737,7 @@ class test_Command(ClassChecker):
|
||||
output.Output('hello', int),
|
||||
Subclass('world'),
|
||||
)
|
||||
inst = nested(api)
|
||||
inst = nested()
|
||||
inst.finalize()
|
||||
okay = dict(foo='bar')
|
||||
nope = ('aye', 'bee')
|
||||
@@ -829,10 +758,6 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.frontend.Command.get_output_params` method.
|
||||
"""
|
||||
class api(object):
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
class example(self.cls):
|
||||
has_output_params = (
|
||||
'one',
|
||||
@@ -847,7 +772,8 @@ class test_Command(ClassChecker):
|
||||
'baz',
|
||||
)
|
||||
|
||||
inst = example(api)
|
||||
inst = example()
|
||||
assert list(inst.get_output_params()) == ['one', 'two', 'three']
|
||||
inst.finalize()
|
||||
assert list(inst.get_output_params()) == [
|
||||
'one', 'two', 'three', inst.params.foo, inst.params.baz
|
||||
@@ -865,11 +791,7 @@ class test_LocalOrRemote(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.frontend.LocalOrRemote.__init__` method.
|
||||
"""
|
||||
class api(object):
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
o = self.cls(api)
|
||||
o = self.cls()
|
||||
o.finalize()
|
||||
assert list(o.args) == []
|
||||
assert list(o.options) == ['server', 'version']
|
||||
@@ -892,7 +814,7 @@ class test_LocalOrRemote(ClassChecker):
|
||||
|
||||
# Test when in_server=False:
|
||||
(api, home) = create_test_api(in_server=False)
|
||||
api.add_plugin(example)
|
||||
api.register(example)
|
||||
api.finalize()
|
||||
cmd = api.Command.example
|
||||
assert cmd(version=u'2.47') == dict(
|
||||
@@ -910,7 +832,7 @@ class test_LocalOrRemote(ClassChecker):
|
||||
|
||||
# Test when in_server=True (should always call execute):
|
||||
(api, home) = create_test_api(in_server=True)
|
||||
api.add_plugin(example)
|
||||
api.register(example)
|
||||
api.finalize()
|
||||
cmd = api.Command.example
|
||||
assert cmd(version=u'2.47') == dict(
|
||||
@@ -947,6 +869,16 @@ class test_Object(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.frontend.Object.__init__` method.
|
||||
"""
|
||||
o = self.cls()
|
||||
assert o.backend is None
|
||||
assert o.methods is None
|
||||
assert o.params is None
|
||||
assert o.params_minus_pk is None
|
||||
|
||||
def test_set_api(self):
|
||||
"""
|
||||
Test the `ipalib.frontend.Object.set_api` method.
|
||||
"""
|
||||
# Setup for test:
|
||||
class DummyAttribute(object):
|
||||
def __init__(self, obj_name, attr_name, name=None):
|
||||
@@ -967,37 +899,33 @@ class test_Object(ClassChecker):
|
||||
|
||||
def get_attributes(cnt, format):
|
||||
for name in ['other', 'user', 'another']:
|
||||
for i in range(cnt):
|
||||
for i in xrange(cnt):
|
||||
yield DummyAttribute(name, format % i)
|
||||
|
||||
cnt = 10
|
||||
methods_format = 'method_%d'
|
||||
|
||||
class FakeAPI(object):
|
||||
Method = plugable.NameSpace(
|
||||
_d = dict(
|
||||
Method=plugable.NameSpace(
|
||||
get_attributes(cnt, methods_format)
|
||||
)
|
||||
def __contains__(self, key):
|
||||
return hasattr(self, key)
|
||||
def __getitem__(self, key):
|
||||
return getattr(self, key)
|
||||
def is_production_mode(self):
|
||||
return False
|
||||
api = FakeAPI()
|
||||
),
|
||||
)
|
||||
api = plugable.MagicDict(_d)
|
||||
assert len(api.Method) == cnt * 3
|
||||
|
||||
class user(self.cls):
|
||||
pass
|
||||
|
||||
# Actually perform test:
|
||||
o = user(api)
|
||||
o = user()
|
||||
o.set_api(api)
|
||||
assert read_only(o, 'api') is api
|
||||
|
||||
namespace = o.methods
|
||||
assert isinstance(namespace, plugable.NameSpace)
|
||||
assert len(namespace) == cnt
|
||||
f = methods_format
|
||||
for i in range(cnt):
|
||||
for i in xrange(cnt):
|
||||
attr_name = f % i
|
||||
attr = namespace[attr_name]
|
||||
assert isinstance(attr, DummyAttribute)
|
||||
@@ -1007,13 +935,15 @@ class test_Object(ClassChecker):
|
||||
assert attr.name == '%s_%s' % ('user', attr_name)
|
||||
|
||||
# Test params instance attribute
|
||||
o = self.cls(api)
|
||||
o = self.cls()
|
||||
o.set_api(api)
|
||||
ns = o.params
|
||||
assert type(ns) is plugable.NameSpace
|
||||
assert len(ns) == 0
|
||||
class example(self.cls):
|
||||
takes_params = ('banana', 'apple')
|
||||
o = example(api)
|
||||
o = example()
|
||||
o.set_api(api)
|
||||
ns = o.params
|
||||
assert type(ns) is plugable.NameSpace
|
||||
assert len(ns) == 2, repr(ns)
|
||||
@@ -1036,7 +966,8 @@ class test_Object(ClassChecker):
|
||||
'one',
|
||||
'two',
|
||||
)
|
||||
o = example1(api)
|
||||
o = example1()
|
||||
o.set_api(api)
|
||||
assert o.primary_key is None
|
||||
|
||||
# Test with 1 primary key:
|
||||
@@ -1047,7 +978,8 @@ class test_Object(ClassChecker):
|
||||
parameters.Str('three', primary_key=True),
|
||||
'four',
|
||||
)
|
||||
o = example2(api)
|
||||
o = example2()
|
||||
o.set_api(api)
|
||||
pk = o.primary_key
|
||||
assert type(pk) is parameters.Str
|
||||
assert pk.name == 'three'
|
||||
@@ -1064,7 +996,8 @@ class test_Object(ClassChecker):
|
||||
'three',
|
||||
parameters.Str('four', primary_key=True),
|
||||
)
|
||||
o = example3(api)
|
||||
o = example3()
|
||||
o.set_api(api)
|
||||
e = raises(ValueError, o.finalize)
|
||||
assert str(e) == \
|
||||
'example3 (Object) has multiple primary keys: one, two, four'
|
||||
@@ -1076,10 +1009,10 @@ class test_Object(ClassChecker):
|
||||
(api, home) = create_test_api()
|
||||
class ldap(backend.Backend):
|
||||
whatever = 'It worked!'
|
||||
api.add_plugin(ldap)
|
||||
api.register(ldap)
|
||||
class user(frontend.Object):
|
||||
backend_name = 'ldap'
|
||||
api.add_plugin(user)
|
||||
api.register(user)
|
||||
api.finalize()
|
||||
b = api.Object.user.backend
|
||||
assert isinstance(b, ldap)
|
||||
@@ -1089,13 +1022,12 @@ class test_Object(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.frontend.Object.get_dn` method.
|
||||
"""
|
||||
api = 'the api instance'
|
||||
o = self.cls(api)
|
||||
o = self.cls()
|
||||
e = raises(NotImplementedError, o.get_dn, 'primary key')
|
||||
assert str(e) == 'Object.get_dn()'
|
||||
class user(self.cls):
|
||||
pass
|
||||
o = user(api)
|
||||
o = user()
|
||||
e = raises(NotImplementedError, o.get_dn, 'primary key')
|
||||
assert str(e) == 'user.get_dn()'
|
||||
|
||||
@@ -1105,9 +1037,9 @@ class test_Object(ClassChecker):
|
||||
"""
|
||||
class example(self.cls):
|
||||
takes_params = ('one', 'two', 'three', 'four')
|
||||
o = example()
|
||||
(api, home) = create_test_api()
|
||||
api.finalize()
|
||||
o = example(api)
|
||||
o.set_api(api)
|
||||
p = o.params
|
||||
assert tuple(o.params_minus()) == tuple(p())
|
||||
assert tuple(o.params_minus([])) == tuple(p())
|
||||
@@ -1138,19 +1070,28 @@ class test_Attribute(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.frontend.Attribute.__init__` method.
|
||||
"""
|
||||
class user_add(self.cls):
|
||||
pass
|
||||
o = user_add()
|
||||
assert read_only(o, 'obj') is None
|
||||
assert read_only(o, 'obj_name') == 'user'
|
||||
assert read_only(o, 'attr_name') == 'add'
|
||||
|
||||
def test_set_api(self):
|
||||
"""
|
||||
Test the `ipalib.frontend.Attribute.set_api` method.
|
||||
"""
|
||||
user_obj = 'The user frontend.Object instance'
|
||||
class api(object):
|
||||
Object = dict(user=user_obj)
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
class user_add(self.cls):
|
||||
pass
|
||||
o = user_add(api)
|
||||
o = user_add()
|
||||
assert read_only(o, 'api') is None
|
||||
assert read_only(o, 'obj') is None
|
||||
o.set_api(api)
|
||||
assert read_only(o, 'api') is api
|
||||
assert read_only(o, 'obj') is user_obj
|
||||
assert read_only(o, 'obj_name') == 'user'
|
||||
assert read_only(o, 'attr_name') == 'add'
|
||||
|
||||
|
||||
class test_Method(ClassChecker):
|
||||
@@ -1174,8 +1115,8 @@ class test_Method(ClassChecker):
|
||||
class user_verb(self.cls):
|
||||
takes_args = args
|
||||
takes_options = options
|
||||
api.add_plugin(user)
|
||||
api.add_plugin(user_verb)
|
||||
api.register(user)
|
||||
api.register(user_verb)
|
||||
api.finalize()
|
||||
return api
|
||||
|
||||
@@ -1189,10 +1130,9 @@ class test_Method(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.frontend.Method.__init__` method.
|
||||
"""
|
||||
api = 'the api instance'
|
||||
class user_add(self.cls):
|
||||
pass
|
||||
o = user_add(api)
|
||||
o = user_add()
|
||||
assert o.name == 'user_add'
|
||||
assert o.obj_name == 'user'
|
||||
assert o.attr_name == 'add'
|
||||
|
||||
@@ -25,9 +25,6 @@ from ipalib import messages
|
||||
from ipalib.capabilities import capabilities
|
||||
from ipatests.test_ipalib import test_errors
|
||||
|
||||
import pytest
|
||||
|
||||
pytestmark = pytest.mark.tier0
|
||||
|
||||
class HelloMessage(messages.PublicMessage):
|
||||
type = 'info'
|
||||
@@ -44,7 +41,7 @@ class test_PublicMessage(test_errors.test_PublicError):
|
||||
|
||||
class test_PublicMessages(test_errors.BaseMessagesTest):
|
||||
message_list = messages.public_messages
|
||||
errno_range = list(range(10000, 19999))
|
||||
errno_range = xrange(10000, 19999)
|
||||
required_classes = (UserWarning, messages.PublicMessage)
|
||||
texts = messages._texts
|
||||
|
||||
|
||||
@@ -27,10 +27,6 @@ from ipalib.frontend import Command
|
||||
from ipalib import _
|
||||
from ipapython.version import API_VERSION
|
||||
|
||||
import pytest
|
||||
|
||||
pytestmark = pytest.mark.tier0
|
||||
|
||||
class test_Output(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.output.Output` class.
|
||||
@@ -75,10 +71,9 @@ class test_ListOfEntries(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.output.ListOfEntries.validate` method.
|
||||
"""
|
||||
api = 'the api instance'
|
||||
class example(Command):
|
||||
pass
|
||||
cmd = example(api)
|
||||
cmd = example()
|
||||
inst = self.cls('stuff')
|
||||
|
||||
okay = dict(foo='bar')
|
||||
|
||||
@@ -22,19 +22,12 @@
|
||||
Test the `ipalib.parameters` module.
|
||||
"""
|
||||
|
||||
# FIXME: Pylint errors
|
||||
# pylint: disable=no-member
|
||||
|
||||
import datetime
|
||||
import re
|
||||
import sys
|
||||
from types import NoneType
|
||||
from decimal import Decimal
|
||||
from inspect import isclass
|
||||
from six.moves.xmlrpc_client import MAXINT, MININT
|
||||
import pytest
|
||||
|
||||
import six
|
||||
|
||||
from ipatests.util import raises, ClassChecker, read_only
|
||||
from ipatests.util import dummy_ugettext, assert_equal
|
||||
from ipatests.data import binary_bytes, utf8_bytes, unicode_str
|
||||
@@ -42,15 +35,9 @@ from ipalib import parameters, text, errors, config
|
||||
from ipalib.constants import TYPE_ERROR, CALLABLE_ERROR
|
||||
from ipalib.errors import ValidationError, ConversionError
|
||||
from ipalib import _
|
||||
from xmlrpclib import MAXINT, MININT
|
||||
|
||||
if six.PY3:
|
||||
unicode = str
|
||||
long = int
|
||||
|
||||
NULLS = (None, b'', u'', tuple(), [])
|
||||
|
||||
pytestmark = pytest.mark.tier0
|
||||
|
||||
NULLS = (None, '', u'', tuple(), [])
|
||||
|
||||
class test_DefaultFrom(ClassChecker):
|
||||
"""
|
||||
@@ -160,12 +147,8 @@ def test_parse_param_spec():
|
||||
assert f('name^') == ('name^', dict(required=True, multivalue=False))
|
||||
|
||||
# Test that TypeError is raised if spec isn't an str:
|
||||
if six.PY2:
|
||||
bad_value = u'name?'
|
||||
else:
|
||||
bad_value = b'name?'
|
||||
e = raises(TypeError, f, bad_value)
|
||||
assert str(e) == TYPE_ERROR % ('spec', str, bad_value, type(bad_value))
|
||||
e = raises(TypeError, f, u'name?')
|
||||
assert str(e) == TYPE_ERROR % ('spec', str, u'name?', unicode)
|
||||
|
||||
|
||||
class DummyRule(object):
|
||||
@@ -236,12 +219,12 @@ class test_Param(ClassChecker):
|
||||
|
||||
# Test that ValueError is raised when a kwarg from a subclass
|
||||
# conflicts with an attribute:
|
||||
class Subclass1(self.cls):
|
||||
class Subclass(self.cls):
|
||||
kwargs = self.cls.kwargs + (
|
||||
('convert', callable, None),
|
||||
)
|
||||
e = raises(ValueError, Subclass1, name)
|
||||
assert str(e) == "kwarg 'convert' conflicts with attribute on Subclass1"
|
||||
e = raises(ValueError, Subclass, name)
|
||||
assert str(e) == "kwarg 'convert' conflicts with attribute on Subclass"
|
||||
|
||||
# Test type validation of keyword arguments:
|
||||
class Subclass(self.cls):
|
||||
@@ -488,10 +471,10 @@ class test_Param(ClassChecker):
|
||||
|
||||
# Test with wrong (scalar) type:
|
||||
e = raises(TypeError, o.validate, (None, None, 42, None), 'cli')
|
||||
assert str(e) == TYPE_ERROR % ('my_param', type(None), 42, int)
|
||||
assert str(e) == TYPE_ERROR % ('my_param', NoneType, 42, int)
|
||||
o = self.cls('my_param')
|
||||
e = raises(TypeError, o.validate, 'Hello', 'cli')
|
||||
assert str(e) == TYPE_ERROR % ('my_param', type(None), 'Hello', str)
|
||||
assert str(e) == TYPE_ERROR % ('my_param', NoneType, 'Hello', str)
|
||||
|
||||
class Example(self.cls):
|
||||
type = int
|
||||
@@ -610,8 +593,6 @@ class test_Param(ClassChecker):
|
||||
type = unicode
|
||||
|
||||
def __init__(self, name, **kw):
|
||||
# (Pylint complains because the superclass is unknowm)
|
||||
# pylint: disable=bad-super-call, super-on-old-class
|
||||
self._convert_scalar = PassThrough()
|
||||
super(Str, self).__init__(name, **kw)
|
||||
|
||||
@@ -658,7 +639,7 @@ class test_Flag(ClassChecker):
|
||||
|
||||
# Test that TypeError is raise if default is not a bool:
|
||||
e = raises(TypeError, self.cls, 'my_flag', default=None)
|
||||
assert str(e) == TYPE_ERROR % ('default', bool, None, type(None))
|
||||
assert str(e) == TYPE_ERROR % ('default', bool, None, NoneType)
|
||||
|
||||
# Test with autofill=False, default=True
|
||||
o = self.cls('my_flag', autofill=False, default=True)
|
||||
@@ -693,7 +674,7 @@ class test_Data(ClassChecker):
|
||||
Test the `ipalib.parameters.Data.__init__` method.
|
||||
"""
|
||||
o = self.cls('my_data')
|
||||
assert o.type is type(None)
|
||||
assert o.type is NoneType
|
||||
assert o.password is False
|
||||
assert o.rules == tuple()
|
||||
assert o.class_rules == tuple()
|
||||
@@ -701,6 +682,7 @@ class test_Data(ClassChecker):
|
||||
assert o.minlength is None
|
||||
assert o.maxlength is None
|
||||
assert o.length is None
|
||||
assert o.pattern is None
|
||||
|
||||
# Test mixing length with minlength or maxlength:
|
||||
o = self.cls('my_data', length=5)
|
||||
@@ -712,7 +694,7 @@ class test_Data(ClassChecker):
|
||||
]
|
||||
for kw in permutations:
|
||||
o = self.cls('my_data', **kw)
|
||||
for (key, value) in kw.items():
|
||||
for (key, value) in kw.iteritems():
|
||||
assert getattr(o, key) == value
|
||||
e = raises(ValueError, self.cls, 'my_data', length=5, **kw)
|
||||
assert str(e) == \
|
||||
@@ -746,7 +728,7 @@ class test_Bytes(ClassChecker):
|
||||
Test the `ipalib.parameters.Bytes.__init__` method.
|
||||
"""
|
||||
o = self.cls('my_bytes')
|
||||
assert o.type is bytes
|
||||
assert o.type is str
|
||||
assert o.password is False
|
||||
assert o.rules == tuple()
|
||||
assert o.class_rules == tuple()
|
||||
@@ -773,7 +755,7 @@ class test_Bytes(ClassChecker):
|
||||
assert len(o.class_rules) == len(kw)
|
||||
assert len(o.rules) == 0
|
||||
assert len(o.all_rules) == len(kw)
|
||||
for (key, value) in kw.items():
|
||||
for (key, value) in kw.iteritems():
|
||||
assert getattr(o, key) == value
|
||||
e = raises(ValueError, self.cls, 'my_bytes', length=5, **kw)
|
||||
assert str(e) == \
|
||||
@@ -807,12 +789,12 @@ class test_Bytes(ClassChecker):
|
||||
assert dummy.translation is translation
|
||||
|
||||
# Test with passing values:
|
||||
for value in (b'abc', b'four', b'12345'):
|
||||
for value in ('abc', 'four', '12345'):
|
||||
assert rule(dummy, value) is None
|
||||
assert dummy.called() is False
|
||||
|
||||
# Test with failing values:
|
||||
for value in (b'', b'a', b'12'):
|
||||
for value in ('', 'a', '12'):
|
||||
assert_equal(
|
||||
rule(dummy, value),
|
||||
translation % dict(minlength=3)
|
||||
@@ -833,12 +815,12 @@ class test_Bytes(ClassChecker):
|
||||
assert dummy.translation is translation
|
||||
|
||||
# Test with passing values:
|
||||
for value in (b'ab', b'123', b'four'):
|
||||
for value in ('ab', '123', 'four'):
|
||||
assert rule(dummy, value) is None
|
||||
assert dummy.called() is False
|
||||
|
||||
# Test with failing values:
|
||||
for value in (b'12345', b'sixsix'):
|
||||
for value in ('12345', 'sixsix'):
|
||||
assert_equal(
|
||||
rule(dummy, value),
|
||||
translation % dict(maxlength=4)
|
||||
@@ -859,12 +841,12 @@ class test_Bytes(ClassChecker):
|
||||
assert dummy.translation is translation
|
||||
|
||||
# Test with passing values:
|
||||
for value in (b'1234', b'four'):
|
||||
for value in ('1234', 'four'):
|
||||
assert rule(dummy, value) is None
|
||||
assert dummy.called() is False
|
||||
|
||||
# Test with failing values:
|
||||
for value in (b'ab', b'123', b'12345', b'sixsix'):
|
||||
for value in ('ab', '123', '12345', 'sixsix'):
|
||||
assert_equal(
|
||||
rule(dummy, value),
|
||||
translation % dict(length=4),
|
||||
@@ -878,9 +860,9 @@ class test_Bytes(ClassChecker):
|
||||
Test the `ipalib.parameters.Bytes._rule_pattern` method.
|
||||
"""
|
||||
# Test our assumptions about Python re module and Unicode:
|
||||
pat = b'\w+$'
|
||||
pat = '\w+$'
|
||||
r = re.compile(pat)
|
||||
assert r.match(b'Hello_World') is not None
|
||||
assert r.match('Hello_World') is not None
|
||||
assert r.match(utf8_bytes) is None
|
||||
assert r.match(binary_bytes) is None
|
||||
|
||||
@@ -892,12 +874,12 @@ class test_Bytes(ClassChecker):
|
||||
dummy = dummy_ugettext(translation)
|
||||
|
||||
# Test with passing values:
|
||||
for value in (b'HELLO', b'hello', b'Hello_World'):
|
||||
for value in ('HELLO', 'hello', 'Hello_World'):
|
||||
assert rule(dummy, value) is None
|
||||
assert dummy.called() is False
|
||||
|
||||
# Test with failing values:
|
||||
for value in (b'Hello!', b'Hello World', utf8_bytes, binary_bytes):
|
||||
for value in ('Hello!', 'Hello World', utf8_bytes, binary_bytes):
|
||||
assert_equal(
|
||||
rule(dummy, value),
|
||||
translation % dict(pattern=pat),
|
||||
@@ -933,7 +915,7 @@ class test_Str(ClassChecker):
|
||||
mthd = o._convert_scalar
|
||||
for value in (u'Hello', 42, 1.2, unicode_str):
|
||||
assert mthd(value) == unicode(value)
|
||||
bad = [True, b'Hello', dict(one=1), utf8_bytes]
|
||||
bad = [True, 'Hello', dict(one=1), utf8_bytes]
|
||||
for value in bad:
|
||||
e = raises(errors.ConversionError, mthd, value)
|
||||
assert e.name == 'my_str'
|
||||
@@ -1037,10 +1019,7 @@ class test_Str(ClassChecker):
|
||||
pat = '\w{5}$'
|
||||
r1 = re.compile(pat)
|
||||
r2 = re.compile(pat, re.UNICODE)
|
||||
if six.PY2:
|
||||
assert r1.match(unicode_str) is None
|
||||
else:
|
||||
assert r1.match(unicode_str) is not None
|
||||
assert r1.match(unicode_str) is None
|
||||
assert r2.match(unicode_str) is not None
|
||||
|
||||
# Create instance:
|
||||
@@ -1176,8 +1155,8 @@ class test_StrEnum(EnumChecker):
|
||||
_name = 'my_strenum'
|
||||
_datatype = unicode
|
||||
_test_values = u'Hello', u'naughty', u'nurse!'
|
||||
_bad_type_values = u'Hello', b'naughty', u'nurse!'
|
||||
_bad_type = bytes
|
||||
_bad_type_values = u'Hello', 'naughty', u'nurse!'
|
||||
_bad_type = str
|
||||
_translation = u"values='Hello', 'naughty', 'nurse!'"
|
||||
_bad_values = u'Howdy', u'quiet', u'library!'
|
||||
_single_value_translation = u"value='Hello'"
|
||||
@@ -1196,9 +1175,9 @@ def check_int_scalar_conversions(o):
|
||||
assert e.name == 'my_number'
|
||||
assert e.index is None
|
||||
# Assure large magnitude values are handled correctly
|
||||
assert type(o._convert_scalar(sys.maxsize * 2)) == long
|
||||
assert o._convert_scalar(sys.maxsize * 2) == sys.maxsize * 2
|
||||
assert o._convert_scalar(unicode(sys.maxsize * 2)) == sys.maxsize * 2
|
||||
assert type(o._convert_scalar(sys.maxint * 2)) == long
|
||||
assert o._convert_scalar(sys.maxint * 2) == sys.maxint * 2
|
||||
assert o._convert_scalar(unicode(sys.maxint * 2)) == sys.maxint * 2
|
||||
assert o._convert_scalar(long(16)) == 16
|
||||
# Assure normal conversions produce expected result
|
||||
assert o._convert_scalar(u'16.99') == 16
|
||||
@@ -1206,7 +1185,6 @@ def check_int_scalar_conversions(o):
|
||||
assert o._convert_scalar(u'16') == 16
|
||||
assert o._convert_scalar(u'0x10') == 16
|
||||
assert o._convert_scalar(u'020') == 16
|
||||
assert o._convert_scalar(u'0o20') == 16
|
||||
|
||||
|
||||
class test_IntEnum(EnumChecker):
|
||||
@@ -1242,7 +1220,7 @@ class test_Number(ClassChecker):
|
||||
Test the `ipalib.parameters.Number.__init__` method.
|
||||
"""
|
||||
o = self.cls('my_number')
|
||||
assert o.type is type(None)
|
||||
assert o.type is NoneType
|
||||
assert o.password is False
|
||||
assert o.rules == tuple()
|
||||
assert o.class_rules == tuple()
|
||||
@@ -1263,7 +1241,7 @@ class test_Int(ClassChecker):
|
||||
# Test with no kwargs:
|
||||
o = self.cls('my_number')
|
||||
assert o.type == int
|
||||
assert o.allowed_types == six.integer_types
|
||||
assert o.allowed_types == (int, long)
|
||||
assert isinstance(o, parameters.Int)
|
||||
assert o.minvalue == int(MININT)
|
||||
assert o.maxvalue == int(MAXINT)
|
||||
@@ -1441,7 +1419,8 @@ class test_Decimal(ClassChecker):
|
||||
param = self.cls('my_number', precision=1)
|
||||
e = raises(ConversionError, param, '123456789012345678901234567890')
|
||||
|
||||
assert str(e).startswith("invalid 'my_number': ")
|
||||
assert str(e) == \
|
||||
"invalid 'my_number': quantize result has too many digits for current context"
|
||||
|
||||
def test_exponential(self):
|
||||
"""
|
||||
@@ -1562,11 +1541,7 @@ def test_create_param():
|
||||
assert p.multivalue is kw['multivalue']
|
||||
|
||||
# Test that TypeError is raised when spec is neither a Param nor a str:
|
||||
if six.PY2:
|
||||
bad_value = u'one'
|
||||
else:
|
||||
bad_value = b'one'
|
||||
for spec in (bad_value, 42, parameters.Param, parameters.Str):
|
||||
for spec in (u'one', 42, parameters.Param, parameters.Str):
|
||||
e = raises(TypeError, f, spec)
|
||||
assert str(e) == \
|
||||
TYPE_ERROR % ('spec', (str, parameters.Param), spec, type(spec))
|
||||
@@ -1605,10 +1580,7 @@ class test_IA5Str(ClassChecker):
|
||||
e = raises(errors.ConversionError, mthd, value)
|
||||
assert e.name == 'my_str'
|
||||
assert e.index is None
|
||||
if six.PY2:
|
||||
assert_equal(e.error, "The character '\\xc3' is not allowed.")
|
||||
else:
|
||||
assert_equal(e.error, "The character 'á' is not allowed.")
|
||||
assert_equal(e.error, "The character '\\xc3' is not allowed.")
|
||||
|
||||
|
||||
class test_DateTime(ClassChecker):
|
||||
@@ -1653,4 +1625,4 @@ class test_DateTime(ClassChecker):
|
||||
u'1991-31-12Z',
|
||||
u'1991-12-07T25:30:05Z',
|
||||
):
|
||||
raises(ConversionError, o.convert, value)
|
||||
raises(ConversionError, o.convert, value)
|
||||
@@ -21,9 +21,6 @@
|
||||
Test the `ipalib.plugable` module.
|
||||
"""
|
||||
|
||||
# FIXME: Pylint errors
|
||||
# pylint: disable=no-member
|
||||
|
||||
import inspect
|
||||
from ipatests.util import raises, no_set, no_del, read_only
|
||||
from ipatests.util import getitem, setitem, delitem
|
||||
@@ -31,9 +28,176 @@ from ipatests.util import ClassChecker, create_test_api
|
||||
from ipalib import plugable, errors, text
|
||||
from ipaplatform.paths import paths
|
||||
|
||||
import pytest
|
||||
|
||||
pytestmark = pytest.mark.tier0
|
||||
class test_SetProxy(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.plugable.SetProxy` class.
|
||||
"""
|
||||
_cls = plugable.SetProxy
|
||||
|
||||
def test_class(self):
|
||||
"""
|
||||
Test the `ipalib.plugable.SetProxy` class.
|
||||
"""
|
||||
assert self.cls.__bases__ == (plugable.ReadOnly,)
|
||||
|
||||
def test_init(self):
|
||||
"""
|
||||
Test the `ipalib.plugable.SetProxy.__init__` method.
|
||||
"""
|
||||
okay = (set, frozenset, dict)
|
||||
fail = (list, tuple)
|
||||
for t in okay:
|
||||
self.cls(t())
|
||||
raises(TypeError, self.cls, t)
|
||||
for t in fail:
|
||||
raises(TypeError, self.cls, t())
|
||||
raises(TypeError, self.cls, t)
|
||||
|
||||
def test_SetProxy(self):
|
||||
"""
|
||||
Test container emulation of `ipalib.plugable.SetProxy` class.
|
||||
"""
|
||||
def get_key(i):
|
||||
return 'key_%d' % i
|
||||
|
||||
cnt = 10
|
||||
target = set()
|
||||
proxy = self.cls(target)
|
||||
for i in xrange(cnt):
|
||||
key = get_key(i)
|
||||
|
||||
# Check initial state
|
||||
assert len(proxy) == len(target)
|
||||
assert list(proxy) == sorted(target)
|
||||
assert key not in proxy
|
||||
assert key not in target
|
||||
|
||||
# Add and test again
|
||||
target.add(key)
|
||||
assert len(proxy) == len(target)
|
||||
assert list(proxy) == sorted(target)
|
||||
assert key in proxy
|
||||
assert key in target
|
||||
|
||||
|
||||
class test_DictProxy(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.plugable.DictProxy` class.
|
||||
"""
|
||||
_cls = plugable.DictProxy
|
||||
|
||||
def test_class(self):
|
||||
"""
|
||||
Test the `ipalib.plugable.DictProxy` class.
|
||||
"""
|
||||
assert self.cls.__bases__ == (plugable.SetProxy,)
|
||||
|
||||
def test_init(self):
|
||||
"""
|
||||
Test the `ipalib.plugable.DictProxy.__init__` method.
|
||||
"""
|
||||
self.cls(dict())
|
||||
raises(TypeError, self.cls, dict)
|
||||
fail = (set, frozenset, list, tuple)
|
||||
for t in fail:
|
||||
raises(TypeError, self.cls, t())
|
||||
raises(TypeError, self.cls, t)
|
||||
|
||||
def test_DictProxy(self):
|
||||
"""
|
||||
Test container emulation of `ipalib.plugable.DictProxy` class.
|
||||
"""
|
||||
def get_kv(i):
|
||||
return (
|
||||
'key_%d' % i,
|
||||
'val_%d' % i,
|
||||
)
|
||||
cnt = 10
|
||||
target = dict()
|
||||
proxy = self.cls(target)
|
||||
for i in xrange(cnt):
|
||||
(key, val) = get_kv(i)
|
||||
|
||||
# Check initial state
|
||||
assert len(proxy) == len(target)
|
||||
assert list(proxy) == sorted(target)
|
||||
assert list(proxy()) == [target[k] for k in sorted(target)]
|
||||
assert key not in proxy
|
||||
raises(KeyError, getitem, proxy, key)
|
||||
|
||||
# Add and test again
|
||||
target[key] = val
|
||||
assert len(proxy) == len(target)
|
||||
assert list(proxy) == sorted(target)
|
||||
assert list(proxy()) == [target[k] for k in sorted(target)]
|
||||
|
||||
# Verify TypeError is raised trying to set/del via proxy
|
||||
raises(TypeError, setitem, proxy, key, val)
|
||||
raises(TypeError, delitem, proxy, key)
|
||||
|
||||
|
||||
class test_MagicDict(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.plugable.MagicDict` class.
|
||||
"""
|
||||
_cls = plugable.MagicDict
|
||||
|
||||
def test_class(self):
|
||||
"""
|
||||
Test the `ipalib.plugable.MagicDict` class.
|
||||
"""
|
||||
assert self.cls.__bases__ == (plugable.DictProxy,)
|
||||
for non_dict in ('hello', 69, object):
|
||||
raises(TypeError, self.cls, non_dict)
|
||||
|
||||
def test_MagicDict(self):
|
||||
"""
|
||||
Test container emulation of `ipalib.plugable.MagicDict` class.
|
||||
"""
|
||||
cnt = 10
|
||||
keys = []
|
||||
d = dict()
|
||||
dictproxy = self.cls(d)
|
||||
for i in xrange(cnt):
|
||||
key = 'key_%d' % i
|
||||
val = 'val_%d' % i
|
||||
keys.append(key)
|
||||
|
||||
# Test thet key does not yet exist
|
||||
assert len(dictproxy) == i
|
||||
assert key not in dictproxy
|
||||
assert not hasattr(dictproxy, key)
|
||||
raises(KeyError, getitem, dictproxy, key)
|
||||
raises(AttributeError, getattr, dictproxy, key)
|
||||
|
||||
# Test that items/attributes cannot be set on dictproxy:
|
||||
raises(TypeError, setitem, dictproxy, key, val)
|
||||
raises(AttributeError, setattr, dictproxy, key, val)
|
||||
|
||||
# Test that additions in d are reflected in dictproxy:
|
||||
d[key] = val
|
||||
assert len(dictproxy) == i + 1
|
||||
assert key in dictproxy
|
||||
assert hasattr(dictproxy, key)
|
||||
assert dictproxy[key] is val
|
||||
assert read_only(dictproxy, key) is val
|
||||
|
||||
# Test __iter__
|
||||
assert list(dictproxy) == keys
|
||||
|
||||
for key in keys:
|
||||
# Test that items cannot be deleted through dictproxy:
|
||||
raises(TypeError, delitem, dictproxy, key)
|
||||
raises(AttributeError, delattr, dictproxy, key)
|
||||
|
||||
# Test that deletions in d are reflected in dictproxy
|
||||
del d[key]
|
||||
assert len(dictproxy) == len(d)
|
||||
assert key not in dictproxy
|
||||
raises(KeyError, getitem, dictproxy, key)
|
||||
raises(AttributeError, getattr, dictproxy, key)
|
||||
|
||||
|
||||
class test_Plugin(ClassChecker):
|
||||
"""
|
||||
@@ -52,8 +216,7 @@ class test_Plugin(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.plugable.Plugin.__init__` method.
|
||||
"""
|
||||
api = 'the api instance'
|
||||
o = self.cls(api)
|
||||
o = self.cls()
|
||||
assert o.name == 'Plugin'
|
||||
assert o.module == 'ipalib.plugable'
|
||||
assert o.fullname == 'ipalib.plugable.Plugin'
|
||||
@@ -68,7 +231,7 @@ class test_Plugin(ClassChecker):
|
||||
|
||||
One more paragraph.
|
||||
"""
|
||||
o = some_subclass(api)
|
||||
o = some_subclass()
|
||||
assert o.name == 'some_subclass'
|
||||
assert o.module == __name__
|
||||
assert o.fullname == '%s.some_subclass' % __name__
|
||||
@@ -76,30 +239,50 @@ class test_Plugin(ClassChecker):
|
||||
assert isinstance(o.doc, text.Gettext)
|
||||
class another_subclass(self.cls):
|
||||
pass
|
||||
o = another_subclass(api)
|
||||
o = another_subclass()
|
||||
assert o.summary == '<%s>' % o.fullname
|
||||
|
||||
# Test that Plugin makes sure the subclass hasn't defined attributes
|
||||
# whose names conflict with the logger methods set in Plugin.__init__():
|
||||
class check(self.cls):
|
||||
info = 'whatever'
|
||||
e = raises(Exception, check, api)
|
||||
e = raises(StandardError, check)
|
||||
assert str(e) == \
|
||||
"info is already bound to ipatests.test_ipalib.test_plugable.check()"
|
||||
|
||||
def test_set_api(self):
|
||||
"""
|
||||
Test the `ipalib.plugable.Plugin.set_api` method.
|
||||
"""
|
||||
api = 'the api instance'
|
||||
o = self.cls()
|
||||
assert o.api is None
|
||||
e = raises(AssertionError, o.set_api, None)
|
||||
assert str(e) == 'set_api() argument cannot be None'
|
||||
o.set_api(api)
|
||||
assert o.api is api
|
||||
e = raises(AssertionError, o.set_api, api)
|
||||
assert str(e) == 'set_api() can only be called once'
|
||||
|
||||
def test_finalize(self):
|
||||
"""
|
||||
Test the `ipalib.plugable.Plugin.finalize` method.
|
||||
"""
|
||||
class api(object):
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
o = self.cls(api)
|
||||
o = self.cls()
|
||||
assert not o.__islocked__()
|
||||
o.finalize()
|
||||
assert o.__islocked__()
|
||||
|
||||
def test_call(self):
|
||||
"""
|
||||
Test the `ipalib.plugable.Plugin.call` method.
|
||||
"""
|
||||
o = self.cls()
|
||||
o.call(paths.BIN_TRUE) is None
|
||||
e = raises(errors.SubprocessError, o.call, paths.BIN_FALSE)
|
||||
assert e.returncode == 1
|
||||
assert e.argv == (paths.BIN_FALSE,)
|
||||
|
||||
|
||||
def test_Registrar():
|
||||
"""
|
||||
@@ -119,7 +302,19 @@ def test_Registrar():
|
||||
pass
|
||||
|
||||
# Test creation of Registrar:
|
||||
r = plugable.Registrar()
|
||||
r = plugable.Registrar(Base1, Base2)
|
||||
|
||||
# Test __iter__:
|
||||
assert list(r) == ['Base1', 'Base2']
|
||||
|
||||
# Test __hasitem__, __getitem__:
|
||||
for base in [Base1, Base2]:
|
||||
name = base.__name__
|
||||
assert name in r
|
||||
assert r[name] is base
|
||||
magic = getattr(r, name)
|
||||
assert type(magic) is plugable.MagicDict
|
||||
assert len(magic) == 0
|
||||
|
||||
# Check that TypeError is raised trying to register something that isn't
|
||||
# a class:
|
||||
@@ -127,33 +322,52 @@ def test_Registrar():
|
||||
e = raises(TypeError, r, p)
|
||||
assert str(e) == 'plugin must be a class; got %r' % p
|
||||
|
||||
# Check that SubclassError is raised trying to register a class that is
|
||||
# not a subclass of an allowed base:
|
||||
e = raises(errors.PluginSubclassError, r, plugin3)
|
||||
assert e.plugin is plugin3
|
||||
|
||||
# Check that registration works
|
||||
r(plugin1)
|
||||
assert len(r) == 1
|
||||
assert plugin1 in r
|
||||
assert r[plugin1] == dict(override=False)
|
||||
assert len(r.Base1) == 1
|
||||
assert r.Base1['plugin1'] is plugin1
|
||||
assert r.Base1.plugin1 is plugin1
|
||||
|
||||
# Check that DuplicateError is raised trying to register exact class
|
||||
# again:
|
||||
e = raises(errors.PluginDuplicateError, r, plugin1)
|
||||
assert e.plugin is plugin1
|
||||
|
||||
# Check that overriding works
|
||||
# Check that OverrideError is raised trying to register class with same
|
||||
# name and same base:
|
||||
orig1 = plugin1
|
||||
class base1_extended(Base1):
|
||||
pass
|
||||
class plugin1(base1_extended): # pylint: disable=function-redefined
|
||||
class plugin1(base1_extended):
|
||||
pass
|
||||
e = raises(errors.PluginOverrideError, r, plugin1)
|
||||
assert e.base == 'Base1'
|
||||
assert e.name == 'plugin1'
|
||||
assert e.plugin is plugin1
|
||||
|
||||
# Check that overriding works
|
||||
r(plugin1, override=True)
|
||||
assert len(r) == 2
|
||||
assert plugin1 in r
|
||||
assert r[plugin1] == dict(override=True)
|
||||
assert len(r.Base1) == 1
|
||||
assert r.Base1.plugin1 is plugin1
|
||||
assert r.Base1.plugin1 is not orig1
|
||||
|
||||
# Check that MissingOverrideError is raised trying to override a name
|
||||
# not yet registerd:
|
||||
e = raises(errors.PluginMissingOverrideError, r, plugin2, override=True)
|
||||
assert e.base == 'Base2'
|
||||
assert e.name == 'plugin2'
|
||||
assert e.plugin is plugin2
|
||||
|
||||
# Test that another plugin can be registered:
|
||||
assert len(r.Base2) == 0
|
||||
r(plugin2)
|
||||
assert len(r) == 3
|
||||
assert plugin2 in r
|
||||
assert r[plugin2] == dict(override=False)
|
||||
assert len(r.Base2) == 1
|
||||
assert r.Base2.plugin2 is plugin2
|
||||
|
||||
# Setup to test more registration:
|
||||
class plugin1a(Base1):
|
||||
@@ -172,6 +386,18 @@ def test_Registrar():
|
||||
pass
|
||||
r(plugin2b)
|
||||
|
||||
# Again test __hasitem__, __getitem__:
|
||||
for base in [Base1, Base2]:
|
||||
name = base.__name__
|
||||
assert name in r
|
||||
assert r[name] is base
|
||||
magic = getattr(r, name)
|
||||
assert len(magic) == 3
|
||||
for key in magic:
|
||||
klass = magic[key]
|
||||
assert getattr(magic, key) is klass
|
||||
assert issubclass(klass, base)
|
||||
|
||||
|
||||
class test_API(ClassChecker):
|
||||
"""
|
||||
@@ -195,14 +421,12 @@ class test_API(ClassChecker):
|
||||
def method(self, n):
|
||||
return n + 1
|
||||
|
||||
class API(plugable.API):
|
||||
bases = (base0, base1)
|
||||
modules = ()
|
||||
|
||||
api = API()
|
||||
api = plugable.API(base0, base1)
|
||||
api.env.mode = 'unit_test'
|
||||
api.env.in_tree = True
|
||||
r = api.add_plugin
|
||||
r = api.register
|
||||
assert isinstance(r, plugable.Registrar)
|
||||
assert read_only(api, 'register') is r
|
||||
|
||||
class base0_plugin0(base0):
|
||||
pass
|
||||
@@ -242,14 +466,14 @@ class test_API(ClassChecker):
|
||||
def get_plugin_name(b, p):
|
||||
return 'base%d_plugin%d' % (b, p)
|
||||
|
||||
for b in range(2):
|
||||
for b in xrange(2):
|
||||
base_name = get_base_name(b)
|
||||
base = locals()[base_name]
|
||||
ns = getattr(api, base_name)
|
||||
assert isinstance(ns, plugable.NameSpace)
|
||||
assert read_only(api, base_name) is ns
|
||||
assert len(ns) == 3
|
||||
for p in range(3):
|
||||
for p in xrange(3):
|
||||
plugin_name = get_plugin_name(b, p)
|
||||
plugin = locals()[plugin_name]
|
||||
inst = ns[plugin_name]
|
||||
@@ -260,7 +484,7 @@ class test_API(ClassChecker):
|
||||
assert inst.method(7) == 7 + b
|
||||
|
||||
# Test that calling finilize again raises AssertionError:
|
||||
e = raises(Exception, api.finalize)
|
||||
e = raises(StandardError, api.finalize)
|
||||
assert str(e) == 'API.finalize() already called', str(e)
|
||||
|
||||
def test_bootstrap(self):
|
||||
@@ -276,7 +500,7 @@ class test_API(ClassChecker):
|
||||
assert o.env._isdone('_bootstrap') is True
|
||||
assert o.env._isdone('_finalize_core') is True
|
||||
assert o.env.my_test_override == 'Hello, world!'
|
||||
e = raises(Exception, o.bootstrap)
|
||||
e = raises(StandardError, o.bootstrap)
|
||||
assert str(e) == 'API.bootstrap() already called'
|
||||
|
||||
def test_load_plugins(self):
|
||||
@@ -289,5 +513,5 @@ class test_API(ClassChecker):
|
||||
o.load_plugins()
|
||||
assert o.isdone('bootstrap') is True
|
||||
assert o.isdone('load_plugins') is True
|
||||
e = raises(Exception, o.load_plugins)
|
||||
e = raises(StandardError, o.load_plugins)
|
||||
assert str(e) == 'API.load_plugins() already called'
|
||||
|
||||
@@ -20,13 +20,10 @@
|
||||
"""
|
||||
Test the `ipalib.rpc` module.
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
from six.moves.xmlrpc_client import Binary, Fault, dumps, loads
|
||||
from xmlrpclib import Binary, Fault, dumps, loads
|
||||
|
||||
import nose
|
||||
import six
|
||||
|
||||
from ipatests.util import raises, assert_equal, PluginTester, DummyClass
|
||||
from ipatests.data import binary_bytes, utf8_bytes, unicode_str
|
||||
from ipalib.frontend import Command
|
||||
@@ -34,9 +31,6 @@ from ipalib.request import context, Connection
|
||||
from ipalib import rpc, errors, api, request
|
||||
from ipapython.version import API_VERSION
|
||||
|
||||
if six.PY3:
|
||||
unicode = str
|
||||
|
||||
|
||||
std_compound = (binary_bytes, utf8_bytes, unicode_str)
|
||||
|
||||
@@ -58,39 +52,32 @@ def test_round_trip():
|
||||
"""
|
||||
Test `ipalib.rpc.xml_wrap` and `ipalib.rpc.xml_unwrap`.
|
||||
|
||||
This tests the two functions together with ``xmlrpc.client.dumps()`` and
|
||||
``xmlrpc.client.loads()`` in a full wrap/dumps/loads/unwrap round trip.
|
||||
This tests the two functions together with ``xmlrpclib.dumps()`` and
|
||||
``xmlrpclib.loads()`` in a full wrap/dumps/loads/unwrap round trip.
|
||||
"""
|
||||
# We first test that our assumptions about xmlrpc.client module in the Python
|
||||
# We first test that our assumptions about xmlrpclib module in the Python
|
||||
# standard library are correct:
|
||||
if six.PY2:
|
||||
output_binary_type = bytes
|
||||
else:
|
||||
output_binary_type = Binary
|
||||
|
||||
if six.PY2:
|
||||
assert_equal(dump_n_load(utf8_bytes), unicode_str)
|
||||
assert_equal(dump_n_load(utf8_bytes), unicode_str)
|
||||
assert_equal(dump_n_load(unicode_str), unicode_str)
|
||||
# "Binary" is not "str". pylint: disable=no-member
|
||||
assert_equal(dump_n_load(Binary(binary_bytes)).data, binary_bytes)
|
||||
assert isinstance(dump_n_load(Binary(binary_bytes)), Binary)
|
||||
assert type(dump_n_load(b'hello')) is output_binary_type
|
||||
assert type(dump_n_load('hello')) is str
|
||||
assert type(dump_n_load(u'hello')) is str
|
||||
assert_equal(dump_n_load(b''), output_binary_type(b''))
|
||||
assert_equal(dump_n_load(u''), str())
|
||||
assert_equal(dump_n_load(''), '')
|
||||
assert_equal(dump_n_load(u''), '')
|
||||
assert dump_n_load(None) is None
|
||||
|
||||
# Now we test our wrap and unwrap methods in combination with dumps, loads:
|
||||
# All bytes should come back bytes (because they get wrapped in
|
||||
# xmlrpc.client.Binary(). All unicode should come back unicode because str
|
||||
# All str should come back str (because they get wrapped in
|
||||
# xmlrpclib.Binary(). All unicode should come back unicode because str
|
||||
# explicity get decoded by rpc.xml_unwrap() if they weren't already
|
||||
# decoded by xmlrpc.client.loads().
|
||||
# decoded by xmlrpclib.loads().
|
||||
assert_equal(round_trip(utf8_bytes), utf8_bytes)
|
||||
assert_equal(round_trip(unicode_str), unicode_str)
|
||||
assert_equal(round_trip(binary_bytes), binary_bytes)
|
||||
assert type(round_trip(b'hello')) is bytes
|
||||
assert type(round_trip('hello')) is str
|
||||
assert type(round_trip(u'hello')) is unicode
|
||||
assert_equal(round_trip(b''), b'')
|
||||
assert_equal(round_trip(''), '')
|
||||
assert_equal(round_trip(u''), u'')
|
||||
assert round_trip(None) is None
|
||||
compound = [utf8_bytes, None, binary_bytes, (None, unicode_str),
|
||||
@@ -106,14 +93,13 @@ def test_xml_wrap():
|
||||
f = rpc.xml_wrap
|
||||
assert f([], API_VERSION) == tuple()
|
||||
assert f({}, API_VERSION) == dict()
|
||||
b = f(b'hello', API_VERSION)
|
||||
b = f('hello', API_VERSION)
|
||||
assert isinstance(b, Binary)
|
||||
# "Binary" is not "dict" or "tuple". pylint: disable=no-member
|
||||
assert b.data == b'hello'
|
||||
assert b.data == 'hello'
|
||||
u = f(u'hello', API_VERSION)
|
||||
assert type(u) is unicode
|
||||
assert u == u'hello'
|
||||
value = f([dict(one=False, two=u'hello'), None, b'hello'], API_VERSION)
|
||||
value = f([dict(one=False, two=u'hello'), None, 'hello'], API_VERSION)
|
||||
|
||||
|
||||
def test_xml_unwrap():
|
||||
@@ -124,13 +110,13 @@ def test_xml_unwrap():
|
||||
assert f([]) == tuple()
|
||||
assert f({}) == dict()
|
||||
value = f(Binary(utf8_bytes))
|
||||
assert type(value) is bytes
|
||||
assert type(value) is str
|
||||
assert value == utf8_bytes
|
||||
assert f(utf8_bytes) == unicode_str
|
||||
assert f(unicode_str) == unicode_str
|
||||
value = f([True, Binary(b'hello'), dict(one=1, two=utf8_bytes, three=None)])
|
||||
assert value == (True, b'hello', dict(one=1, two=unicode_str, three=None))
|
||||
assert type(value[1]) is bytes
|
||||
value = f([True, Binary('hello'), dict(one=1, two=utf8_bytes, three=None)])
|
||||
assert value == (True, 'hello', dict(one=1, two=unicode_str, three=None))
|
||||
assert type(value[1]) is str
|
||||
assert type(value[2]['two']) is unicode
|
||||
|
||||
|
||||
@@ -243,9 +229,6 @@ class test_xmlclient(PluginTester):
|
||||
),
|
||||
|
||||
)
|
||||
|
||||
# Create connection for the current thread
|
||||
setattr(context, o.id, Connection(conn, lambda: None))
|
||||
context.xmlclient = Connection(conn, lambda: None)
|
||||
|
||||
# Test with a successful return value:
|
||||
@@ -265,7 +248,7 @@ class test_xmlclient(PluginTester):
|
||||
|
||||
class test_xml_introspection(object):
|
||||
@classmethod
|
||||
def setup_class(self):
|
||||
def setUpClass(self):
|
||||
try:
|
||||
api.Backend.xmlclient.connect(fallback=False)
|
||||
except (errors.NetworkError, IOError):
|
||||
@@ -273,7 +256,7 @@ class test_xml_introspection(object):
|
||||
(__name__, api.env.xmlrpc_uri))
|
||||
|
||||
@classmethod
|
||||
def teardown_class(self):
|
||||
def tearDownClass(self):
|
||||
request.destroy_context()
|
||||
|
||||
def test_list_methods(self):
|
||||
@@ -288,8 +271,8 @@ class test_xml_introspection(object):
|
||||
def test_list_methods_many_params(self):
|
||||
try:
|
||||
result = api.Backend.xmlclient.conn.system.listMethods('foo')
|
||||
except Fault as f:
|
||||
print(f)
|
||||
except Fault, f:
|
||||
print f
|
||||
assert f.faultCode == 3003
|
||||
assert f.faultString == (
|
||||
"command 'system.listMethods' takes no arguments")
|
||||
@@ -308,8 +291,8 @@ class test_xml_introspection(object):
|
||||
def test_signature_no_params(self):
|
||||
try:
|
||||
result = api.Backend.xmlclient.conn.system.methodSignature()
|
||||
except Fault as f:
|
||||
print(f)
|
||||
except Fault, f:
|
||||
print f
|
||||
assert f.faultCode == 3007
|
||||
assert f.faultString == "'method name' is required"
|
||||
else:
|
||||
@@ -318,8 +301,8 @@ class test_xml_introspection(object):
|
||||
def test_signature_many_params(self):
|
||||
try:
|
||||
result = api.Backend.xmlclient.conn.system.methodSignature('a', 'b')
|
||||
except Fault as f:
|
||||
print(f)
|
||||
except Fault, f:
|
||||
print f
|
||||
assert f.faultCode == 3004
|
||||
assert f.faultString == (
|
||||
"command 'system.methodSignature' takes at most 1 argument")
|
||||
@@ -329,8 +312,8 @@ class test_xml_introspection(object):
|
||||
def test_help_no_params(self):
|
||||
try:
|
||||
result = api.Backend.xmlclient.conn.system.methodHelp()
|
||||
except Fault as f:
|
||||
print(f)
|
||||
except Fault, f:
|
||||
print f
|
||||
assert f.faultCode == 3007
|
||||
assert f.faultString == "'method name' is required"
|
||||
else:
|
||||
@@ -339,8 +322,8 @@ class test_xml_introspection(object):
|
||||
def test_help_many_params(self):
|
||||
try:
|
||||
result = api.Backend.xmlclient.conn.system.methodHelp('a', 'b')
|
||||
except Fault as f:
|
||||
print(f)
|
||||
except Fault, f:
|
||||
print f
|
||||
assert f.faultCode == 3004
|
||||
assert f.faultString == (
|
||||
"command 'system.methodHelp' takes at most 1 argument")
|
||||
|
||||
@@ -20,18 +20,13 @@
|
||||
"""
|
||||
Test the `ipalib.text` module.
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
import re
|
||||
|
||||
import nose
|
||||
import locale
|
||||
import six
|
||||
import pytest
|
||||
|
||||
from ipatests.util import raises, assert_equal
|
||||
from ipatests.i18n import create_po, po_file_iterate
|
||||
from ipalib.request import context
|
||||
@@ -39,11 +34,6 @@ from ipalib import request
|
||||
from ipalib import text
|
||||
from ipapython.ipautil import file_exists
|
||||
|
||||
if six.PY3:
|
||||
unicode = str
|
||||
|
||||
pytestmark = pytest.mark.tier0
|
||||
|
||||
singular = '%(count)d goose makes a %(dish)s'
|
||||
plural = '%(count)d geese make a %(dish)s'
|
||||
|
||||
@@ -56,7 +46,7 @@ def test_create_translation():
|
||||
|
||||
|
||||
class test_TestLang(object):
|
||||
def setup(self):
|
||||
def setUp(self):
|
||||
self.tmp_dir = None
|
||||
self.saved_lang = None
|
||||
|
||||
@@ -95,7 +85,7 @@ class test_TestLang(object):
|
||||
|
||||
self.po_file_iterate = po_file_iterate
|
||||
|
||||
def teardown(self):
|
||||
def tearDown(self):
|
||||
if self.saved_lang is not None:
|
||||
os.environ['LANG'] = self.saved_lang
|
||||
|
||||
@@ -103,7 +93,7 @@ class test_TestLang(object):
|
||||
shutil.rmtree(self.tmp_dir)
|
||||
|
||||
def test_test_lang(self):
|
||||
print("test_test_lang")
|
||||
print "test_test_lang"
|
||||
# The test installs the test message catalog under the xh_ZA
|
||||
# (e.g. Zambia Xhosa) language by default. It would be nice to
|
||||
# use a dummy language not associated with any real language,
|
||||
|
||||
@@ -21,18 +21,19 @@
|
||||
Test the `ipalib.x509` module.
|
||||
"""
|
||||
|
||||
import os
|
||||
from os import path
|
||||
import sys
|
||||
from ipatests.util import raises, setitem, delitem, ClassChecker
|
||||
from ipatests.util import getitem, setitem, delitem
|
||||
from ipatests.util import TempDir, TempHome
|
||||
from ipalib.constants import TYPE_ERROR, OVERRIDE_ERROR, SET_ERROR, DEL_ERROR
|
||||
from ipalib.constants import NAME_REGEX, NAME_ERROR
|
||||
import base64
|
||||
|
||||
import pytest
|
||||
from nss.error import NSPRError
|
||||
|
||||
from ipalib import x509
|
||||
from nss.error import NSPRError
|
||||
from ipapython.dn import DN
|
||||
|
||||
import pytest
|
||||
|
||||
pytestmark = pytest.mark.tier0
|
||||
|
||||
# certutil -
|
||||
|
||||
# certificate for CN=ipa.example.com,O=IPA
|
||||
@@ -65,12 +66,16 @@ class test_x509(object):
|
||||
|
||||
# Load a good cert with bad headers
|
||||
newcert = '-----BEGIN CERTIFICATE-----' + goodcert
|
||||
with pytest.raises((TypeError, ValueError)):
|
||||
try:
|
||||
cert = x509.load_certificate(newcert)
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
# Load a bad cert
|
||||
with pytest.raises(NSPRError):
|
||||
try:
|
||||
cert = x509.load_certificate(badcert)
|
||||
except NSPRError:
|
||||
pass
|
||||
|
||||
def test_1_load_der_cert(self):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user