From ae39dece1386dbc3e9a07977a538d9b87acb5e30 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Wed, 21 Jan 2009 23:39:17 -0700 Subject: Added Command.args_options_2_params() method and its unit tests --- tests/test_ipalib/test_frontend.py | 51 ++++++++++++++++++++++++++++++++++-- tests/test_ipalib/test_parameters.py | 2 ++ tests/test_ipalib/test_rpc.py | 2 +- 3 files changed, 52 insertions(+), 3 deletions(-) (limited to 'tests/test_ipalib') diff --git a/tests/test_ipalib/test_frontend.py b/tests/test_ipalib/test_frontend.py index df61453ab..25e225135 100644 --- a/tests/test_ipalib/test_frontend.py +++ b/tests/test_ipalib/test_frontend.py @@ -329,14 +329,61 @@ class test_Command(ClassChecker): e = raises(errors.ArgumentError, o.args_to_kw, 1, 2, 3) assert str(e) == 'example takes at most 2 arguments' + def test_args_options_2_params(self): + """ + Test the `ipalib.frontend.Command.args_options_2_params` method. + """ + assert 'args_options_2_params' in self.cls.__public__ # Public + + # Test that ZeroArgumentError is raised: + o = self.get_instance() + e = raises(errors2.ZeroArgumentError, o.args_options_2_params, 1) + assert e.name == 'example' + + # Test that MaxArgumentError is raised (count=1) + o = self.get_instance(args=('one?',)) + e = raises(errors2.MaxArgumentError, o.args_options_2_params, 1, 2) + assert e.name == 'example' + assert e.count == 1 + assert str(e) == "command 'example' takes at most 1 argument" + + # Test that MaxArgumentError is raised (count=2) + o = self.get_instance(args=('one', 'two?')) + e = raises(errors2.MaxArgumentError, o.args_options_2_params, 1, 2, 3) + assert e.name == 'example' + assert e.count == 2 + assert str(e) == "command 'example' takes at most 2 arguments" + + # Test that OverlapError is raised: + o = self.get_instance(args=('one', 'two'), options=('three', 'four')) + e = raises(errors2.OverlapError, o.args_options_2_params, + 1, 2, three=3, two=2, four=4, one=1) + assert e.names == ['one', 'two'] + + # Test the permutations: + o = self.get_instance(args=('one', 'two*'), options=('three', 'four')) + mthd = o.args_options_2_params + assert mthd() == dict() + assert mthd(1) == dict(one=1) + assert mthd(1, 2) == dict(one=1, two=(2,)) + assert mthd(1, 21, 22, 23) == dict(one=1, two=(21, 22, 23)) + assert mthd(1, (21, 22, 23)) == dict(one=1, two=(21, 22, 23)) + assert mthd(three=3, four=4) == dict(three=3, four=4) + assert mthd(three=3, four=4, one=1, two=2) == \ + dict(one=1, two=2, three=3, four=4) + assert mthd(1, 21, 22, 23, three=3, four=4) == \ + dict(one=1, two=(21, 22, 23), three=3, four=4) + assert mthd(1, (21, 22, 23), three=3, four=4) == \ + dict(one=1, two=(21, 22, 23), three=3, four=4) + def test_params_2_args_options(self): """ Test the `ipalib.frontend.Command.params_2_args_options` method. """ assert 'params_2_args_options' in self.cls.__public__ # Public o = self.get_instance(args=['one'], options=['two']) - assert o.params_2_args_options({}) == ((None,), dict(two=None)) - assert o.params_2_args_options(dict(one=1)) == ((1,), dict(two=None)) + assert o.params_2_args_options({}) == ((None,), {}) + assert o.params_2_args_options(dict(one=1)) == ((1,), {}) assert o.params_2_args_options(dict(two=2)) == ((None,), dict(two=2)) assert o.params_2_args_options(dict(two=2, one=1)) == \ ((1,), dict(two=2)) diff --git a/tests/test_ipalib/test_parameters.py b/tests/test_ipalib/test_parameters.py index 261e14811..e9e514eb1 100644 --- a/tests/test_ipalib/test_parameters.py +++ b/tests/test_ipalib/test_parameters.py @@ -165,6 +165,8 @@ class test_Param(ClassChecker): assert o._get_default is None assert o.autofill is False assert o.query is False + assert o.attribute is False + assert o.limit_to is None assert o.flags == frozenset() # Test that ValueError is raised when a kwarg from a subclass diff --git a/tests/test_ipalib/test_rpc.py b/tests/test_ipalib/test_rpc.py index 296e9bc1c..bc8936ab6 100644 --- a/tests/test_ipalib/test_rpc.py +++ b/tests/test_ipalib/test_rpc.py @@ -221,7 +221,7 @@ class test_xmlclient(PluginTester): 'user_add', (rpc.xml_wrap(params),), {}, - Fault(3005, u"'four' is required"), # RequirementError + Fault(3007, u"'four' is required"), # RequirementError ), ( 'user_add', -- cgit