Imported Upstream version 4.0.5
This commit is contained in:
@@ -26,15 +26,12 @@ import ldap
|
||||
from ipapython.dn import DN
|
||||
from ipapython import ipaldap
|
||||
from ipalib import errors
|
||||
from ipalib.frontend import Command
|
||||
from ipaserver.plugins import baseldap
|
||||
from ipalib.plugins import baseldap
|
||||
from ipatests.util import assert_deepequal
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.tier0
|
||||
def test_exc_wrapper():
|
||||
"""Test the BaseLDAPCommand._exc_wrapper helper method"""
|
||||
"""Test the CallbackInterface._exc_wrapper helper method"""
|
||||
handled_exceptions = []
|
||||
|
||||
class test_callback(baseldap.BaseLDAPCommand):
|
||||
@@ -47,14 +44,12 @@ def test_exc_wrapper():
|
||||
assert kwargs == dict(a=1, b=2)
|
||||
raise errors.ExecutionError('failure')
|
||||
|
||||
api = 'the api instance'
|
||||
instance = test_callback(api)
|
||||
instance = test_callback()
|
||||
|
||||
# Test with one callback first
|
||||
|
||||
@test_callback.register_exc_callback
|
||||
def handle_exception( # pylint: disable=unused-variable
|
||||
self, keys, options, e, call_func, *args, **kwargs):
|
||||
def handle_exception(self, keys, options, e, call_func, *args, **kwargs):
|
||||
assert args == (1, 2)
|
||||
assert kwargs == dict(a=1, b=2)
|
||||
handled_exceptions.append(type(e))
|
||||
@@ -77,10 +72,9 @@ def test_exc_wrapper():
|
||||
assert handled_exceptions == [None, errors.ExecutionError]
|
||||
|
||||
|
||||
@pytest.mark.tier0
|
||||
def test_callback_registration():
|
||||
class callbacktest_base(Command):
|
||||
callback_types = Command.callback_types + ('test',)
|
||||
class callbacktest_base(baseldap.CallbackInterface):
|
||||
_callback_registry = dict(test={})
|
||||
|
||||
def test_callback(self, param):
|
||||
messages.append(('Base test_callback', param))
|
||||
@@ -102,10 +96,8 @@ def test_callback_registration():
|
||||
callbacktest_subclass.register_callback('test', subclass_callback)
|
||||
|
||||
|
||||
api = 'the api instance'
|
||||
|
||||
messages = []
|
||||
instance = callbacktest_base(api)
|
||||
instance = callbacktest_base()
|
||||
for callback in instance.get_callbacks('test'):
|
||||
callback(instance, 42)
|
||||
assert messages == [
|
||||
@@ -114,7 +106,7 @@ def test_callback_registration():
|
||||
('Registered callback from another class', 42)]
|
||||
|
||||
messages = []
|
||||
instance = callbacktest_subclass(api)
|
||||
instance = callbacktest_subclass()
|
||||
for callback in instance.get_callbacks('test'):
|
||||
callback(instance, 42)
|
||||
assert messages == [
|
||||
@@ -122,7 +114,6 @@ def test_callback_registration():
|
||||
('Subclass registered callback', 42)]
|
||||
|
||||
|
||||
@pytest.mark.tier0
|
||||
def test_exc_callback_registration():
|
||||
messages = []
|
||||
class callbacktest_base(baseldap.BaseLDAPCommand):
|
||||
@@ -143,21 +134,18 @@ def test_exc_callback_registration():
|
||||
"""Raise an error"""
|
||||
raise errors.ExecutionError('failure')
|
||||
|
||||
api = 'the api instance'
|
||||
|
||||
base_instance = callbacktest_base(api)
|
||||
base_instance = callbacktest_base()
|
||||
|
||||
class callbacktest_subclass(callbacktest_base):
|
||||
pass
|
||||
|
||||
@callbacktest_subclass.register_exc_callback
|
||||
def exc_callback( # pylint: disable=unused-variable
|
||||
self, keys, options, exc, call_func, *args, **kwargs):
|
||||
def exc_callback(self, keys, options, exc, call_func, *args, **kwargs):
|
||||
"""Subclass's private exception callback"""
|
||||
messages.append('Subclass registered callback')
|
||||
raise exc
|
||||
|
||||
subclass_instance = callbacktest_subclass(api)
|
||||
subclass_instance = callbacktest_subclass()
|
||||
|
||||
# Make sure exception in base class is only handled by the base class
|
||||
base_instance.test_fail()
|
||||
@@ -165,8 +153,7 @@ def test_exc_callback_registration():
|
||||
|
||||
|
||||
@callbacktest_base.register_exc_callback
|
||||
def exc_callback_2( # pylint: disable=unused-variable
|
||||
self, keys, options, exc, call_func, *args, **kwargs):
|
||||
def exc_callback(self, keys, options, exc, call_func, *args, **kwargs):
|
||||
"""Callback on super class; doesn't affect the subclass"""
|
||||
messages.append('Superclass registered callback')
|
||||
raise exc
|
||||
@@ -177,7 +164,6 @@ def test_exc_callback_registration():
|
||||
assert messages == ['Base exc_callback', 'Subclass registered callback']
|
||||
|
||||
|
||||
@pytest.mark.tier0
|
||||
def test_entry_to_dict():
|
||||
class FakeAttributeType(object):
|
||||
def __init__(self, name, syntax):
|
||||
@@ -195,14 +181,13 @@ def test_entry_to_dict():
|
||||
elif name == 'dnattr':
|
||||
return FakeAttributeType(name, '1.3.6.1.4.1.1466.115.121.1.12')
|
||||
|
||||
class FakeLDAPClient(ipaldap.LDAPClient):
|
||||
class FakeIPASimpleLDAPObject(ipaldap.IPASimpleLDAPObject):
|
||||
def __init__(self):
|
||||
super(FakeLDAPClient, self).__init__('ldap://test',
|
||||
force_schema_updates=False)
|
||||
self._has_schema = True
|
||||
super(FakeIPASimpleLDAPObject, self).__init__('ldap://test', False)
|
||||
self._schema = FakeSchema()
|
||||
self._has_schema = True
|
||||
|
||||
conn = FakeLDAPClient()
|
||||
conn = FakeIPASimpleLDAPObject()
|
||||
rights = {'nothing': 'is'}
|
||||
|
||||
entry = ipaldap.LDAPEntry(
|
||||
@@ -210,13 +195,13 @@ def test_entry_to_dict():
|
||||
DN('cn=test'),
|
||||
textattr=[u'text'],
|
||||
dnattr=[DN('cn=test')],
|
||||
binaryattr=[b'\xffabcd'],
|
||||
binaryattr=['\xffabcd'],
|
||||
attributelevelrights=rights)
|
||||
the_dict = {
|
||||
u'dn': u'cn=test',
|
||||
u'textattr': [u'text'],
|
||||
u'dnattr': [u'cn=test'],
|
||||
u'binaryattr': [b'\xffabcd'],
|
||||
u'binaryattr': ['\xffabcd'],
|
||||
u'attributelevelrights': rights}
|
||||
assert_deepequal(
|
||||
baseldap.entry_to_dict(entry, all=True, raw=True),
|
||||
|
||||
Reference in New Issue
Block a user