mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-20 11:48:43 -06:00
New Param: added Param.clone() method and corresponding unit test
This commit is contained in:
parent
a0fb215a2c
commit
659bb4c142
@ -329,6 +329,14 @@ class Param(ReadOnly):
|
||||
**self.__kw
|
||||
)
|
||||
|
||||
def clone(self, **overrides):
|
||||
"""
|
||||
Return a new `Param` instance similar to this one.
|
||||
"""
|
||||
kw = dict(self.__clonekw)
|
||||
kw.update(overrides)
|
||||
return self.__class__(self.name, **kw)
|
||||
|
||||
def get_label(self):
|
||||
"""
|
||||
Return translated label using `request.ugettext`.
|
||||
|
@ -239,6 +239,41 @@ class test_Param(ClassChecker):
|
||||
o = self.cls('name', multivalue=True)
|
||||
assert repr(o) == "Param('name', multivalue=True)"
|
||||
|
||||
def test_clone(self):
|
||||
"""
|
||||
Test the `ipalib.parameter.Param.clone` method.
|
||||
"""
|
||||
# Test with the defaults
|
||||
orig = self.cls('my_param')
|
||||
clone = orig.clone()
|
||||
assert clone is not orig
|
||||
assert type(clone) is self.cls
|
||||
assert clone.name is orig.name
|
||||
for (key, kind, default) in self.cls.kwargs:
|
||||
assert getattr(clone, key) is getattr(orig, key)
|
||||
|
||||
# Test with a param spec:
|
||||
orig = self.cls('my_param*')
|
||||
assert orig.param_spec == 'my_param*'
|
||||
clone = orig.clone()
|
||||
assert clone.param_spec == 'my_param'
|
||||
assert clone is not orig
|
||||
assert type(clone) is self.cls
|
||||
for (key, kind, default) in self.cls.kwargs:
|
||||
assert getattr(clone, key) is getattr(orig, key)
|
||||
|
||||
# Test with overrides:
|
||||
orig = self.cls('my_param*')
|
||||
assert orig.required is False
|
||||
assert orig.multivalue is True
|
||||
clone = orig.clone(required=True)
|
||||
assert clone is not orig
|
||||
assert type(clone) is self.cls
|
||||
assert clone.required is True
|
||||
assert clone.multivalue is True
|
||||
assert clone.param_spec == 'my_param'
|
||||
assert clone.name == 'my_param'
|
||||
|
||||
def test_get_label(self):
|
||||
"""
|
||||
Test the `ipalib.parameter.get_label` method.
|
||||
|
Loading…
Reference in New Issue
Block a user