Merge "add negative unit test for delete attribute"

This commit is contained in:
Zuul 2023-07-03 08:53:11 +00:00 committed by Gerrit Code Review
commit fb942915a2
2 changed files with 13 additions and 0 deletions

View File

@ -130,6 +130,8 @@ class DeleteAttribute(command.Command):
try:
acc_client.delete_attribute(uuid, False)
print(_('Deleted attribute %s') % uuid)
except sdk_exc.ResourceNotFound:
raise exc.CommandError(_('Attribute %s not found') % uuid)
except exc.ClientException as e:
failures.append(_("Failed to delete attribute \
%(attribute)s: %(error)s")

View File

@ -205,3 +205,14 @@ class TestAttributeDelete(TestAttribute):
self.mock_acc_client.delete_attribute.assert_called_with(
acc_fakes.attribute_uuid, False)
def test_attribute_delete_not_exist(self):
get_arq_req = self.mock_acc_client.delete_attribute
get_arq_req.side_effect = sdk_exc.ResourceNotFound
arglist = [acc_fakes.attribute_uuid]
verifylist = []
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.assertRaisesRegex(
exc.CommandError,
'Attribute %s not found' % acc_fakes.attribute_uuid,
self.cmd.take_action, parsed_args)