summaryrefslogtreecommitdiffstats
path: root/tests/test_ipalib/test_frontend.py
diff options
context:
space:
mode:
authorPetr Viktorin <pviktori@redhat.com>2012-06-21 08:20:26 -0400
committerMartin Kosek <mkosek@redhat.com>2013-02-21 16:26:09 +0100
commit7336a176b43989b9d459a2536af88f89e849213f (patch)
tree46c2ab141dc545e8f0c148871508fe7c952d22e5 /tests/test_ipalib/test_frontend.py
parent246bc3f3eaccf2a84310df84dc85fe455c24ac65 (diff)
downloadfreeipa.git-7336a176b43989b9d459a2536af88f89e849213f.tar.gz
freeipa.git-7336a176b43989b9d459a2536af88f89e849213f.tar.xz
freeipa.git-7336a176b43989b9d459a2536af88f89e849213f.zip
Add the version option to all Commands
Several Commands were missing the 'version' option. Add it to those that were missing it. Do not remove the version option before calling commands. This means methods such as execute(), forward(), run() receive it. Several of these needed `**options` added to their signatures. Commands in the Cert plugin passed any unknown options to the underlying functions, these are changed to pass what's needed explicitly. Some commands in DNS and Batch plugins now pass version to commands they call. When the option is not given, fill it in automatically. (In a subsequent commit, a warning will be added in this case). Note that the public API did not change: all RPC calls already accepted a version option. There's no need for an API version bump (even though API.txt changes substantially). Design page: http://freeipa.org/page/V3/Messages Tickets: https://fedorahosted.org/freeipa/ticket/2732 https://fedorahosted.org/freeipa/ticket/3294
Diffstat (limited to 'tests/test_ipalib/test_frontend.py')
-rw-r--r--tests/test_ipalib/test_frontend.py58
1 files changed, 31 insertions, 27 deletions
diff --git a/tests/test_ipalib/test_frontend.py b/tests/test_ipalib/test_frontend.py
index 528609d9..4b473559 100644
--- a/tests/test_ipalib/test_frontend.py
+++ b/tests/test_ipalib/test_frontend.py
@@ -243,10 +243,14 @@ class test_Command(ClassChecker):
"""
Test the `ipalib.frontend.Command.get_options` method.
"""
- assert list(self.cls().get_options()) == []
+ options = list(self.cls().get_options())
+ assert len(options) == 1
+ assert options[0].name == 'version'
options = ('verbose', 'debug')
o = self.get_instance(options=options)
- assert tuple(o.get_options()) == options
+ assert len(tuple(o.get_options())) == 3
+ assert 'verbose' in tuple(o.get_options())
+ assert 'debug' in tuple(o.get_options())
def test_args(self):
"""
@@ -305,12 +309,12 @@ class test_Command(ClassChecker):
o = self.cls()
o.finalize()
assert type(o.options) is plugable.NameSpace
- assert len(o.options) == 0
+ assert len(o.options) == 1
options = ('target', 'files*')
ns = self.get_instance(options=options).options
assert type(ns) is plugable.NameSpace
- assert len(ns) == len(options)
- assert list(ns) == ['target', 'files']
+ assert len(ns) == len(options) + 1
+ assert list(ns) == ['target', 'files', 'version']
assert type(ns.target) is parameters.Str
assert type(ns.files) is parameters.Str
assert ns.target.required is True
@@ -377,12 +381,13 @@ class test_Command(ClassChecker):
cmd = user_add()
cmd.env = config.Env(context='cli')
cmd.finalize()
- assert list(cmd.params) == ['givenname', 'sn', 'uid']
+ assert list(cmd.params) == ['givenname', 'sn', 'uid', 'version']
ret = cmd.soft_validate({})
- assert len(ret['values']) == 0
- assert len(ret['errors']) == 3
+ assert sorted(ret['values']) == ['version']
+ assert sorted(ret['errors']) == ['givenname', 'sn', 'uid']
assert cmd.soft_validate(dict(givenname=u'First', sn=u'Last')) == dict(
- values=dict(givenname=u'First', sn=u'Last', uid=u'flast'),
+ values=dict(givenname=u'First', sn=u'Last', uid=u'flast',
+ version=None),
errors=dict(),
)
@@ -604,7 +609,6 @@ class test_Command(ClassChecker):
o.set_api(api)
assert o.run.im_func is self.cls.run.im_func
out = o.run(*args, **kw)
- del kw['version']
assert ('execute', args, kw) == out
# Test in non-server context
@@ -749,7 +753,7 @@ class test_LocalOrRemote(ClassChecker):
o = self.cls()
o.finalize()
assert list(o.args) == []
- assert list(o.options) == ['server']
+ assert list(o.options) == ['server', 'version']
op = o.options.server
assert op.required is False
assert op.default is False
@@ -772,17 +776,17 @@ class test_LocalOrRemote(ClassChecker):
api.register(example)
api.finalize()
cmd = api.Command.example
- assert cmd() == dict(
- result=('execute', (None,), dict(server=False))
+ assert cmd(version=u'2.47') == dict(
+ result=('execute', (None,), dict(version=u'2.47', server=False))
)
- assert cmd(u'var') == dict(
- result=('execute', (u'var',), dict(server=False))
+ assert cmd(u'var', version=u'2.47') == dict(
+ result=('execute', (u'var',), dict(version=u'2.47', server=False))
)
- assert cmd(server=True) == dict(
- result=('forward', (None,), dict(server=True))
+ assert cmd(server=True, version=u'2.47') == dict(
+ result=('forward', (None,), dict(version=u'2.47', server=True))
)
- assert cmd(u'var', server=True) == dict(
- result=('forward', (u'var',), dict(server=True))
+ assert cmd(u'var', server=True, version=u'2.47') == dict(
+ result=('forward', (u'var',), dict(version=u'2.47', server=True))
)
# Test when in_server=True (should always call execute):
@@ -790,17 +794,17 @@ class test_LocalOrRemote(ClassChecker):
api.register(example)
api.finalize()
cmd = api.Command.example
- assert cmd() == dict(
- result=('execute', (None,), dict(server=False))
+ assert cmd(version=u'2.47') == dict(
+ result=('execute', (None,), dict(version=u'2.47', server=False))
)
- assert cmd(u'var') == dict(
- result=('execute', (u'var',), dict(server=False))
+ assert cmd(u'var', version=u'2.47') == dict(
+ result=('execute', (u'var',), dict(version=u'2.47', server=False))
)
- assert cmd(server=True) == dict(
- result=('execute', (None,), dict(server=True))
+ assert cmd(server=True, version=u'2.47') == dict(
+ result=('execute', (None,), dict(version=u'2.47', server=True))
)
- assert cmd(u'var', server=True) == dict(
- result=('execute', (u'var',), dict(server=True))
+ assert cmd(u'var', server=True, version=u'2.47') == dict(
+ result=('execute', (u'var',), dict(version=u'2.47', server=True))
)