summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Cholasta <jcholast@redhat.com>2015-06-22 10:59:35 +0000
committerJan Cholasta <jcholast@redhat.com>2015-07-01 13:05:30 +0000
commit4b277d04771bece11f5cc9fe04cc04d3f2ded165 (patch)
tree050034eff53e762a494490b0aeb5df8e24a133a0
parent1a21fd971ccc26cf8f06d1ba965b263856be56c6 (diff)
downloadfreeipa-4b277d04771bece11f5cc9fe04cc04d3f2ded165.tar.gz
freeipa-4b277d04771bece11f5cc9fe04cc04d3f2ded165.tar.xz
freeipa-4b277d04771bece11f5cc9fe04cc04d3f2ded165.zip
plugable: Change is_production_mode to method of API
https://fedorahosted.org/freeipa/ticket/3090 Reviewed-By: Martin Babinsky <mbabinsk@redhat.com>
-rw-r--r--ipalib/frontend.py4
-rw-r--r--ipalib/plugable.py22
-rw-r--r--ipatests/test_ipalib/test_frontend.py66
-rw-r--r--ipatests/test_ipalib/test_plugable.py5
4 files changed, 70 insertions, 27 deletions
diff --git a/ipalib/frontend.py b/ipalib/frontend.py
index c36bfca46..af201fc9a 100644
--- a/ipalib/frontend.py
+++ b/ipalib/frontend.py
@@ -27,7 +27,7 @@ from distutils import version
from ipapython.version import API_VERSION
from ipapython.ipa_log_manager import root_logger
from base import NameSpace
-from plugable import Plugin, is_production_mode
+from plugable import Plugin
from parameters import create_param, Param, Str, Flag, Password
from output import Output, Entry, ListOfEntries
from text import _
@@ -359,7 +359,7 @@ class HasParam(Plugin):
self._filter_param_by_context(name, env),
sort=False
)
- if not is_production_mode(self):
+ if not self.api.is_production_mode():
check = getattr(self, 'check_' + name, None)
if callable(check):
check(namespace)
diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index 9e7e4fc3b..967246f10 100644
--- a/ipalib/plugable.py
+++ b/ipalib/plugable.py
@@ -49,17 +49,6 @@ from ipapython.version import VERSION, API_VERSION
# FIXME: Updated constants.TYPE_ERROR to use this clearer format from wehjit:
TYPE_ERROR = '%s: need a %r; got a %r: %r'
-def is_production_mode(obj):
- """
- If the object has self.env.mode defined and that mode is
- production return True, otherwise return False.
- """
- if getattr(obj, 'env', None) is None:
- return False
- if getattr(obj.env, 'mode', None) is None:
- return False
- return obj.env.mode == 'production'
-
# FIXME: This function has no unit test
def find_modules_in_dir(src_dir):
@@ -184,7 +173,7 @@ class Plugin(ReadOnly):
self.__finalize_called = True
self._on_finalize()
self.__finalized = True
- if not is_production_mode(self):
+ if not self.__api.is_production_mode():
lock(self)
def _on_finalize(self):
@@ -368,6 +357,13 @@ class API(ReadOnly):
except AttributeError:
raise KeyError(name)
+ def is_production_mode(self):
+ """
+ If the object has self.env.mode defined and that mode is
+ production return True, otherwise return False.
+ """
+ return getattr(self.env, 'mode', None) == 'production'
+
def __doing(self, name):
if name in self.__done:
raise StandardError(
@@ -664,7 +660,7 @@ class API(ReadOnly):
self.__doing('finalize')
self.__do_if_not_done('load_plugins')
- production_mode = is_production_mode(self)
+ production_mode = self.is_production_mode()
plugins = {}
plugin_info = {}
diff --git a/ipatests/test_ipalib/test_frontend.py b/ipatests/test_ipalib/test_frontend.py
index 1e27dfeb9..3ca03c39b 100644
--- a/ipatests/test_ipalib/test_frontend.py
+++ b/ipatests/test_ipalib/test_frontend.py
@@ -221,7 +221,10 @@ class test_Command(ClassChecker):
"""
Helper method used to test args and options.
"""
- api = 'the api instance'
+ class api(object):
+ @staticmethod
+ def is_production_mode():
+ return False
class example(self.cls):
takes_args = args
takes_options = options
@@ -264,7 +267,10 @@ class test_Command(ClassChecker):
"""
Test the ``ipalib.frontend.Command.args`` instance attribute.
"""
- api = 'the api instance'
+ class api(object):
+ @staticmethod
+ def is_production_mode():
+ return False
o = self.cls(api)
o.finalize()
assert type(o.args) is plugable.NameSpace
@@ -313,7 +319,10 @@ class test_Command(ClassChecker):
"""
Test the ``ipalib.frontend.Command.options`` instance attribute.
"""
- api = 'the api instance'
+ class api(object):
+ @staticmethod
+ def is_production_mode():
+ return False
o = self.cls(api)
o.finalize()
assert type(o.options) is plugable.NameSpace
@@ -334,7 +343,10 @@ class test_Command(ClassChecker):
"""
Test the ``ipalib.frontend.Command.output`` instance attribute.
"""
- api = 'the api instance'
+ class api(object):
+ @staticmethod
+ def is_production_mode():
+ return False
inst = self.cls(api)
inst.finalize()
assert type(inst.output) is plugable.NameSpace
@@ -381,6 +393,9 @@ class test_Command(ClassChecker):
"""
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(),
@@ -405,7 +420,10 @@ class test_Command(ClassChecker):
"""
Test the `ipalib.frontend.Command.convert` method.
"""
- api = 'the api instance'
+ class api(object):
+ @staticmethod
+ def is_production_mode():
+ return False
kw = dict(
option0=u'1.5',
option1=u'7',
@@ -419,7 +437,10 @@ class test_Command(ClassChecker):
"""
Test the `ipalib.frontend.Command.normalize` method.
"""
- api = 'the api instance'
+ class api(object):
+ @staticmethod
+ def is_production_mode():
+ return False
kw = dict(
option0=u'OPTION0',
option1=u'OPTION1',
@@ -467,6 +488,9 @@ class test_Command(ClassChecker):
"""
class api(object):
env = config.Env(context='cli')
+ @staticmethod
+ def is_production_mode():
+ return False
sub = self.subcls(api)
sub.finalize()
@@ -672,7 +696,10 @@ class test_Command(ClassChecker):
"""
Test the `ipalib.frontend.Command.validate_output` method.
"""
- api = 'the api instance'
+ class api(object):
+ @staticmethod
+ def is_production_mode():
+ return False
class Example(self.cls):
has_output = ('foo', 'bar', 'baz')
@@ -711,7 +738,10 @@ class test_Command(ClassChecker):
"""
Test `ipalib.frontend.Command.validate_output` per-type validation.
"""
- api = 'the api instance'
+ class api(object):
+ @staticmethod
+ def is_production_mode():
+ return False
class Complex(self.cls):
has_output = (
@@ -737,7 +767,10 @@ class test_Command(ClassChecker):
"""
Test `ipalib.frontend.Command.validate_output` nested validation.
"""
- api = 'the api instance'
+ class api(object):
+ @staticmethod
+ def is_production_mode():
+ return False
class Subclass(output.ListOfEntries):
pass
@@ -769,7 +802,10 @@ class test_Command(ClassChecker):
"""
Test the `ipalib.frontend.Command.get_output_params` method.
"""
- api = 'the api instance'
+ class api(object):
+ @staticmethod
+ def is_production_mode():
+ return False
class example(self.cls):
has_output_params = (
'one',
@@ -802,7 +838,10 @@ class test_LocalOrRemote(ClassChecker):
"""
Test the `ipalib.frontend.LocalOrRemote.__init__` method.
"""
- api = 'the api instance'
+ class api(object):
+ @staticmethod
+ def is_production_mode():
+ return False
o = self.cls(api)
o.finalize()
assert list(o.args) == []
@@ -915,6 +954,8 @@ class test_Object(ClassChecker):
return hasattr(self, key)
def __getitem__(self, key):
return getattr(self, key)
+ def is_production_mode(self):
+ return False
api = FakeAPI()
assert len(api.Method) == cnt * 3
@@ -1073,6 +1114,9 @@ class test_Attribute(ClassChecker):
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)
diff --git a/ipatests/test_ipalib/test_plugable.py b/ipatests/test_ipalib/test_plugable.py
index f5434e8a4..99554d4f8 100644
--- a/ipatests/test_ipalib/test_plugable.py
+++ b/ipatests/test_ipalib/test_plugable.py
@@ -88,7 +88,10 @@ class test_Plugin(ClassChecker):
"""
Test the `ipalib.plugable.Plugin.finalize` method.
"""
- api = 'the api instance'
+ class api(object):
+ @staticmethod
+ def is_production_mode():
+ return False
o = self.cls(api)
assert not o.__islocked__()
o.finalize()