diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2008-10-30 01:34:46 -0600 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2008-10-30 01:34:46 -0600 |
commit | 2fee6a3e20169f12b837647f0f71d6f28937490f (patch) | |
tree | f84fc2ad8486a70ba51be6cd36214ab9dc6ac53f | |
parent | ddb5449c7faabbd4c1b71adfe84c386b943a163f (diff) | |
download | freeipa-2fee6a3e20169f12b837647f0f71d6f28937490f.tar.gz freeipa-2fee6a3e20169f12b837647f0f71d6f28937490f.tar.xz freeipa-2fee6a3e20169f12b837647f0f71d6f28937490f.zip |
Added tests.util.get_api() function to create a standard (api, home) tuple for unit testing
-rw-r--r-- | ipalib/__init__.py | 8 | ||||
-rw-r--r-- | tests/test_ipalib/test_cli.py | 17 | ||||
-rw-r--r-- | tests/test_ipalib/test_plugable.py | 15 | ||||
-rw-r--r-- | tests/util.py | 21 |
4 files changed, 29 insertions, 32 deletions
diff --git a/ipalib/__init__.py b/ipalib/__init__.py index a6664f73b..5cc4c1214 100644 --- a/ipalib/__init__.py +++ b/ipalib/__init__.py @@ -35,13 +35,11 @@ from frontend import Command, Object, Method, Property, Application from ipa_types import Bool, Int, Unicode, Enum from frontend import Param, DefaultFrom -def get_standard_api(unit_test=False): - api = plugable.API( +def get_standard_api(): + return plugable.API( Command, Object, Method, Property, Application, Backend, Context, ) - if unit_test is True: - api.env.mode = 'unit_test' - return api + api = get_standard_api() diff --git a/tests/test_ipalib/test_cli.py b/tests/test_ipalib/test_cli.py index 7b3239d7c..f13db51eb 100644 --- a/tests/test_ipalib/test_cli.py +++ b/tests/test_ipalib/test_cli.py @@ -21,8 +21,7 @@ Test the `ipalib.cli` module. """ -from tests.util import raises, getitem, no_set, no_del, read_only, ClassChecker -from tests.util import TempHome +from tests.util import raises, get_api, ClassChecker from ipalib import cli, plugable, frontend, backend @@ -92,8 +91,6 @@ from_cli_conf = overridden in default.conf """ - - class test_CLI(ClassChecker): """ Test the `ipalib.cli.CLI` class. @@ -101,17 +98,7 @@ class test_CLI(ClassChecker): _cls = cli.CLI def new(self, argv=tuple()): - home = TempHome() - api = plugable.API( - frontend.Command, - frontend.Object, - frontend.Method, - frontend.Property, - frontend.Application, - backend.Backend, - ) - api.env.mode = 'unit_test' - api.env.in_tree = True + (api, home) = get_api() o = self.cls(api, argv) assert o.api is api return (o, api, home) diff --git a/tests/test_ipalib/test_plugable.py b/tests/test_ipalib/test_plugable.py index c7b8abbd9..ce0c79a97 100644 --- a/tests/test_ipalib/test_plugable.py +++ b/tests/test_ipalib/test_plugable.py @@ -23,7 +23,7 @@ Test the `ipalib.plugable` module. from tests.util import raises, no_set, no_del, read_only from tests.util import getitem, setitem, delitem -from tests.util import ClassChecker, TempHome +from tests.util import ClassChecker, get_api from ipalib import plugable, errors @@ -771,13 +771,6 @@ class test_API(ClassChecker): _cls = plugable.API - def new(self, *bases): - home = TempHome() - api = self.cls(*bases) - api.env.mode = 'unit_test' - api.env.in_tree = True - return (api, home) - def test_API(self): """ Test the `ipalib.plugable.API` class. @@ -802,6 +795,8 @@ class test_API(ClassChecker): return n + 1 api = plugable.API(base0, base1) + api.env.mode = 'unit_test' + api.env.in_tree = True r = api.register assert isinstance(r, plugable.Registrar) assert read_only(api, 'register') is r @@ -884,7 +879,7 @@ class test_API(ClassChecker): """ Test the `ipalib.plugable.API.bootstrap` method. """ - (o, home) = self.new() + (o, home) = get_api() assert o.env._isdone('_bootstrap') is False assert o.env._isdone('_finalize_core') is False assert o.isdone('bootstrap') is False @@ -900,7 +895,7 @@ class test_API(ClassChecker): """ Test the `ipalib.plugable.API.load_plugins` method. """ - (o, home) = self.new() + (o, home) = get_api() assert o.isdone('bootstrap') is False assert o.isdone('load_plugins') is False o.load_plugins() diff --git a/tests/util.py b/tests/util.py index cc761ce72..aa0299fdf 100644 --- a/tests/util.py +++ b/tests/util.py @@ -26,7 +26,8 @@ import os from os import path import tempfile import shutil -from ipalib import errors +import ipalib + class TempDir(object): @@ -206,5 +207,21 @@ def check_TypeError(value, type_, name, callback, *args, **kw): assert e.type is type_ assert e.name == name assert type(e.name) is str - assert str(e) == errors.TYPE_FORMAT % (name, type_, value) + assert str(e) == ipalib.errors.TYPE_FORMAT % (name, type_, value) return e + + +def get_api(**kw): + """ + Returns (api, home) tuple. + + This function returns a tuple containing an `ipalib.plugable.API` + instance and a `TempHome` instance. + """ + home = TempHome() + api = ipalib.get_standard_api() + api.env.mode = 'unit_test' + api.env.in_tree = True + for (key, value) in kw.iteritems(): + api.env[key] = value + return (api, home) |