2008-09-24 15:17:53 -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.crud` module.
|
2008-09-24 15:17:53 -05:00
|
|
|
"""
|
|
|
|
|
2008-10-07 23:30:53 -05:00
|
|
|
from tests.util import read_only, raises, ClassChecker
|
2008-09-29 10:41:30 -05:00
|
|
|
from ipalib import crud, frontend, plugable, config
|
2008-09-24 21:13:16 -05:00
|
|
|
|
2008-10-08 00:36:58 -05:00
|
|
|
|
2008-10-08 01:17:32 -05:00
|
|
|
class CrudChecker(ClassChecker):
|
|
|
|
"""
|
|
|
|
Class for testing base classes in `ipalib.crud`.
|
|
|
|
"""
|
|
|
|
|
2008-10-09 12:33:35 -05:00
|
|
|
def get_api(self, args=tuple(), options={}):
|
2008-10-08 01:17:32 -05:00
|
|
|
"""
|
|
|
|
Return a finalized `ipalib.plugable.API` instance.
|
|
|
|
"""
|
|
|
|
assert self.cls.__bases__ == (frontend.Method,)
|
|
|
|
api = plugable.API(
|
|
|
|
frontend.Object,
|
|
|
|
frontend.Method,
|
|
|
|
frontend.Property,
|
2008-09-24 21:13:16 -05:00
|
|
|
)
|
2008-10-08 01:17:32 -05:00
|
|
|
api.env.update(config.generate_env())
|
|
|
|
class user(frontend.Object):
|
|
|
|
takes_params = (
|
|
|
|
'givenname',
|
|
|
|
'sn',
|
|
|
|
frontend.Param('uid', primary_key=True),
|
|
|
|
'initials',
|
|
|
|
)
|
|
|
|
class user_verb(self.cls):
|
2008-10-09 12:33:35 -05:00
|
|
|
takes_args = args
|
|
|
|
takes_options = options
|
2008-10-08 01:17:32 -05:00
|
|
|
api.register(user)
|
|
|
|
api.register(user_verb)
|
|
|
|
api.finalize()
|
|
|
|
return api
|
2008-09-24 15:17:53 -05:00
|
|
|
|
|
|
|
|
2008-10-08 01:17:32 -05:00
|
|
|
class test_Add(CrudChecker):
|
2008-09-24 15:17:53 -05:00
|
|
|
"""
|
2008-10-08 00:36:58 -05:00
|
|
|
Test the `ipalib.crud.Add` class.
|
2008-09-24 15:17:53 -05:00
|
|
|
"""
|
|
|
|
|
|
|
|
_cls = crud.Add
|
|
|
|
|
2008-10-08 01:17:32 -05:00
|
|
|
def test_get_args(self):
|
2008-10-08 00:36:58 -05:00
|
|
|
"""
|
2008-10-08 01:17:32 -05:00
|
|
|
Test the `ipalib.crud.Add.get_args` method.
|
2008-10-08 00:36:58 -05:00
|
|
|
"""
|
2008-10-08 01:17:32 -05:00
|
|
|
api = self.get_api()
|
|
|
|
assert list(api.Method.user_verb.args) == ['uid']
|
|
|
|
assert api.Method.user_verb.args.uid.required is True
|
2008-10-09 12:33:35 -05:00
|
|
|
api = self.get_api(args=('extra?',))
|
|
|
|
assert list(api.Method.user_verb.args) == ['uid', 'extra']
|
|
|
|
assert api.Method.user_verb.args.uid.required is True
|
|
|
|
assert api.Method.user_verb.args.extra.required is False
|
2008-09-24 15:17:53 -05:00
|
|
|
|
2008-10-08 01:17:32 -05:00
|
|
|
def test_get_options(self):
|
2008-09-24 21:13:16 -05:00
|
|
|
"""
|
2008-10-08 01:17:32 -05:00
|
|
|
Test the `ipalib.crud.Add.get_options` method.
|
2008-09-24 21:13:16 -05:00
|
|
|
"""
|
2008-10-08 01:17:32 -05:00
|
|
|
api = self.get_api()
|
|
|
|
assert list(api.Method.user_verb.options) == \
|
2008-09-30 21:27:52 -05:00
|
|
|
['givenname', 'sn', 'initials']
|
2008-10-08 01:17:32 -05:00
|
|
|
for param in api.Method.user_verb.options():
|
2008-09-24 22:42:38 -05:00
|
|
|
assert param.required is True
|
2008-10-09 12:33:35 -05:00
|
|
|
api = self.get_api(options=('extra?',))
|
|
|
|
assert list(api.Method.user_verb.options) == \
|
|
|
|
['givenname', 'sn', 'initials', 'extra']
|
|
|
|
assert api.Method.user_verb.options.extra.required is False
|
2008-09-24 21:13:16 -05:00
|
|
|
|
|
|
|
|
2008-10-08 01:17:32 -05:00
|
|
|
class test_Get(CrudChecker):
|
2008-09-24 15:17:53 -05:00
|
|
|
"""
|
2008-10-08 00:36:58 -05:00
|
|
|
Test the `ipalib.crud.Get` class.
|
2008-09-24 15:17:53 -05:00
|
|
|
"""
|
|
|
|
|
|
|
|
_cls = crud.Get
|
|
|
|
|
2008-10-08 01:17:32 -05:00
|
|
|
def test_get_args(self):
|
2008-10-08 00:36:58 -05:00
|
|
|
"""
|
2008-10-08 01:17:32 -05:00
|
|
|
Test the `ipalib.crud.Get.get_args` method.
|
2008-10-08 00:36:58 -05:00
|
|
|
"""
|
2008-10-08 01:17:32 -05:00
|
|
|
api = self.get_api()
|
|
|
|
assert list(api.Method.user_verb.args) == ['uid']
|
|
|
|
assert api.Method.user_verb.args.uid.required is True
|
2008-09-24 15:17:53 -05:00
|
|
|
|
2008-10-08 01:17:32 -05:00
|
|
|
def test_get_options(self):
|
2008-09-24 22:14:12 -05:00
|
|
|
"""
|
2008-10-08 01:17:32 -05:00
|
|
|
Test the `ipalib.crud.Get.get_options` method.
|
2008-09-24 22:14:12 -05:00
|
|
|
"""
|
2008-10-08 01:17:32 -05:00
|
|
|
api = self.get_api()
|
|
|
|
assert list(api.Method.user_verb.options) == []
|
|
|
|
assert len(api.Method.user_verb.options) == 0
|
2008-09-24 22:14:12 -05:00
|
|
|
|
2008-09-24 15:17:53 -05:00
|
|
|
|
2008-10-08 01:17:32 -05:00
|
|
|
class test_Del(CrudChecker):
|
2008-09-24 15:17:53 -05:00
|
|
|
"""
|
2008-10-08 00:36:58 -05:00
|
|
|
Test the `ipalib.crud.Del` class.
|
2008-09-24 15:17:53 -05:00
|
|
|
"""
|
|
|
|
|
|
|
|
_cls = crud.Del
|
|
|
|
|
2008-10-08 01:17:32 -05:00
|
|
|
def test_get_args(self):
|
2008-10-08 00:36:58 -05:00
|
|
|
"""
|
2008-10-08 01:17:32 -05:00
|
|
|
Test the `ipalib.crud.Del.get_args` method.
|
2008-10-08 00:36:58 -05:00
|
|
|
"""
|
2008-10-08 01:17:32 -05:00
|
|
|
api = self.get_api()
|
|
|
|
assert list(api.Method.user_verb.args) == ['uid']
|
|
|
|
assert api.Method.user_verb.args.uid.required is True
|
2008-09-24 15:17:53 -05:00
|
|
|
|
2008-10-08 01:17:32 -05:00
|
|
|
def test_get_options(self):
|
2008-09-24 22:14:12 -05:00
|
|
|
"""
|
2008-10-08 01:17:32 -05:00
|
|
|
Test the `ipalib.crud.Del.get_options` method.
|
2008-09-24 22:14:12 -05:00
|
|
|
"""
|
2008-10-08 01:17:32 -05:00
|
|
|
api = self.get_api()
|
|
|
|
assert list(api.Method.user_verb.options) == []
|
|
|
|
assert len(api.Method.user_verb.options) == 0
|
2008-09-24 22:14:12 -05:00
|
|
|
|
2008-09-24 15:17:53 -05:00
|
|
|
|
2008-10-08 01:17:32 -05:00
|
|
|
class test_Mod(CrudChecker):
|
2008-09-24 15:17:53 -05:00
|
|
|
"""
|
2008-10-08 00:36:58 -05:00
|
|
|
Test the `ipalib.crud.Mod` class.
|
2008-09-24 15:17:53 -05:00
|
|
|
"""
|
|
|
|
|
|
|
|
_cls = crud.Mod
|
|
|
|
|
2008-10-08 01:17:32 -05:00
|
|
|
def test_get_args(self):
|
2008-10-08 00:36:58 -05:00
|
|
|
"""
|
2008-10-08 01:17:32 -05:00
|
|
|
Test the `ipalib.crud.Mod.get_args` method.
|
2008-10-08 00:36:58 -05:00
|
|
|
"""
|
2008-10-08 01:17:32 -05:00
|
|
|
api = self.get_api()
|
|
|
|
assert list(api.Method.user_verb.args) == ['uid']
|
|
|
|
assert api.Method.user_verb.args.uid.required is True
|
2008-09-24 15:17:53 -05:00
|
|
|
|
2008-10-08 01:17:32 -05:00
|
|
|
def test_get_options(self):
|
2008-09-24 22:42:38 -05:00
|
|
|
"""
|
2008-10-08 01:17:32 -05:00
|
|
|
Test the `ipalib.crud.Mod.get_options` method.
|
2008-09-24 22:42:38 -05:00
|
|
|
"""
|
2008-10-08 01:17:32 -05:00
|
|
|
api = self.get_api()
|
|
|
|
assert list(api.Method.user_verb.options) == \
|
2008-09-24 22:42:38 -05:00
|
|
|
['givenname', 'sn', 'initials']
|
2008-10-08 01:17:32 -05:00
|
|
|
for param in api.Method.user_verb.options():
|
2008-09-24 22:42:38 -05:00
|
|
|
assert param.required is False
|
|
|
|
|
2008-09-24 15:17:53 -05:00
|
|
|
|
2008-10-08 01:17:32 -05:00
|
|
|
class test_Find(CrudChecker):
|
2008-09-24 15:17:53 -05:00
|
|
|
"""
|
2008-10-08 00:36:58 -05:00
|
|
|
Test the `ipalib.crud.Find` class.
|
2008-09-24 15:17:53 -05:00
|
|
|
"""
|
|
|
|
|
|
|
|
_cls = crud.Find
|
|
|
|
|
2008-10-08 01:17:32 -05:00
|
|
|
def test_get_args(self):
|
2008-10-08 00:36:58 -05:00
|
|
|
"""
|
2008-10-08 01:17:32 -05:00
|
|
|
Test the `ipalib.crud.Find.get_args` method.
|
2008-10-08 00:36:58 -05:00
|
|
|
"""
|
2008-10-08 01:17:32 -05:00
|
|
|
api = self.get_api()
|
|
|
|
assert list(api.Method.user_verb.args) == ['uid']
|
|
|
|
assert api.Method.user_verb.args.uid.required is True
|
2008-09-24 22:47:22 -05:00
|
|
|
|
2008-10-08 01:17:32 -05:00
|
|
|
def test_get_options(self):
|
2008-09-24 22:47:22 -05:00
|
|
|
"""
|
2008-10-08 01:17:32 -05:00
|
|
|
Test the `ipalib.crud.Find.get_options` method.
|
2008-09-24 22:47:22 -05:00
|
|
|
"""
|
2008-10-08 01:17:32 -05:00
|
|
|
api = self.get_api()
|
|
|
|
assert list(api.Method.user_verb.options) == \
|
2008-09-24 22:47:22 -05:00
|
|
|
['givenname', 'sn', 'initials']
|
2008-10-08 01:17:32 -05:00
|
|
|
for param in api.Method.user_verb.options():
|
2008-09-24 22:47:22 -05:00
|
|
|
assert param.required is False
|