On 03/26/2012 10:44 PM, Rob Crittenden wrote:
Petr Viktorin wrote:
Patch 25 fixes errors I found by running pylint on the testsuite. They
were in code that was unused, either by error or because it only runs on
errors.
Patch 26 adds a test for the batch plugin.
In patch 25 the second test_internal_error should really be
test_unauthorized_error. I think that is a clearer name. Otherwise looks
good.
Patch 26 needs a very minor rebase to fix an error caused by improved
error code handling:
expected = Fuzzy(u"invalid 'gidnumber'.*", <type 'unicode'>, None)
got = u"invalid 'gid': Gettext('must be an integer', domain='ipa',
localedir=None)"
I tested this:
diff --git a/tests/test_xmlrpc/test_batch_plugin.py
b/tests/test_xmlrpc/test_bat
ch_plugin.py
index e4280ed..d69bfd9 100644
--- a/tests/test_xmlrpc/test_batch_plugin.py
+++ b/tests/test_xmlrpc/test_batch_plugin.py
@@ -186,7 +186,7 @@ class test_batch(Declarative):
dict(error=u"'params' is required"),
dict(error=u"'givenname' is required"),
dict(error=u"'description' is required"),
- dict(error=Fuzzy(u"invalid 'gidnumber'.*")),
+ dict(error=Fuzzy(u"invalid 'gid'.*")),
),
),
),
rob
Thank you! Fixed, attaching updated patches.
--
PetrĀ³
From 51f582778ac1e7b901ea221d3aa1845a9f71a831 Mon Sep 17 00:00:00 2001
From: Petr Viktorin <pvikt...@redhat.com>
Date: Fri, 9 Mar 2012 11:48:32 -0500
Subject: [PATCH] Fix little test errors
Two test methods in test_rpcserver had the same name; the first didn't get
to run.
Another duplicate pair was in test_hbac_plugin with the same name; the ignored
test had small error in it.
check_TypeError used a wrong constant name
An error reporting function in test.util used uninitialized argument names.
This patch fixes these problems.
---
tests/test_ipaserver/test_rpcserver.py | 3 +--
tests/test_xmlrpc/test_hbac_plugin.py | 6 +++---
tests/util.py | 4 ++--
3 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/tests/test_ipaserver/test_rpcserver.py b/tests/test_ipaserver/test_rpcserver.py
index 97632b05d454b0ece60181ceeb6980b95e6909a1..96d4614a1325b3b21a6f58a59c472248c33b24bc 100644
--- a/tests/test_ipaserver/test_rpcserver.py
+++ b/tests/test_ipaserver/test_rpcserver.py
@@ -96,7 +96,7 @@ def test_internal_error():
assert s.headers == [('Content-Type', 'text/html; charset=utf-8')]
-def test_internal_error():
+def test_unauthorized_error():
f = rpcserver.HTTP_Status()
t = rpcserver._unauthorized_template
s = StartResponse()
@@ -109,7 +109,6 @@ def test_internal_error():
assert s.headers == [('Content-Type', 'text/html; charset=utf-8')]
-
def test_params_2_args_options():
"""
Test the `ipaserver.rpcserver.params_2_args_options` function.
diff --git a/tests/test_xmlrpc/test_hbac_plugin.py b/tests/test_xmlrpc/test_hbac_plugin.py
index 58265dc07c729fbaca0111807d511b0e906fc095..895d6c82ba9e4f1720858c95c14ee5e9406e75fe 100644
--- a/tests/test_xmlrpc/test_hbac_plugin.py
+++ b/tests/test_xmlrpc/test_hbac_plugin.py
@@ -263,8 +263,8 @@ def test_b_hbacrule_remove_host(self):
assert 'hostgroup' in failed['memberhost']
assert not failed['memberhost']['hostgroup']
entry = ret['result']
- assert 'memberhost_host' not in res[1]
- assert 'memberhost_hostgroup' not in res[1]
+ assert 'memberhost_host' not in entry
+ assert 'memberhost_hostgroup' not in entry
def test_a_hbacrule_add_sourcehost(self):
"""
@@ -314,7 +314,7 @@ def test_a_hbacrule_remove_service(self):
entry = ret['result']
assert 'memberservice service' not in entry
- def test_b_hbacrule_remove_host(self):
+ def test_b_hbacrule_remove_sourcehost(self):
"""
Test removing source host and hostgroup from HBAC rule using `xmlrpc.hbacrule_remove_host`.
"""
diff --git a/tests/util.py b/tests/util.py
index 5a365fbcd0e065b2f645b379b554b973d511c791..9bce7c08ca33de50dbc4ee57be61f2aa23dcb8be 100644
--- a/tests/util.py
+++ b/tests/util.py
@@ -446,7 +446,7 @@ def check_TypeError(value, type_, name, callback, *args, **kw):
assert e.type is type_
assert e.name == name
assert type(e.name) is str
- assert str(e) == ipalib.errors.TYPE_FORMAT % (name, type_, value)
+ assert str(e) == ipalib.errors.TYPE_ERROR % (name, type_, value)
return e
@@ -592,7 +592,7 @@ def __init__(self, *calls):
def __process(self, name_, args_, kw_):
if self.__i >= len(self.__calls):
raise AssertionError(
- 'extra call: %s, %r, %r' % (name, args, kw)
+ 'extra call: %s, %r, %r' % (name_, args_, kw_)
)
(name, args, kw, result) = self.__calls[self.__i]
self.__i += 1
--
1.7.7.6
From a68491c73561cb542396732d2e9df657860afa5e Mon Sep 17 00:00:00 2001
From: Petr Viktorin <pvikt...@redhat.com>
Date: Mon, 12 Mar 2012 05:58:44 -0400
Subject: [PATCH] Test the batch plugin
This adds tests for the batch plugin, and changes its output
declaration to allow results as tuples (this tripped validation).
The assert_deepequal function ignores the order of items in lists.
Document this in its docstring, and use a custom checker for the
batch plugin results.
---
ipalib/plugins/batch.py | 11 +-
tests/test_xmlrpc/test_batch_plugin.py | 194 ++++++++++++++++++++++++++++++++
tests/util.py | 3 +
3 files changed, 201 insertions(+), 7 deletions(-)
create mode 100644 tests/test_xmlrpc/test_batch_plugin.py
diff --git a/ipalib/plugins/batch.py b/ipalib/plugins/batch.py
index 4c5a6bd1e1b7ddb834f34e592837de5e233f7bcf..8abad5e1eeab5eeed46c5dc09f17bda1857f9562 100644
--- a/ipalib/plugins/batch.py
+++ b/ipalib/plugins/batch.py
@@ -76,11 +76,11 @@ class batch(Command):
has_output = (
Output('count', int, doc=''),
- Output('results', list, doc='')
+ Output('results', (list, tuple), doc='')
)
def execute(self, *args, **options):
- results=[]
+ results = []
for arg in args[0]:
params = dict()
name = None
@@ -92,11 +92,8 @@ def execute(self, *args, **options):
name = arg['method']
if name not in self.Command:
raise errors.CommandError(name=name)
- a = arg['params'][0]
- kw = arg['params'][1]
- newkw = {}
- for k in kw:
- newkw[str(k)] = kw[k]
+ a, kw = arg['params']
+ newkw = dict((str(k), v) for k, v in kw.iteritems())
params = api.Command[name].args_options_2_params(*a, **newkw)
result = api.Command[name](*a, **newkw)
diff --git a/tests/test_xmlrpc/test_batch_plugin.py b/tests/test_xmlrpc/test_batch_plugin.py
new file mode 100644
index 0000000000000000000000000000000000000000..d69bfd9c4193af2b8d96bd1f3178dc5566145a35
--- /dev/null
+++ b/tests/test_xmlrpc/test_batch_plugin.py
@@ -0,0 +1,194 @@
+# Authors:
+# Petr Viktorin <pvikt...@redhat.com>
+#
+# Copyright (C) 2012 Red Hat
+# see file 'COPYING' for use and warranty information
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+"""
+Test the `ipalib/plugins/batch.py` module.
+"""
+
+from ipalib import api, errors
+from tests.test_xmlrpc import objectclasses
+from tests.util import assert_equal, Fuzzy, assert_deepequal
+from xmlrpc_test import Declarative, fuzzy_digits, fuzzy_uuid
+from ipalib.dn import DN
+
+group1 = u'testgroup1'
+
+
+def deepequal_list(*expected):
+ """Factory for a function that checks a list
+
+ The created function asserts items of a list are "deepequal" to the given
+ argument. Unlike using assert_deepequal directly, the order matters.
+ """
+ def checker(got):
+ if len(expected) != len(got):
+ raise AssertionError('Expected %s entries, got %s\n\n%s\n%s' %
+ (len(expected), len(got), expected, got))
+ for e, g in zip(expected, got):
+ assert_deepequal(e, g)
+ return True
+ return checker
+
+
+class test_batch(Declarative):
+
+ cleanup_commands = [
+ ('group_del', [group1], {}),
+ ]
+
+ tests = [
+
+ dict(
+ desc='Batch ping',
+ command=('batch', [dict(method='ping', params=([], {}))], {}),
+ expected=dict(
+ count=1,
+ results=[
+ dict(summary=Fuzzy('IPA server version .*'), error=None),
+ ]
+ ),
+ ),
+
+ dict(
+ desc='Batch two pings',
+ command=('batch', [dict(method='ping', params=([], {}))] * 2, {}),
+ expected=dict(
+ count=2,
+ results=[
+ dict(summary=Fuzzy('IPA server version .*'), error=None),
+ dict(summary=Fuzzy('IPA server version .*'), error=None),
+ ]
+ ),
+ ),
+
+ dict(
+ desc='Create and deleting a group',
+ command=('batch', [
+ dict(method='group_add',
+ params=([group1], dict(description=u'Test desc 1'))),
+ dict(method='group_del', params=([group1], dict())),
+ ], {}),
+ expected=dict(
+ count=2,
+ results=deepequal_list(
+ dict(
+ value=group1,
+ summary=u'Added group "testgroup1"',
+ result=dict(
+ cn=[group1],
+ description=[u'Test desc 1'],
+ objectclass=objectclasses.group + [u'posixgroup'],
+ ipauniqueid=[fuzzy_uuid],
+ gidnumber=[fuzzy_digits],
+ dn=lambda x: DN(x) == \
+ DN(('cn', 'testgroup1'),
+ ('cn', 'groups'),
+ ('cn', 'accounts'),
+ api.env.basedn),
+ ),
+ error=None),
+ dict(
+ summary=u'Deleted group "%s"' % group1,
+ result=dict(failed=u''),
+ value=group1,
+ error=None),
+ ),
+ ),
+ ),
+
+ dict(
+ desc='Try to delete nonexistent group twice',
+ command=('batch', [
+ dict(method='group_del', params=([group1], dict())),
+ dict(method='group_del', params=([group1], dict())),
+ ], {}),
+ expected=dict(
+ count=2,
+ results=[
+ dict(error=u'%s: group not found' % group1),
+ dict(error=u'%s: group not found' % group1),
+ ],
+ ),
+ ),
+
+ dict(
+ desc='Try to delete non-existent group first, then create it',
+ command=('batch', [
+ dict(method='group_del', params=([group1], dict())),
+ dict(method='group_add',
+ params=([group1], dict(description=u'Test desc 1'))),
+ ], {}),
+ expected=dict(
+ count=2,
+ results=deepequal_list(
+ dict(error=u'%s: group not found' % group1),
+ dict(
+ value=group1,
+ summary=u'Added group "testgroup1"',
+ result=dict(
+ cn=[group1],
+ description=[u'Test desc 1'],
+ objectclass=objectclasses.group + [u'posixgroup'],
+ ipauniqueid=[fuzzy_uuid],
+ gidnumber=[fuzzy_digits],
+ dn=lambda x: DN(x) == \
+ DN(('cn', 'testgroup1'),
+ ('cn', 'groups'),
+ ('cn', 'accounts'),
+ api.env.basedn),
+ ),
+ error=None),
+ ),
+ ),
+ ),
+
+ dict(
+ desc='Try bad command invocations',
+ command=('batch', [
+ # bad command name
+ dict(method='nonexistent_ipa_command', params=([], dict())),
+ # dash, not underscore, in command name
+ dict(method='user-del', params=([], dict())),
+ # missing command name
+ dict(params=([group1], dict())),
+ # missing params
+ dict(method='user_del'),
+ # missing required argument
+ dict(method='user_add', params=([], dict())),
+ # missing required option
+ dict(method='group_add', params=([group1], dict())),
+ # bad type
+ dict(method='group_add', params=([group1], dict(
+ description=u't', gidnumber=u'bad'))),
+ ], {}),
+ expected=dict(
+ count=7,
+ results=deepequal_list(
+ dict(error=u"unknown command 'nonexistent_ipa_command'"),
+ dict(error=u"unknown command 'user-del'"),
+ dict(error=u"'method' is required"),
+ dict(error=u"'params' is required"),
+ dict(error=u"'givenname' is required"),
+ dict(error=u"'description' is required"),
+ dict(error=Fuzzy(u"invalid 'gid'.*")),
+ ),
+ ),
+ ),
+
+ ]
diff --git a/tests/util.py b/tests/util.py
index 9bce7c08ca33de50dbc4ee57be61f2aa23dcb8be..7929321a1310bbd7f4e6b84e8e222f75796f3170 100644
--- a/tests/util.py
+++ b/tests/util.py
@@ -287,6 +287,9 @@ def assert_deepequal(expected, got, doc='', stack=tuple()):
expected = u'how are you?'
got = 'how are you?'
path = (0, 'world')
+
+ Note that lists and tuples are considered equivalent, and the order of
+ their elements does not matter.
"""
if isinstance(expected, tuple):
expected = list(expected)
--
1.7.7.6
_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel