From cfd4e2a7228c1e7f6ad677f2dd6dbd09e638dfb7 Mon Sep 17 00:00:00 2001 From: Huanxuan Ao Date: Thu, 9 Feb 2017 18:05:32 +0800 Subject: 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 --- .../tests/unit/identity/v3/test_group.py | 29 +++++++++++++++ .../tests/unit/identity/v3/test_role.py | 43 ++++++++++++++++++++++ 2 files changed, 72 insertions(+) (limited to 'openstackclient/tests/unit') 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): -- cgit v1.2.1