summaryrefslogtreecommitdiffstats
path: root/tests/test_ipalib
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2009-05-13 01:04:35 -0600
committerJason Gerard DeRose <jderose@redhat.com>2009-05-19 13:49:15 -0600
commit4f9224774f7ec7c1c8ed4fedef2f2b62390064d2 (patch)
tree40dada32e1083c94eff71c31046d13e51399f485 /tests/test_ipalib
parent86472a94eeb166a0d1379834e91995809a7ddf7e (diff)
downloadfreeipa-4f9224774f7ec7c1c8ed4fedef2f2b62390064d2.tar.gz
freeipa-4f9224774f7ec7c1c8ed4fedef2f2b62390064d2.tar.xz
freeipa-4f9224774f7ec7c1c8ed4fedef2f2b62390064d2.zip
Added Param 'include' and 'exclude' kwargs; added frontend.UsesParams base class with methods implementing the filtering to restrict params to only certain contexts
Diffstat (limited to 'tests/test_ipalib')
-rw-r--r--tests/test_ipalib/test_parameters.py39
1 files changed, 37 insertions, 2 deletions
diff --git a/tests/test_ipalib/test_parameters.py b/tests/test_ipalib/test_parameters.py
index ea098a95a..db9c01efc 100644
--- a/tests/test_ipalib/test_parameters.py
+++ b/tests/test_ipalib/test_parameters.py
@@ -27,7 +27,7 @@ from inspect import isclass
from tests.util import raises, ClassChecker, read_only
from tests.util import dummy_ugettext, assert_equal
from tests.data import binary_bytes, utf8_bytes, unicode_str
-from ipalib import parameters, request, errors
+from ipalib import parameters, request, errors, config
from ipalib.constants import TYPE_ERROR, CALLABLE_ERROR, NULLS
@@ -168,7 +168,8 @@ class test_Param(ClassChecker):
assert o.autofill is False
assert o.query is False
assert o.attribute is False
- assert o.limit_to is None
+ assert o.include is None
+ assert o.exclude is None
assert o.flags == frozenset()
# Test that ValueError is raised when a kwarg from a subclass
@@ -223,6 +224,18 @@ class test_Param(ClassChecker):
"Param('my_param')", 'default_from', 'create_default',
)
+ # Test that ValueError is raised if you provide both include and
+ # exclude:
+ e = raises(ValueError, self.cls, 'my_param',
+ include=['server', 'foo'],
+ exclude=['client', 'bar'],
+ )
+ assert str(e) == '%s: cannot have both %s=%r and %s=%r' % (
+ "Param('my_param')",
+ 'include', frozenset(['server', 'foo']),
+ 'exclude', frozenset(['client', 'bar']),
+ )
+
# Test that _get_default gets set:
call1 = lambda first, last: first[0] + last
call2 = lambda **kw: 'The Default'
@@ -245,6 +258,28 @@ class test_Param(ClassChecker):
o = self.cls('name', multivalue=True)
assert repr(o) == "Param('name', multivalue=True)"
+ def test_use_in_context(self):
+ """
+ Test the `ipalib.parameters.Param.use_in_context` method.
+ """
+ set1 = ('one', 'two', 'three')
+ set2 = ('four', 'five', 'six')
+ param1 = self.cls('param1')
+ param2 = self.cls('param2', include=set1)
+ param3 = self.cls('param3', exclude=set2)
+ for context in set1:
+ env = config.Env()
+ env.context = context
+ assert param1.use_in_context(env) is True, context
+ assert param2.use_in_context(env) is True, context
+ assert param3.use_in_context(env) is True, context
+ for context in set2:
+ env = config.Env()
+ env.context = context
+ assert param1.use_in_context(env) is True, context
+ assert param2.use_in_context(env) is False, context
+ assert param3.use_in_context(env) is False, context
+
def test_safe_value(self):
"""
Test the `ipalib.parameters.Param.safe_value` method.