summaryrefslogtreecommitdiff
path: root/openstackclient/tests/unit
diff options
context:
space:
mode:
authorHuanxuan Ao <huanxuan.ao@easystack.cn>2017-02-09 18:05:32 +0800
committerHuanxuan Ao <huanxuan.ao@easystack.cn>2017-02-09 19:49:55 +0800
commitcfd4e2a7228c1e7f6ad677f2dd6dbd09e638dfb7 (patch)
treef25b74a7c67369012d2564456237055d45192152 /openstackclient/tests/unit
parent46d1df0adf00862a4b9ff21925836539a0e2f98f (diff)
downloadpython-openstackclient-cfd4e2a7228c1e7f6ad677f2dd6dbd09e638dfb7.tar.gz
Modify error handling for role and group commands
if command failed, we usually raise exception, if command success, sometimes there is not any output (such as set, add commands) So modify the error handling for role and group commands. Change-Id: I1c0f86c04dcedd9c0d725fd73f3436be9da75ee0
Diffstat (limited to 'openstackclient/tests/unit')
-rw-r--r--openstackclient/tests/unit/identity/v3/test_group.py29
-rw-r--r--openstackclient/tests/unit/identity/v3/test_role.py43
2 files changed, 72 insertions, 0 deletions
diff --git a/openstackclient/tests/unit/identity/v3/test_group.py b/openstackclient/tests/unit/identity/v3/test_group.py
index 8558de95..00bd217d 100644
--- a/openstackclient/tests/unit/identity/v3/test_group.py
+++ b/openstackclient/tests/unit/identity/v3/test_group.py
@@ -70,6 +70,20 @@ class TestGroupAddUser(TestGroup):
self.user.id, self.group.id)
self.assertIsNone(result)
+ def test_group_add_user_with_error(self):
+ self.users_mock.add_to_group.side_effect = exceptions.CommandError()
+ arglist = [
+ self.group.name,
+ self.user.name,
+ ]
+ verifylist = [
+ ('group', self.group.name),
+ ('user', self.user.name),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ self.assertRaises(exceptions.CommandError,
+ self.cmd.take_action, parsed_args)
+
class TestGroupCheckUser(TestGroup):
@@ -460,6 +474,21 @@ class TestGroupRemoveUser(TestGroup):
self.user.id, self.group.id)
self.assertIsNone(result)
+ def test_group_remove_user_with_error(self):
+ self.users_mock.remove_from_group.side_effect = (
+ exceptions.CommandError())
+ arglist = [
+ self.group.id,
+ self.user.id,
+ ]
+ verifylist = [
+ ('group', self.group.id),
+ ('user', self.user.id),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ self.assertRaises(exceptions.CommandError,
+ self.cmd.take_action, parsed_args)
+
class TestGroupSet(TestGroup):
diff --git a/openstackclient/tests/unit/identity/v3/test_role.py b/openstackclient/tests/unit/identity/v3/test_role.py
index c0b68bdf..39dbd244 100644
--- a/openstackclient/tests/unit/identity/v3/test_role.py
+++ b/openstackclient/tests/unit/identity/v3/test_role.py
@@ -273,6 +273,22 @@ class TestRoleAdd(TestRole):
)
self.assertIsNone(result)
+ def test_role_add_with_error(self):
+ arglist = [
+ identity_fakes.role_name,
+ ]
+ verifylist = [
+ ('user', None),
+ ('group', None),
+ ('domain', None),
+ ('project', None),
+ ('role', identity_fakes.role_name),
+ ('inherited', False),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ self.assertRaises(exceptions.CommandError,
+ self.cmd.take_action, parsed_args)
+
class TestRoleAddInherited(TestRoleAdd, TestRoleInherited):
pass
@@ -771,6 +787,17 @@ class TestRoleList(TestRole):
), )
self.assertEqual(datalist, tuple(data))
+ def test_role_list_group_with_error(self):
+ arglist = [
+ '--group', identity_fakes.group_id,
+ ]
+ verifylist = [
+ ('group', identity_fakes.group_id),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ self.assertRaises(exceptions.CommandError,
+ self.cmd.take_action, parsed_args)
+
class TestRoleRemove(TestRole):
@@ -982,6 +1009,22 @@ class TestRoleRemove(TestRole):
)
self.assertIsNone(result)
+ def test_role_remove_with_error(self):
+ arglist = [
+ identity_fakes.role_name,
+ ]
+ verifylist = [
+ ('user', None),
+ ('group', None),
+ ('domain', None),
+ ('project', None),
+ ('role', identity_fakes.role_name),
+ ('inherited', False),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ self.assertRaises(exceptions.CommandError,
+ self.cmd.take_action, parsed_args)
+
class TestRoleSet(TestRole):