2008-08-05 02:39:50 -05:00
|
|
|
# Authors:
|
|
|
|
# Jason Gerard DeRose <jderose@redhat.com>
|
|
|
|
#
|
|
|
|
# Copyright (C) 2008 Red Hat
|
|
|
|
# see file 'COPYING' for use and warranty information
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License as
|
|
|
|
# published by the Free Software Foundation; version 2 only
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
|
|
|
"""
|
2008-10-07 22:25:23 -05:00
|
|
|
Test the `ipalib.frontend` module.
|
2008-08-05 02:39:50 -05:00
|
|
|
"""
|
|
|
|
|
2008-10-08 01:58:53 -05:00
|
|
|
from tests.util import raises, getitem, no_set, no_del, read_only
|
2008-12-08 17:56:24 -06:00
|
|
|
from tests.util import check_TypeError, ClassChecker, create_test_api
|
2009-01-14 13:00:47 -06:00
|
|
|
from ipalib import frontend, backend, plugable, errors, parameters, config
|
2008-08-05 02:39:50 -05:00
|
|
|
|
|
|
|
|
2008-08-06 23:51:21 -05:00
|
|
|
def test_RULE_FLAG():
|
2008-09-23 19:01:29 -05:00
|
|
|
assert frontend.RULE_FLAG == 'validation_rule'
|
2008-08-06 23:51:21 -05:00
|
|
|
|
|
|
|
|
|
|
|
def test_rule():
|
2008-09-02 19:15:20 -05:00
|
|
|
"""
|
2008-10-08 01:58:53 -05:00
|
|
|
Test the `ipalib.frontend.rule` function.
|
2008-09-02 19:15:20 -05:00
|
|
|
"""
|
2008-09-23 19:01:29 -05:00
|
|
|
flag = frontend.RULE_FLAG
|
|
|
|
rule = frontend.rule
|
2008-08-08 12:11:29 -05:00
|
|
|
def my_func():
|
2008-08-08 16:40:03 -05:00
|
|
|
pass
|
2008-08-08 12:11:29 -05:00
|
|
|
assert not hasattr(my_func, flag)
|
|
|
|
rule(my_func)
|
|
|
|
assert getattr(my_func, flag) is True
|
|
|
|
@rule
|
|
|
|
def my_func2():
|
2008-08-08 16:40:03 -05:00
|
|
|
pass
|
2008-08-08 12:11:29 -05:00
|
|
|
assert getattr(my_func2, flag) is True
|
2008-08-06 23:51:21 -05:00
|
|
|
|
|
|
|
|
|
|
|
def test_is_rule():
|
2008-09-02 19:15:20 -05:00
|
|
|
"""
|
2008-10-08 01:58:53 -05:00
|
|
|
Test the `ipalib.frontend.is_rule` function.
|
2008-09-02 19:15:20 -05:00
|
|
|
"""
|
2008-09-23 19:01:29 -05:00
|
|
|
is_rule = frontend.is_rule
|
|
|
|
flag = frontend.RULE_FLAG
|
2008-08-06 23:51:21 -05:00
|
|
|
|
2008-08-08 12:11:29 -05:00
|
|
|
class no_call(object):
|
2008-08-08 16:40:03 -05:00
|
|
|
def __init__(self, value):
|
|
|
|
if value is not None:
|
|
|
|
assert value in (True, False)
|
|
|
|
setattr(self, flag, value)
|
2008-08-06 23:51:21 -05:00
|
|
|
|
2008-08-08 12:11:29 -05:00
|
|
|
class call(no_call):
|
2008-08-08 16:40:03 -05:00
|
|
|
def __call__(self):
|
|
|
|
pass
|
2008-08-06 23:51:21 -05:00
|
|
|
|
2008-08-08 12:11:29 -05:00
|
|
|
assert is_rule(call(True))
|
|
|
|
assert not is_rule(no_call(True))
|
|
|
|
assert not is_rule(call(False))
|
|
|
|
assert not is_rule(call(None))
|
2008-08-06 23:51:21 -05:00
|
|
|
|
|
|
|
|
2008-09-02 18:40:44 -05:00
|
|
|
class test_Command(ClassChecker):
|
2008-08-10 19:21:12 -05:00
|
|
|
"""
|
2008-10-08 01:58:53 -05:00
|
|
|
Test the `ipalib.frontend.Command` class.
|
2008-08-10 19:21:12 -05:00
|
|
|
"""
|
2008-10-08 01:58:53 -05:00
|
|
|
|
2008-09-23 19:01:29 -05:00
|
|
|
_cls = frontend.Command
|
2008-08-10 19:21:12 -05:00
|
|
|
|
|
|
|
def get_subcls(self):
|
2008-10-08 01:58:53 -05:00
|
|
|
"""
|
|
|
|
Return a standard subclass of `ipalib.frontend.Command`.
|
|
|
|
"""
|
2008-09-02 17:19:39 -05:00
|
|
|
class Rule(object):
|
|
|
|
def __init__(self, name):
|
|
|
|
self.name = name
|
|
|
|
|
|
|
|
def __call__(self, value):
|
2008-08-11 12:37:33 -05:00
|
|
|
if value != self.name:
|
2008-09-03 21:02:06 -05:00
|
|
|
return 'must equal %s' % self.name
|
2008-09-02 17:19:39 -05:00
|
|
|
|
2008-09-23 19:01:29 -05:00
|
|
|
default_from = frontend.DefaultFrom(
|
2008-09-02 17:19:39 -05:00
|
|
|
lambda arg: arg,
|
|
|
|
'default_from'
|
|
|
|
)
|
|
|
|
normalize = lambda value: value.lower()
|
2008-08-11 12:37:33 -05:00
|
|
|
|
2008-08-10 19:21:12 -05:00
|
|
|
class example(self.cls):
|
2008-09-10 09:46:20 -05:00
|
|
|
takes_options = (
|
2008-09-26 20:30:39 -05:00
|
|
|
frontend.Param('option0',
|
2008-09-02 17:19:39 -05:00
|
|
|
normalize=normalize,
|
|
|
|
default_from=default_from,
|
|
|
|
rules=(Rule('option0'),)
|
|
|
|
),
|
2008-09-26 20:30:39 -05:00
|
|
|
frontend.Param('option1',
|
2008-09-02 17:19:39 -05:00
|
|
|
normalize=normalize,
|
|
|
|
default_from=default_from,
|
|
|
|
rules=(Rule('option1'),),
|
|
|
|
required=True,
|
|
|
|
),
|
|
|
|
)
|
2008-08-10 19:21:12 -05:00
|
|
|
return example
|
|
|
|
|
2008-09-18 14:39:23 -05:00
|
|
|
def get_instance(self, args=tuple(), options=tuple()):
|
2008-09-10 09:46:20 -05:00
|
|
|
"""
|
|
|
|
Helper method used to test args and options.
|
|
|
|
"""
|
|
|
|
class example(self.cls):
|
|
|
|
takes_args = args
|
|
|
|
takes_options = options
|
2008-09-21 13:50:00 -05:00
|
|
|
o = example()
|
2008-09-21 16:50:56 -05:00
|
|
|
o.finalize()
|
2008-09-21 13:50:00 -05:00
|
|
|
return o
|
2008-09-10 09:46:20 -05:00
|
|
|
|
2008-09-18 18:15:34 -05:00
|
|
|
def test_class(self):
|
2008-10-08 01:58:53 -05:00
|
|
|
"""
|
|
|
|
Test the `ipalib.frontend.Command` class.
|
|
|
|
"""
|
2008-09-18 18:15:34 -05:00
|
|
|
assert self.cls.__bases__ == (plugable.Plugin,)
|
|
|
|
assert self.cls.takes_options == tuple()
|
|
|
|
assert self.cls.takes_args == tuple()
|
|
|
|
|
2008-09-09 16:18:44 -05:00
|
|
|
def test_get_args(self):
|
|
|
|
"""
|
2008-10-08 01:58:53 -05:00
|
|
|
Test the `ipalib.frontend.Command.get_args` method.
|
2008-09-09 16:18:44 -05:00
|
|
|
"""
|
|
|
|
assert list(self.cls().get_args()) == []
|
|
|
|
args = ('login', 'stuff')
|
2008-09-18 14:39:23 -05:00
|
|
|
o = self.get_instance(args=args)
|
2008-09-09 16:18:44 -05:00
|
|
|
assert o.get_args() is args
|
|
|
|
|
2008-09-10 09:46:20 -05:00
|
|
|
def test_get_options(self):
|
|
|
|
"""
|
2008-10-08 01:58:53 -05:00
|
|
|
Test the `ipalib.frontend.Command.get_options` method.
|
2008-09-10 09:46:20 -05:00
|
|
|
"""
|
|
|
|
assert list(self.cls().get_options()) == []
|
|
|
|
options = ('verbose', 'debug')
|
2008-09-18 14:39:23 -05:00
|
|
|
o = self.get_instance(options=options)
|
2008-09-10 09:46:20 -05:00
|
|
|
assert o.get_options() is options
|
2008-09-09 20:54:48 -05:00
|
|
|
|
2008-09-09 18:46:16 -05:00
|
|
|
def test_args(self):
|
|
|
|
"""
|
2008-10-08 01:58:53 -05:00
|
|
|
Test the ``ipalib.frontend.Command.args`` instance attribute.
|
2008-09-09 18:46:16 -05:00
|
|
|
"""
|
2008-09-09 20:54:48 -05:00
|
|
|
assert 'args' in self.cls.__public__ # Public
|
2008-09-21 13:50:00 -05:00
|
|
|
assert self.cls().args is None
|
|
|
|
o = self.cls()
|
2008-09-21 16:50:56 -05:00
|
|
|
o.finalize()
|
2008-09-21 13:50:00 -05:00
|
|
|
assert type(o.args) is plugable.NameSpace
|
|
|
|
assert len(o.args) == 0
|
2008-09-09 20:54:48 -05:00
|
|
|
args = ('destination', 'source?')
|
2008-09-18 14:39:23 -05:00
|
|
|
ns = self.get_instance(args=args).args
|
2008-09-09 20:54:48 -05:00
|
|
|
assert type(ns) is plugable.NameSpace
|
|
|
|
assert len(ns) == len(args)
|
|
|
|
assert list(ns) == ['destination', 'source']
|
2008-09-23 19:01:29 -05:00
|
|
|
assert type(ns.destination) is frontend.Param
|
|
|
|
assert type(ns.source) is frontend.Param
|
2008-09-09 20:54:48 -05:00
|
|
|
assert ns.destination.required is True
|
|
|
|
assert ns.destination.multivalue is False
|
|
|
|
assert ns.source.required is False
|
|
|
|
assert ns.source.multivalue is False
|
|
|
|
|
2008-09-10 09:54:01 -05:00
|
|
|
# Test TypeError:
|
2008-09-18 14:39:23 -05:00
|
|
|
e = raises(TypeError, self.get_instance, args=(u'whatever',))
|
2008-09-10 09:46:20 -05:00
|
|
|
assert str(e) == \
|
2008-09-23 19:01:29 -05:00
|
|
|
'create_param() takes %r or %r; got %r' % (str, frontend.Param, u'whatever')
|
2008-08-05 02:39:50 -05:00
|
|
|
|
2008-09-10 09:54:01 -05:00
|
|
|
# Test ValueError, required after optional:
|
2008-09-18 14:39:23 -05:00
|
|
|
e = raises(ValueError, self.get_instance, args=('arg1?', 'arg2'))
|
2008-09-10 09:54:01 -05:00
|
|
|
assert str(e) == 'arg2: required argument after optional'
|
|
|
|
|
|
|
|
# Test ValueError, scalar after multivalue:
|
2008-09-18 14:39:23 -05:00
|
|
|
e = raises(ValueError, self.get_instance, args=('arg1+', 'arg2'))
|
2008-09-10 09:54:01 -05:00
|
|
|
assert str(e) == 'arg2: only final argument can be multivalue'
|
|
|
|
|
2008-09-18 18:15:34 -05:00
|
|
|
def test_max_args(self):
|
|
|
|
"""
|
2008-10-08 01:58:53 -05:00
|
|
|
Test the ``ipalib.frontend.Command.max_args`` instance attribute.
|
2008-09-18 18:15:34 -05:00
|
|
|
"""
|
|
|
|
o = self.get_instance()
|
|
|
|
assert o.max_args == 0
|
|
|
|
o = self.get_instance(args=('one?',))
|
|
|
|
assert o.max_args == 1
|
|
|
|
o = self.get_instance(args=('one', 'two?'))
|
|
|
|
assert o.max_args == 2
|
|
|
|
o = self.get_instance(args=('one', 'multi+',))
|
|
|
|
assert o.max_args is None
|
|
|
|
o = self.get_instance(args=('one', 'multi*',))
|
|
|
|
assert o.max_args is None
|
|
|
|
|
2008-09-10 10:14:26 -05:00
|
|
|
def test_options(self):
|
|
|
|
"""
|
2008-10-08 01:58:53 -05:00
|
|
|
Test the ``ipalib.frontend.Command.options`` instance attribute.
|
2008-09-10 10:14:26 -05:00
|
|
|
"""
|
|
|
|
assert 'options' in self.cls.__public__ # Public
|
2008-09-21 13:50:00 -05:00
|
|
|
assert self.cls().options is None
|
|
|
|
o = self.cls()
|
2008-09-21 16:50:56 -05:00
|
|
|
o.finalize()
|
2008-09-21 13:50:00 -05:00
|
|
|
assert type(o.options) is plugable.NameSpace
|
|
|
|
assert len(o.options) == 0
|
2008-09-10 10:14:26 -05:00
|
|
|
options = ('target', 'files*')
|
2008-09-18 14:39:23 -05:00
|
|
|
ns = self.get_instance(options=options).options
|
2008-09-10 10:14:26 -05:00
|
|
|
assert type(ns) is plugable.NameSpace
|
|
|
|
assert len(ns) == len(options)
|
|
|
|
assert list(ns) == ['target', 'files']
|
2008-09-23 19:01:29 -05:00
|
|
|
assert type(ns.target) is frontend.Param
|
|
|
|
assert type(ns.files) is frontend.Param
|
2008-09-10 10:14:26 -05:00
|
|
|
assert ns.target.required is True
|
|
|
|
assert ns.target.multivalue is False
|
|
|
|
assert ns.files.required is False
|
|
|
|
assert ns.files.multivalue is True
|
|
|
|
|
2008-09-03 21:30:40 -05:00
|
|
|
def test_convert(self):
|
|
|
|
"""
|
2008-10-08 01:58:53 -05:00
|
|
|
Test the `ipalib.frontend.Command.convert` method.
|
2008-09-03 21:30:40 -05:00
|
|
|
"""
|
|
|
|
assert 'convert' in self.cls.__public__ # Public
|
|
|
|
kw = dict(
|
|
|
|
option0='option0',
|
|
|
|
option1='option1',
|
|
|
|
)
|
|
|
|
expected = dict(kw)
|
|
|
|
expected.update(dict(option0=u'option0', option1=u'option1'))
|
|
|
|
o = self.subcls()
|
2008-09-21 16:50:56 -05:00
|
|
|
o.finalize()
|
2008-09-03 21:30:40 -05:00
|
|
|
for (key, value) in o.convert(**kw).iteritems():
|
|
|
|
v = expected[key]
|
|
|
|
assert value == v
|
|
|
|
assert type(value) is type(v)
|
|
|
|
|
2008-08-11 11:29:37 -05:00
|
|
|
def test_normalize(self):
|
|
|
|
"""
|
2008-10-08 01:58:53 -05:00
|
|
|
Test the `ipalib.frontend.Command.normalize` method.
|
2008-08-11 11:29:37 -05:00
|
|
|
"""
|
|
|
|
assert 'normalize' in self.cls.__public__ # Public
|
|
|
|
kw = dict(
|
2008-09-02 18:40:44 -05:00
|
|
|
option0=u'OPTION0',
|
|
|
|
option1=u'OPTION1',
|
2008-08-11 11:29:37 -05:00
|
|
|
)
|
|
|
|
norm = dict((k, v.lower()) for (k, v) in kw.items())
|
|
|
|
sub = self.subcls()
|
2008-09-21 16:50:56 -05:00
|
|
|
sub.finalize()
|
2008-08-11 11:29:37 -05:00
|
|
|
assert sub.normalize(**kw) == norm
|
|
|
|
|
2008-08-26 14:13:55 -05:00
|
|
|
def test_get_default(self):
|
2008-08-11 12:37:33 -05:00
|
|
|
"""
|
2008-10-08 01:58:53 -05:00
|
|
|
Test the `ipalib.frontend.Command.get_default` method.
|
2008-08-11 12:37:33 -05:00
|
|
|
"""
|
2008-08-26 14:13:55 -05:00
|
|
|
assert 'get_default' in self.cls.__public__ # Public
|
2008-08-11 12:37:33 -05:00
|
|
|
no_fill = dict(
|
|
|
|
option0='value0',
|
|
|
|
option1='value1',
|
|
|
|
whatever='hello world',
|
|
|
|
)
|
|
|
|
fill = dict(
|
|
|
|
default_from='the default',
|
|
|
|
)
|
2008-08-11 12:57:07 -05:00
|
|
|
default = dict(
|
2008-08-11 12:37:33 -05:00
|
|
|
option0='the default',
|
|
|
|
option1='the default',
|
|
|
|
)
|
|
|
|
sub = self.subcls()
|
2008-09-21 16:50:56 -05:00
|
|
|
sub.finalize()
|
2008-08-26 14:13:55 -05:00
|
|
|
assert sub.get_default(**no_fill) == {}
|
|
|
|
assert sub.get_default(**fill) == default
|
2008-08-11 12:37:33 -05:00
|
|
|
|
2008-09-03 21:02:06 -05:00
|
|
|
def test_validate(self):
|
2008-08-11 14:11:26 -05:00
|
|
|
"""
|
2008-10-08 01:58:53 -05:00
|
|
|
Test the `ipalib.frontend.Command.validate` method.
|
2008-08-11 14:11:26 -05:00
|
|
|
"""
|
|
|
|
assert 'validate' in self.cls.__public__ # Public
|
2008-08-13 00:14:12 -05:00
|
|
|
|
2008-08-11 14:11:26 -05:00
|
|
|
sub = self.subcls()
|
2008-09-21 16:50:56 -05:00
|
|
|
sub.finalize()
|
2008-08-13 00:14:12 -05:00
|
|
|
|
|
|
|
# Check with valid args
|
|
|
|
okay = dict(
|
2008-09-02 18:40:44 -05:00
|
|
|
option0=u'option0',
|
|
|
|
option1=u'option1',
|
2008-08-13 00:14:12 -05:00
|
|
|
another_option='some value',
|
|
|
|
)
|
|
|
|
sub.validate(**okay)
|
|
|
|
|
|
|
|
# Check with an invalid arg
|
|
|
|
fail = dict(okay)
|
2008-09-03 21:02:06 -05:00
|
|
|
fail['option0'] = u'whatever'
|
|
|
|
e = raises(errors.RuleError, sub.validate, **fail)
|
|
|
|
assert e.name == 'option0'
|
|
|
|
assert e.value == u'whatever'
|
|
|
|
assert e.error == 'must equal option0'
|
|
|
|
assert e.rule.__class__.__name__ == 'Rule'
|
|
|
|
assert e.index is None
|
2008-08-13 00:14:12 -05:00
|
|
|
|
|
|
|
# Check with a missing required arg
|
|
|
|
fail = dict(okay)
|
|
|
|
fail.pop('option1')
|
2008-09-03 21:02:06 -05:00
|
|
|
e = raises(errors.RequirementError, sub.validate, **fail)
|
|
|
|
assert e.name == 'option1'
|
|
|
|
assert e.value is None
|
|
|
|
assert e.index is None
|
2008-08-11 14:11:26 -05:00
|
|
|
|
2008-08-11 14:35:57 -05:00
|
|
|
def test_execute(self):
|
|
|
|
"""
|
2008-10-08 01:58:53 -05:00
|
|
|
Test the `ipalib.frontend.Command.execute` method.
|
2008-08-11 14:35:57 -05:00
|
|
|
"""
|
|
|
|
assert 'execute' in self.cls.__public__ # Public
|
2008-10-08 19:18:13 -05:00
|
|
|
o = self.cls()
|
|
|
|
e = raises(NotImplementedError, o.execute)
|
|
|
|
assert str(e) == 'Command.execute()'
|
2008-08-11 14:35:57 -05:00
|
|
|
|
2008-09-14 18:17:36 -05:00
|
|
|
def test_args_to_kw(self):
|
2008-09-18 18:53:23 -05:00
|
|
|
"""
|
2008-10-08 01:58:53 -05:00
|
|
|
Test the `ipalib.frontend.Command.args_to_kw` method.
|
2008-09-18 18:53:23 -05:00
|
|
|
"""
|
2008-09-18 19:00:54 -05:00
|
|
|
assert 'args_to_kw' in self.cls.__public__ # Public
|
2008-09-18 14:39:23 -05:00
|
|
|
o = self.get_instance(args=('one', 'two?'))
|
2008-09-14 18:17:36 -05:00
|
|
|
assert o.args_to_kw(1) == dict(one=1)
|
|
|
|
assert o.args_to_kw(1, 2) == dict(one=1, two=2)
|
|
|
|
|
2008-09-18 14:39:23 -05:00
|
|
|
o = self.get_instance(args=('one', 'two*'))
|
2008-09-14 18:17:36 -05:00
|
|
|
assert o.args_to_kw(1) == dict(one=1)
|
|
|
|
assert o.args_to_kw(1, 2) == dict(one=1, two=(2,))
|
|
|
|
assert o.args_to_kw(1, 2, 3) == dict(one=1, two=(2, 3))
|
|
|
|
|
2008-09-18 14:39:23 -05:00
|
|
|
o = self.get_instance(args=('one', 'two+'))
|
2008-09-14 18:17:36 -05:00
|
|
|
assert o.args_to_kw(1) == dict(one=1)
|
|
|
|
assert o.args_to_kw(1, 2) == dict(one=1, two=(2,))
|
|
|
|
assert o.args_to_kw(1, 2, 3) == dict(one=1, two=(2, 3))
|
|
|
|
|
2008-09-18 18:53:23 -05:00
|
|
|
o = self.get_instance()
|
|
|
|
e = raises(errors.ArgumentError, o.args_to_kw, 1)
|
|
|
|
assert str(e) == 'example takes no arguments'
|
|
|
|
|
|
|
|
o = self.get_instance(args=('one?',))
|
|
|
|
e = raises(errors.ArgumentError, o.args_to_kw, 1, 2)
|
|
|
|
assert str(e) == 'example takes at most 1 argument'
|
|
|
|
|
|
|
|
o = self.get_instance(args=('one', 'two?'))
|
|
|
|
e = raises(errors.ArgumentError, o.args_to_kw, 1, 2, 3)
|
|
|
|
assert str(e) == 'example takes at most 2 arguments'
|
|
|
|
|
2008-11-12 10:55:11 -06:00
|
|
|
def test_params_2_args_options(self):
|
2008-09-18 14:39:23 -05:00
|
|
|
"""
|
2008-11-12 10:55:11 -06:00
|
|
|
Test the `ipalib.frontend.Command.params_2_args_options` method.
|
2008-09-18 14:39:23 -05:00
|
|
|
"""
|
2008-11-12 10:55:11 -06:00
|
|
|
assert 'params_2_args_options' in self.cls.__public__ # Public
|
|
|
|
o = self.get_instance(args=['one'], options=['two'])
|
|
|
|
assert o.params_2_args_options({}) == ((None,), dict(two=None))
|
|
|
|
assert o.params_2_args_options(dict(one=1)) == ((1,), dict(two=None))
|
|
|
|
assert o.params_2_args_options(dict(two=2)) == ((None,), dict(two=2))
|
|
|
|
assert o.params_2_args_options(dict(two=2, one=1)) == \
|
|
|
|
((1,), dict(two=2))
|
2008-09-18 14:39:23 -05:00
|
|
|
|
2008-09-23 21:52:19 -05:00
|
|
|
def test_run(self):
|
|
|
|
"""
|
2008-10-08 01:58:53 -05:00
|
|
|
Test the `ipalib.frontend.Command.run` method.
|
2008-09-23 21:52:19 -05:00
|
|
|
"""
|
|
|
|
class my_cmd(self.cls):
|
|
|
|
def execute(self, *args, **kw):
|
|
|
|
return ('execute', args, kw)
|
|
|
|
|
|
|
|
def forward(self, *args, **kw):
|
|
|
|
return ('forward', args, kw)
|
|
|
|
|
|
|
|
args = ('Hello,', 'world,')
|
|
|
|
kw = dict(how_are='you', on_this='fine day?')
|
|
|
|
|
|
|
|
# Test in server context:
|
2008-12-08 17:56:24 -06:00
|
|
|
(api, home) = create_test_api(in_server=True)
|
2008-09-23 21:52:19 -05:00
|
|
|
api.finalize()
|
|
|
|
o = my_cmd()
|
|
|
|
o.set_api(api)
|
|
|
|
assert o.run.im_func is self.cls.run.im_func
|
|
|
|
assert ('execute', args, kw) == o.run(*args, **kw)
|
|
|
|
assert o.run.im_func is my_cmd.execute.im_func
|
|
|
|
|
|
|
|
# Test in non-server context
|
2008-12-08 17:56:24 -06:00
|
|
|
(api, home) = create_test_api(in_server=False)
|
2008-09-23 21:52:19 -05:00
|
|
|
api.finalize()
|
|
|
|
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)
|
|
|
|
assert o.run.im_func is my_cmd.forward.im_func
|
|
|
|
|
2008-09-18 14:39:23 -05:00
|
|
|
|
2008-11-14 22:29:46 -06:00
|
|
|
class test_LocalOrRemote(ClassChecker):
|
|
|
|
"""
|
|
|
|
Test the `ipalib.frontend.LocalOrRemote` class.
|
|
|
|
"""
|
|
|
|
_cls = frontend.LocalOrRemote
|
|
|
|
|
|
|
|
def test_init(self):
|
|
|
|
"""
|
|
|
|
Test the `ipalib.frontend.LocalOrRemote.__init__` method.
|
|
|
|
"""
|
|
|
|
o = self.cls()
|
|
|
|
o.finalize()
|
|
|
|
assert list(o.args) == []
|
|
|
|
assert list(o.options) == ['server']
|
|
|
|
op = o.options.server
|
2008-11-14 22:58:39 -06:00
|
|
|
assert op.required is False
|
2008-11-14 22:29:46 -06:00
|
|
|
assert op.default is False
|
|
|
|
|
|
|
|
def test_run(self):
|
|
|
|
"""
|
|
|
|
Test the `ipalib.frontend.LocalOrRemote.run` method.
|
|
|
|
"""
|
|
|
|
class example(self.cls):
|
|
|
|
takes_args = ['key?']
|
|
|
|
|
|
|
|
def forward(self, *args, **options):
|
|
|
|
return ('forward', args, options)
|
|
|
|
|
|
|
|
def execute(self, *args, **options):
|
|
|
|
return ('execute', args, options)
|
|
|
|
|
|
|
|
# Test when in_server=False:
|
2008-12-08 17:56:24 -06:00
|
|
|
(api, home) = create_test_api(in_server=False)
|
2008-11-14 22:29:46 -06:00
|
|
|
api.register(example)
|
|
|
|
api.finalize()
|
|
|
|
cmd = api.Command.example
|
2008-11-17 19:50:30 -06:00
|
|
|
assert cmd() == ('execute', (None,), dict(server=False))
|
|
|
|
assert cmd('var') == ('execute', (u'var',), dict(server=False))
|
2008-11-14 22:29:46 -06:00
|
|
|
assert cmd(server=True) == ('forward', (None,), dict(server=True))
|
|
|
|
assert cmd('var', server=True) == \
|
|
|
|
('forward', (u'var',), dict(server=True))
|
|
|
|
|
|
|
|
# Test when in_server=True (should always call execute):
|
2008-12-08 17:56:24 -06:00
|
|
|
(api, home) = create_test_api(in_server=True)
|
2008-11-14 22:29:46 -06:00
|
|
|
api.register(example)
|
|
|
|
api.finalize()
|
|
|
|
cmd = api.Command.example
|
2008-11-17 19:50:30 -06:00
|
|
|
assert cmd() == ('execute', (None,), dict(server=False))
|
|
|
|
assert cmd('var') == ('execute', (u'var',), dict(server=False))
|
2008-11-14 22:29:46 -06:00
|
|
|
assert cmd(server=True) == ('execute', (None,), dict(server=True))
|
|
|
|
assert cmd('var', server=True) == \
|
|
|
|
('execute', (u'var',), dict(server=True))
|
|
|
|
|
|
|
|
|
2008-08-22 16:50:53 -05:00
|
|
|
class test_Object(ClassChecker):
|
|
|
|
"""
|
2008-10-08 01:58:53 -05:00
|
|
|
Test the `ipalib.frontend.Object` class.
|
2008-08-22 16:50:53 -05:00
|
|
|
"""
|
2008-09-23 19:01:29 -05:00
|
|
|
_cls = frontend.Object
|
2008-08-22 16:50:53 -05:00
|
|
|
|
|
|
|
def test_class(self):
|
2008-10-08 01:58:53 -05:00
|
|
|
"""
|
|
|
|
Test the `ipalib.frontend.Object` class.
|
|
|
|
"""
|
2008-08-22 16:50:53 -05:00
|
|
|
assert self.cls.__bases__ == (plugable.Plugin,)
|
2008-09-25 21:43:11 -05:00
|
|
|
assert self.cls.backend is None
|
2008-09-24 18:19:34 -05:00
|
|
|
assert self.cls.methods is None
|
|
|
|
assert self.cls.properties is None
|
2008-09-24 18:29:15 -05:00
|
|
|
assert self.cls.params is None
|
2008-09-24 22:27:40 -05:00
|
|
|
assert self.cls.params_minus_pk is None
|
2008-09-24 18:19:34 -05:00
|
|
|
assert self.cls.takes_params == tuple()
|
2008-08-05 02:39:50 -05:00
|
|
|
|
2008-08-22 16:50:53 -05:00
|
|
|
def test_init(self):
|
2008-08-22 17:49:56 -05:00
|
|
|
"""
|
2008-10-08 01:58:53 -05:00
|
|
|
Test the `ipalib.frontend.Object.__init__` method.
|
2008-08-22 17:49:56 -05:00
|
|
|
"""
|
2008-08-22 16:50:53 -05:00
|
|
|
o = self.cls()
|
2008-09-25 21:43:11 -05:00
|
|
|
assert o.backend is None
|
2008-09-24 17:19:43 -05:00
|
|
|
assert o.methods is None
|
2008-09-24 18:19:34 -05:00
|
|
|
assert o.properties is None
|
2008-09-24 18:29:15 -05:00
|
|
|
assert o.params is None
|
2008-09-24 22:27:40 -05:00
|
|
|
assert o.params_minus_pk is None
|
2008-09-24 18:29:15 -05:00
|
|
|
assert o.properties is None
|
2008-08-05 02:39:50 -05:00
|
|
|
|
2008-09-21 16:50:56 -05:00
|
|
|
def test_set_api(self):
|
2008-08-22 17:49:56 -05:00
|
|
|
"""
|
2008-10-08 01:58:53 -05:00
|
|
|
Test the `ipalib.frontend.Object.set_api` method.
|
2008-08-22 17:49:56 -05:00
|
|
|
"""
|
|
|
|
# Setup for test:
|
|
|
|
class DummyAttribute(object):
|
|
|
|
def __init__(self, obj_name, attr_name, name=None):
|
|
|
|
self.obj_name = obj_name
|
|
|
|
self.attr_name = attr_name
|
|
|
|
if name is None:
|
|
|
|
self.name = '%s_%s' % (obj_name, attr_name)
|
|
|
|
else:
|
|
|
|
self.name = name
|
2008-09-24 19:00:58 -05:00
|
|
|
self.param = frontend.create_param(attr_name)
|
|
|
|
|
2008-08-22 17:49:56 -05:00
|
|
|
def __clone__(self, attr_name):
|
|
|
|
return self.__class__(
|
|
|
|
self.obj_name,
|
|
|
|
self.attr_name,
|
|
|
|
getattr(self, attr_name)
|
|
|
|
)
|
|
|
|
|
|
|
|
def get_attributes(cnt, format):
|
|
|
|
for name in ['other', 'user', 'another']:
|
|
|
|
for i in xrange(cnt):
|
|
|
|
yield DummyAttribute(name, format % i)
|
|
|
|
|
|
|
|
cnt = 10
|
|
|
|
formats = dict(
|
2008-09-24 17:19:43 -05:00
|
|
|
methods='method_%d',
|
2008-09-24 18:19:34 -05:00
|
|
|
properties='property_%d',
|
2008-08-22 17:49:56 -05:00
|
|
|
)
|
|
|
|
|
2008-09-25 21:43:11 -05:00
|
|
|
|
|
|
|
_d = dict(
|
|
|
|
Method=plugable.NameSpace(
|
2008-09-24 17:19:43 -05:00
|
|
|
get_attributes(cnt, formats['methods'])
|
2008-09-25 21:43:11 -05:00
|
|
|
),
|
|
|
|
Property=plugable.NameSpace(
|
2008-09-24 18:19:34 -05:00
|
|
|
get_attributes(cnt, formats['properties'])
|
2008-09-25 21:43:11 -05:00
|
|
|
),
|
|
|
|
)
|
|
|
|
api = plugable.MagicDict(_d)
|
2008-08-22 17:49:56 -05:00
|
|
|
assert len(api.Method) == cnt * 3
|
|
|
|
assert len(api.Property) == cnt * 3
|
|
|
|
|
|
|
|
class user(self.cls):
|
|
|
|
pass
|
|
|
|
|
|
|
|
# Actually perform test:
|
|
|
|
o = user()
|
2008-09-21 16:50:56 -05:00
|
|
|
o.set_api(api)
|
2008-08-22 17:49:56 -05:00
|
|
|
assert read_only(o, 'api') is api
|
2008-09-24 18:19:34 -05:00
|
|
|
for name in ['methods', 'properties']:
|
2008-08-22 17:49:56 -05:00
|
|
|
namespace = getattr(o, name)
|
|
|
|
assert isinstance(namespace, plugable.NameSpace)
|
|
|
|
assert len(namespace) == cnt
|
|
|
|
f = formats[name]
|
|
|
|
for i in xrange(cnt):
|
|
|
|
attr_name = f % i
|
|
|
|
attr = namespace[attr_name]
|
|
|
|
assert isinstance(attr, DummyAttribute)
|
|
|
|
assert attr is getattr(namespace, attr_name)
|
|
|
|
assert attr.obj_name == 'user'
|
|
|
|
assert attr.attr_name == attr_name
|
|
|
|
assert attr.name == attr_name
|
|
|
|
|
2008-09-24 18:29:15 -05:00
|
|
|
# Test params instance attribute
|
|
|
|
o = self.cls()
|
|
|
|
o.set_api(api)
|
|
|
|
ns = o.params
|
2008-09-21 19:37:01 -05:00
|
|
|
assert type(ns) is plugable.NameSpace
|
|
|
|
assert len(ns) == 0
|
|
|
|
class example(self.cls):
|
|
|
|
takes_params = ('banana', 'apple')
|
2008-09-24 18:29:15 -05:00
|
|
|
o = example()
|
|
|
|
o.set_api(api)
|
|
|
|
ns = o.params
|
2008-09-21 19:37:01 -05:00
|
|
|
assert type(ns) is plugable.NameSpace
|
|
|
|
assert len(ns) == 2, repr(ns)
|
|
|
|
assert list(ns) == ['banana', 'apple']
|
|
|
|
for p in ns():
|
2008-09-23 19:01:29 -05:00
|
|
|
assert type(p) is frontend.Param
|
2008-09-21 19:37:01 -05:00
|
|
|
assert p.required is True
|
|
|
|
assert p.multivalue is False
|
|
|
|
|
2008-09-24 20:44:53 -05:00
|
|
|
def test_primary_key(self):
|
|
|
|
"""
|
2008-10-08 01:58:53 -05:00
|
|
|
Test the `ipalib.frontend.Object.primary_key` attribute.
|
2008-09-24 20:44:53 -05:00
|
|
|
"""
|
2008-12-08 17:56:24 -06:00
|
|
|
(api, home) = create_test_api()
|
2008-09-24 20:44:53 -05:00
|
|
|
api.finalize()
|
|
|
|
|
|
|
|
# Test with no primary keys:
|
|
|
|
class example1(self.cls):
|
|
|
|
takes_params = (
|
|
|
|
'one',
|
|
|
|
'two',
|
|
|
|
)
|
|
|
|
o = example1()
|
|
|
|
o.set_api(api)
|
|
|
|
assert o.primary_key is None
|
2008-09-24 22:27:40 -05:00
|
|
|
assert o.params_minus_pk is None
|
2008-09-24 20:44:53 -05:00
|
|
|
|
|
|
|
# Test with 1 primary key:
|
|
|
|
class example2(self.cls):
|
|
|
|
takes_params = (
|
|
|
|
'one',
|
|
|
|
'two',
|
|
|
|
frontend.Param('three',
|
|
|
|
primary_key=True,
|
|
|
|
),
|
|
|
|
'four',
|
|
|
|
)
|
|
|
|
o = example2()
|
|
|
|
o.set_api(api)
|
|
|
|
pk = o.primary_key
|
|
|
|
assert isinstance(pk, frontend.Param)
|
|
|
|
assert pk.name == 'three'
|
|
|
|
assert pk.primary_key is True
|
|
|
|
assert o.params[2] is o.primary_key
|
2008-09-24 22:27:40 -05:00
|
|
|
assert isinstance(o.params_minus_pk, plugable.NameSpace)
|
|
|
|
assert list(o.params_minus_pk) == ['one', 'two', 'four']
|
2008-09-24 20:44:53 -05:00
|
|
|
|
|
|
|
# Test with multiple primary_key:
|
|
|
|
class example3(self.cls):
|
|
|
|
takes_params = (
|
|
|
|
frontend.Param('one', primary_key=True),
|
|
|
|
frontend.Param('two', primary_key=True),
|
|
|
|
'three',
|
|
|
|
frontend.Param('four', primary_key=True),
|
|
|
|
)
|
|
|
|
o = example3()
|
|
|
|
e = raises(ValueError, o.set_api, api)
|
|
|
|
assert str(e) == \
|
|
|
|
'example3 (Object) has multiple primary keys: one, two, four'
|
|
|
|
|
2008-09-25 21:43:11 -05:00
|
|
|
def test_backend(self):
|
|
|
|
"""
|
2008-10-08 01:58:53 -05:00
|
|
|
Test the `ipalib.frontend.Object.backend` attribute.
|
2008-09-25 21:43:11 -05:00
|
|
|
"""
|
2008-12-08 17:56:24 -06:00
|
|
|
(api, home) = create_test_api()
|
2008-09-25 21:43:11 -05:00
|
|
|
class ldap(backend.Backend):
|
|
|
|
whatever = 'It worked!'
|
|
|
|
api.register(ldap)
|
|
|
|
class user(frontend.Object):
|
|
|
|
backend_name = 'ldap'
|
|
|
|
api.register(user)
|
|
|
|
api.finalize()
|
|
|
|
b = api.Object.user.backend
|
|
|
|
assert isinstance(b, ldap)
|
|
|
|
assert b.whatever == 'It worked!'
|
|
|
|
|
2008-10-14 00:26:24 -05:00
|
|
|
def test_get_dn(self):
|
|
|
|
"""
|
|
|
|
Test the `ipalib.frontend.Object.get_dn` method.
|
|
|
|
"""
|
|
|
|
assert 'get_dn' in self.cls.__public__ # Public
|
|
|
|
o = self.cls()
|
|
|
|
e = raises(NotImplementedError, o.get_dn, 'primary key')
|
|
|
|
assert str(e) == 'Object.get_dn()'
|
|
|
|
class user(self.cls):
|
|
|
|
pass
|
|
|
|
o = user()
|
|
|
|
e = raises(NotImplementedError, o.get_dn, 'primary key')
|
|
|
|
assert str(e) == 'user.get_dn()'
|
|
|
|
|
2008-08-06 22:38:49 -05:00
|
|
|
|
2008-08-22 16:27:25 -05:00
|
|
|
class test_Attribute(ClassChecker):
|
|
|
|
"""
|
2008-10-08 01:58:53 -05:00
|
|
|
Test the `ipalib.frontend.Attribute` class.
|
2008-08-22 16:27:25 -05:00
|
|
|
"""
|
2008-09-23 19:01:29 -05:00
|
|
|
_cls = frontend.Attribute
|
2008-08-05 02:39:50 -05:00
|
|
|
|
2008-08-22 16:27:25 -05:00
|
|
|
def test_class(self):
|
2008-10-08 01:58:53 -05:00
|
|
|
"""
|
|
|
|
Test the `ipalib.frontend.Attribute` class.
|
|
|
|
"""
|
2008-08-22 16:27:25 -05:00
|
|
|
assert self.cls.__bases__ == (plugable.Plugin,)
|
|
|
|
assert type(self.cls.obj) is property
|
|
|
|
assert type(self.cls.obj_name) is property
|
|
|
|
assert type(self.cls.attr_name) is property
|
2008-08-05 02:39:50 -05:00
|
|
|
|
2008-08-22 16:27:25 -05:00
|
|
|
def test_init(self):
|
2008-09-02 19:15:20 -05:00
|
|
|
"""
|
2008-10-08 01:58:53 -05:00
|
|
|
Test the `ipalib.frontend.Attribute.__init__` method.
|
2008-09-02 19:15:20 -05:00
|
|
|
"""
|
2008-08-22 16:27:25 -05:00
|
|
|
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'
|
|
|
|
|
2008-09-21 16:50:56 -05:00
|
|
|
def test_set_api(self):
|
2008-09-02 19:15:20 -05:00
|
|
|
"""
|
2008-10-08 01:58:53 -05:00
|
|
|
Test the `ipalib.frontend.Attribute.set_api` method.
|
2008-09-02 19:15:20 -05:00
|
|
|
"""
|
2008-09-23 19:01:29 -05:00
|
|
|
user_obj = 'The user frontend.Object instance'
|
2008-08-22 16:27:25 -05:00
|
|
|
class api(object):
|
2008-08-22 16:50:53 -05:00
|
|
|
Object = dict(user=user_obj)
|
2008-08-22 16:27:25 -05:00
|
|
|
class user_add(self.cls):
|
|
|
|
pass
|
|
|
|
o = user_add()
|
|
|
|
assert read_only(o, 'api') is None
|
|
|
|
assert read_only(o, 'obj') is None
|
2008-09-21 16:50:56 -05:00
|
|
|
o.set_api(api)
|
2008-08-22 16:27:25 -05:00
|
|
|
assert read_only(o, 'api') is api
|
|
|
|
assert read_only(o, 'obj') is user_obj
|
2008-08-11 17:12:23 -05:00
|
|
|
|
2008-08-05 02:39:50 -05:00
|
|
|
|
2008-09-02 19:01:45 -05:00
|
|
|
class test_Method(ClassChecker):
|
2008-08-11 16:14:07 -05:00
|
|
|
"""
|
2008-10-08 01:58:53 -05:00
|
|
|
Test the `ipalib.frontend.Method` class.
|
2008-08-11 16:14:07 -05:00
|
|
|
"""
|
2008-09-23 19:01:29 -05:00
|
|
|
_cls = frontend.Method
|
2008-08-11 16:14:07 -05:00
|
|
|
|
|
|
|
def test_class(self):
|
2008-10-08 01:58:53 -05:00
|
|
|
"""
|
|
|
|
Test the `ipalib.frontend.Method` class.
|
|
|
|
"""
|
2008-09-23 19:01:29 -05:00
|
|
|
assert self.cls.__bases__ == (frontend.Attribute, frontend.Command)
|
|
|
|
assert self.cls.implements(frontend.Command)
|
2008-09-24 20:52:34 -05:00
|
|
|
assert self.cls.implements(frontend.Attribute)
|
2008-08-05 02:39:50 -05:00
|
|
|
|
2008-09-24 20:52:34 -05:00
|
|
|
def test_init(self):
|
2008-08-11 17:12:23 -05:00
|
|
|
"""
|
2008-10-08 01:58:53 -05:00
|
|
|
Test the `ipalib.frontend.Method.__init__` method.
|
2008-08-11 17:12:23 -05:00
|
|
|
"""
|
2008-09-24 20:52:34 -05:00
|
|
|
class user_add(self.cls):
|
|
|
|
pass
|
|
|
|
o = user_add()
|
|
|
|
assert o.name == 'user_add'
|
|
|
|
assert o.obj_name == 'user'
|
|
|
|
assert o.attr_name == 'add'
|
|
|
|
assert frontend.Command.implemented_by(o)
|
|
|
|
assert frontend.Attribute.implemented_by(o)
|
2008-08-11 17:12:23 -05:00
|
|
|
|
2008-08-05 02:39:50 -05:00
|
|
|
|
2008-09-02 15:16:34 -05:00
|
|
|
class test_Property(ClassChecker):
|
|
|
|
"""
|
2008-10-08 01:58:53 -05:00
|
|
|
Test the `ipalib.frontend.Property` class.
|
2008-09-02 15:16:34 -05:00
|
|
|
"""
|
2008-09-23 19:01:29 -05:00
|
|
|
_cls = frontend.Property
|
2008-08-11 16:14:07 -05:00
|
|
|
|
2008-09-02 17:19:39 -05:00
|
|
|
def get_subcls(self):
|
2008-10-08 01:58:53 -05:00
|
|
|
"""
|
|
|
|
Return a standard subclass of `ipalib.frontend.Property`.
|
|
|
|
"""
|
2008-09-02 17:19:39 -05:00
|
|
|
class user_givenname(self.cls):
|
|
|
|
'User first name'
|
|
|
|
|
2008-09-23 19:01:29 -05:00
|
|
|
@frontend.rule
|
2008-09-02 17:19:39 -05:00
|
|
|
def rule0_lowercase(self, value):
|
|
|
|
if not value.islower():
|
|
|
|
return 'Must be lowercase'
|
|
|
|
return user_givenname
|
|
|
|
|
2008-08-11 16:14:07 -05:00
|
|
|
def test_class(self):
|
2008-10-08 01:58:53 -05:00
|
|
|
"""
|
|
|
|
Test the `ipalib.frontend.Property` class.
|
|
|
|
"""
|
2008-09-23 19:01:29 -05:00
|
|
|
assert self.cls.__bases__ == (frontend.Attribute,)
|
2008-09-02 17:19:39 -05:00
|
|
|
assert isinstance(self.cls.type, ipa_types.Unicode)
|
|
|
|
assert self.cls.required is False
|
|
|
|
assert self.cls.multivalue is False
|
|
|
|
assert self.cls.default is None
|
|
|
|
assert self.cls.default_from is None
|
|
|
|
assert self.cls.normalize is None
|
|
|
|
|
|
|
|
def test_init(self):
|
2008-09-02 19:15:20 -05:00
|
|
|
"""
|
2008-10-08 01:58:53 -05:00
|
|
|
Test the `ipalib.frontend.Property.__init__` method.
|
2008-09-02 19:15:20 -05:00
|
|
|
"""
|
2008-09-02 17:19:39 -05:00
|
|
|
o = self.subcls()
|
|
|
|
assert len(o.rules) == 1
|
|
|
|
assert o.rules[0].__name__ == 'rule0_lowercase'
|
2008-09-22 10:33:32 -05:00
|
|
|
param = o.param
|
2008-09-23 19:01:29 -05:00
|
|
|
assert isinstance(param, frontend.Param)
|
2008-09-22 10:33:32 -05:00
|
|
|
assert param.name == 'givenname'
|
|
|
|
assert param.doc == 'User first name'
|
2008-09-03 22:34:16 -05:00
|
|
|
|
|
|
|
|
|
|
|
class test_Application(ClassChecker):
|
|
|
|
"""
|
2008-10-08 01:58:53 -05:00
|
|
|
Test the `ipalib.frontend.Application` class.
|
2008-09-03 22:34:16 -05:00
|
|
|
"""
|
2008-09-23 19:01:29 -05:00
|
|
|
_cls = frontend.Application
|
2008-09-03 22:34:16 -05:00
|
|
|
|
|
|
|
def test_class(self):
|
2008-10-08 01:58:53 -05:00
|
|
|
"""
|
|
|
|
Test the `ipalib.frontend.Application` class.
|
|
|
|
"""
|
2008-09-23 19:01:29 -05:00
|
|
|
assert self.cls.__bases__ == (frontend.Command,)
|
2008-09-03 22:34:16 -05:00
|
|
|
assert type(self.cls.application) is property
|
|
|
|
|
|
|
|
def test_application(self):
|
|
|
|
"""
|
2008-10-08 01:58:53 -05:00
|
|
|
Test the `ipalib.frontend.Application.application` property.
|
2008-09-03 22:34:16 -05:00
|
|
|
"""
|
|
|
|
assert 'application' in self.cls.__public__ # Public
|
2008-09-03 23:39:01 -05:00
|
|
|
assert 'set_application' in self.cls.__public__ # Public
|
2008-09-03 22:34:16 -05:00
|
|
|
app = 'The external application'
|
|
|
|
class example(self.cls):
|
|
|
|
'A subclass'
|
|
|
|
for o in (self.cls(), example()):
|
2008-09-03 23:39:01 -05:00
|
|
|
assert read_only(o, 'application') is None
|
|
|
|
e = raises(TypeError, o.set_application, None)
|
2008-09-03 22:34:16 -05:00
|
|
|
assert str(e) == (
|
|
|
|
'%s.application cannot be None' % o.__class__.__name__
|
|
|
|
)
|
2008-09-03 23:39:01 -05:00
|
|
|
o.set_application(app)
|
|
|
|
assert read_only(o, 'application') is app
|
|
|
|
e = raises(AttributeError, o.set_application, app)
|
2008-09-03 22:34:16 -05:00
|
|
|
assert str(e) == (
|
|
|
|
'%s.application can only be set once' % o.__class__.__name__
|
|
|
|
)
|
2008-09-03 23:39:01 -05:00
|
|
|
assert read_only(o, 'application') is app
|