mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
parent
bf778a74a3
commit
ffc6031ad7
@ -579,9 +579,15 @@ class Param(ReadOnly):
|
||||
"""
|
||||
Return a new `Param` instance similar to this one.
|
||||
"""
|
||||
return self.clone_rename(self.name, **overrides)
|
||||
|
||||
def clone_rename(self, name, **overrides):
|
||||
"""
|
||||
Return a new `Param` instance similar to this one, but named differently
|
||||
"""
|
||||
kw = dict(self.__clonekw)
|
||||
kw.update(overrides)
|
||||
return self.__class__(self.name, *self.rules, **kw)
|
||||
return self.__class__(name, *self.rules, **kw)
|
||||
|
||||
def normalize(self, value):
|
||||
"""
|
||||
|
@ -708,6 +708,17 @@ class LDAPUpdate(LDAPQuery, crud.Update):
|
||||
|
||||
has_output_params = global_output_params
|
||||
|
||||
def _get_rename_option(self):
|
||||
rdnparam = getattr(self.obj.params, self.obj.rdnattr)
|
||||
return rdnparam.clone_rename('rename', cli_name='rename',
|
||||
doc=_('Rename the %s object' % self.obj.object_name))
|
||||
|
||||
def get_options(self):
|
||||
for option in super(LDAPUpdate, self).get_options():
|
||||
yield option
|
||||
if self.obj.rdnattr:
|
||||
yield self._get_rename_option()
|
||||
|
||||
def execute(self, *keys, **options):
|
||||
ldap = self.obj.backend
|
||||
|
||||
@ -768,6 +779,9 @@ class LDAPUpdate(LDAPQuery, crud.Update):
|
||||
|
||||
rdnupdate = False
|
||||
try:
|
||||
if self.obj.rdnattr and 'rename' in options:
|
||||
entry_attrs[self.obj.rdnattr] = options['rename']
|
||||
|
||||
if self.obj.rdnattr and self.obj.rdnattr in entry_attrs:
|
||||
# RDN change
|
||||
ldap.update_entry_rdn(dn, unicode('%s=%s' % (self.obj.rdnattr,
|
||||
|
@ -359,6 +359,34 @@ class test_Param(ClassChecker):
|
||||
assert clone.param_spec == 'my_param'
|
||||
assert clone.name == 'my_param'
|
||||
|
||||
def test_clone_rename(self):
|
||||
"""
|
||||
Test the `ipalib.parameters.Param.clone` method.
|
||||
"""
|
||||
new_name = 'my_new_param'
|
||||
|
||||
# Test with the defaults
|
||||
orig = self.cls('my_param')
|
||||
clone = orig.clone_rename(new_name)
|
||||
assert clone is not orig
|
||||
assert type(clone) is self.cls
|
||||
assert clone.name == new_name
|
||||
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_rename(new_name, 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 == new_name
|
||||
assert clone.name == new_name
|
||||
|
||||
|
||||
def test_convert(self):
|
||||
"""
|
||||
Test the `ipalib.parameters.Param.convert` method.
|
||||
|
Loading…
Reference in New Issue
Block a user