New Param: added Param.query kwarg for crud operations like Retrieve and Search where criteria should not be validated

This commit is contained in:
Jason Gerard DeRose 2009-01-14 14:04:05 -07:00
parent 79422d0489
commit cd3508bace
3 changed files with 15 additions and 4 deletions

View File

@ -50,13 +50,14 @@ class Del(frontend.Method):
for option in self.takes_options:
yield option
class Mod(frontend.Method):
def get_args(self):
yield self.obj.primary_key
def get_options(self):
for param in self.obj.params_minus_pk():
yield param.clone(required=False)
yield param.clone(required=False, query=True)
for option in self.takes_options:
yield option
@ -67,7 +68,7 @@ class Find(frontend.Method):
def get_options(self):
for param in self.obj.params_minus_pk():
yield param.clone(required=False)
yield param.clone(required=False, query=True)
for option in self.takes_options:
yield option

View File

@ -229,6 +229,7 @@ class Param(ReadOnly):
('default_from', DefaultFrom, None),
('create_default', callable, None),
('autofill', bool, False),
('query', bool, False),
('flags', frozenset, frozenset()),
# The 'default' kwarg gets appended in Param.__init__():
@ -489,6 +490,8 @@ class Param(ReadOnly):
:param value: A proposed value for this parameter.
"""
if self.query:
return
if value is None:
if self.required:
raise RequirementError(name=self.name)

View File

@ -164,6 +164,7 @@ class test_Param(ClassChecker):
assert o.create_default is None
assert o._get_default is None
assert o.autofill is False
assert o.query is False
assert o.flags == frozenset()
# Test that ValueError is raised when a kwarg from a subclass
@ -366,15 +367,21 @@ class test_Param(ClassChecker):
Test the `ipalib.parameters.Param.validate` method.
"""
# Test with required=True/False:
# Test in default state (with no rules, no kwarg):
o = self.cls('my_param')
assert o.required is True
e = raises(errors2.RequirementError, o.validate, None)
assert e.name == 'my_param'
# Test with required=False
o = self.cls('my_param', required=False)
assert o.required is False
assert o.validate(None) is None
# Test with query=True:
o = self.cls('my_param', query=True)
assert o.query is True
assert o.validate(None) is None
# Test with multivalue=True:
o = self.cls('my_param', multivalue=True)
e = raises(TypeError, o.validate, [])