summaryrefslogtreecommitdiffstats
path: root/tests/test_xmlrpc/test_automount_plugin.py
diff options
context:
space:
mode:
authorPetr Viktorin <pviktori@redhat.com>2012-03-09 09:41:16 -0500
committerMartin Kosek <mkosek@redhat.com>2012-03-19 16:33:35 +0100
commitc14a2d824557b06fd20bac77ddfc9e09001e2a92 (patch)
tree0f8f012dc47ab7ecb8574a53eeeba12706edc336 /tests/test_xmlrpc/test_automount_plugin.py
parent35521ad6bb92057d5faefa2059d7d800bebb1af0 (diff)
downloadfreeipa-c14a2d824557b06fd20bac77ddfc9e09001e2a92.tar.gz
freeipa-c14a2d824557b06fd20bac77ddfc9e09001e2a92.tar.xz
freeipa-c14a2d824557b06fd20bac77ddfc9e09001e2a92.zip
Use nose tools to check for exceptions
Some of our tests checked for exceptions using an error-prone try block: they allowed the expected exception to pass, but sometimes forgot an else block, so the test passed when an exception wasn't thrown. This changes the tests to use the appropriate nose tools (raises, assert_raises). For consistency, tests that had a correct else block are also changed. Also fix some test problems that were hidden by the above: - in some sudorule and HBAC tests, change the *_add_user argument name from `users` to `user` - don't remove HBAC testing data while it was still used
Diffstat (limited to 'tests/test_xmlrpc/test_automount_plugin.py')
-rw-r--r--tests/test_xmlrpc/test_automount_plugin.py86
1 files changed, 18 insertions, 68 deletions
diff --git a/tests/test_xmlrpc/test_automount_plugin.py b/tests/test_xmlrpc/test_automount_plugin.py
index cfea61270..dedd2346a 100644
--- a/tests/test_xmlrpc/test_automount_plugin.py
+++ b/tests/test_xmlrpc/test_automount_plugin.py
@@ -22,6 +22,8 @@ Test the `ipalib/plugins/automount.py' module.
"""
import sys
+from nose.tools import raises, assert_raises # pylint: disable=E0611
+
from xmlrpc_test import XMLRPC_test, assert_attr_equal
from ipalib import api
from ipalib import errors
@@ -77,16 +79,12 @@ class test_automount(XMLRPC_test):
assert res
assert_attr_equal(res, 'automountkey', self.keyname)
+ @raises(errors.DuplicateEntry)
def test_4_automountkey_add(self):
"""
Test adding a duplicate key using `xmlrpc.automountkey_add` method.
"""
- try:
- api.Command['automountkey_add'](self.locname, self.mapname, **self.key_kw)
- except errors.DuplicateEntry:
- pass
- else:
- assert False
+ res = api.Command['automountkey_add'](self.locname, self.mapname, **self.key_kw)
def test_5_automountmap_show(self):
"""
@@ -153,12 +151,8 @@ class test_automount(XMLRPC_test):
assert_attr_equal(res, 'failed', '')
# Verify that it is gone
- try:
+ with assert_raises(errors.NotFound):
api.Command['automountkey_show'](self.locname, self.mapname, **delkey_kw)
- except errors.NotFound:
- pass
- else:
- assert False
def test_c_automountlocation_del(self):
"""
@@ -169,12 +163,8 @@ class test_automount(XMLRPC_test):
assert_attr_equal(res, 'failed', '')
# Verify that it is gone
- try:
+ with assert_raises(errors.NotFound):
api.Command['automountlocation_show'](self.locname)
- except errors.NotFound:
- pass
- else:
- assert False
def test_d_automountmap_del(self):
"""
@@ -182,12 +172,8 @@ class test_automount(XMLRPC_test):
"""
# Verify that the second key we added is gone
key_kw = {'automountkey': self.keyname2, 'automountinformation': self.info, 'raw': True}
- try:
+ with assert_raises(errors.NotFound):
api.Command['automountkey_show'](self.locname, self.mapname, **key_kw)
- except errors.NotFound:
- pass
- else:
- assert False
class test_automount_direct(XMLRPC_test):
"""
@@ -214,16 +200,12 @@ class test_automount_direct(XMLRPC_test):
assert res
assert_attr_equal(res, 'automountmapname', self.mapname)
+ @raises(errors.DuplicateEntry)
def test_2_automountmap_add_duplicate(self):
"""
Test adding a duplicate direct map.
"""
- try:
- res = api.Command['automountmap_add_indirect'](self.locname, self.mapname, **self.direct_kw)['result']
- except errors.DuplicateEntry:
- pass
- else:
- assert False
+ res = api.Command['automountmap_add_indirect'](self.locname, self.mapname, **self.direct_kw)['result']
def test_3_automountlocation_del(self):
"""
@@ -234,12 +216,8 @@ class test_automount_direct(XMLRPC_test):
assert_attr_equal(res, 'failed', '')
# Verity that it is gone
- try:
+ with assert_raises(errors.NotFound):
api.Command['automountlocation_show'](self.locname)
- except errors.NotFound:
- pass
- else:
- assert False
class test_automount_indirect(XMLRPC_test):
"""
@@ -269,16 +247,12 @@ class test_automount_indirect(XMLRPC_test):
assert res
assert_attr_equal(res, 'automountmapname', self.mapname)
+ @raises(errors.DuplicateEntry)
def test_1a_automountmap_add_indirect(self):
"""
Test adding a duplicate indirect map.
"""
- try:
- api.Command['automountmap_add_indirect'](self.locname, self.mapname, **self.map_kw)['result']
- except errors.DuplicateEntry:
- pass
- else:
- assert False
+ api.Command['automountmap_add_indirect'](self.locname, self.mapname, **self.map_kw)['result']
def test_2_automountmap_show(self):
"""
@@ -297,12 +271,8 @@ class test_automount_indirect(XMLRPC_test):
assert_attr_equal(res, 'failed', '')
# Verify that it is gone
- try:
+ with assert_raises(errors.NotFound):
api.Command['automountkey_show'](self.locname, self.parentmap, **self.key_kw)
- except errors.NotFound:
- pass
- else:
- assert False
def test_4_automountmap_del(self):
"""
@@ -313,12 +283,8 @@ class test_automount_indirect(XMLRPC_test):
assert_attr_equal(res, 'failed', '')
# Verify that it is gone
- try:
+ with assert_raises(errors.NotFound):
api.Command['automountmap_show'](self.locname, self.mapname)
- except errors.NotFound:
- pass
- else:
- assert False
def test_5_automountlocation_del(self):
"""
@@ -329,12 +295,8 @@ class test_automount_indirect(XMLRPC_test):
assert_attr_equal(res, 'failed', '')
# Verity that it is gone
- try:
+ with assert_raises(errors.NotFound):
api.Command['automountlocation_show'](self.locname)
- except errors.NotFound:
- pass
- else:
- assert False
class test_automount_indirect_no_parent(XMLRPC_test):
@@ -382,12 +344,8 @@ class test_automount_indirect_no_parent(XMLRPC_test):
assert_attr_equal(res, 'failed', '')
# Verify that it is gone
- try:
+ with assert_raises(errors.NotFound):
api.Command['automountkey_show'](self.locname, self.parentmap, **delkey_kw)
- except errors.NotFound:
- pass
- else:
- assert False
def test_4_automountmap_del(self):
"""
@@ -398,12 +356,8 @@ class test_automount_indirect_no_parent(XMLRPC_test):
assert_attr_equal(res, 'failed', '')
# Verify that it is gone
- try:
+ with assert_raises(errors.NotFound):
api.Command['automountmap_show'](self.locname, self.mapname)
- except errors.NotFound:
- pass
- else:
- assert False
def test_5_automountlocation_del(self):
"""
@@ -414,9 +368,5 @@ class test_automount_indirect_no_parent(XMLRPC_test):
assert_attr_equal(res, 'failed', '')
# Verity that it is gone
- try:
+ with assert_raises(errors.NotFound):
api.Command['automountlocation_show'](self.locname)
- except errors.NotFound:
- pass
- else:
- assert False