Fix errors in flavor unit tests

This patch fixes the problems below:
1. flavor.unset_keys() is not checked in flavor unit tests.
   So check them in the tests.
2. test_flavor_unset_no_project makes no sense. It is OK to
   specify ``--project ''`` without raising any exception.
   It can pass because in the test, we set nither project
   nor property. So remove this test.

Change-Id: I04e537349936343b6d8c85b06bc6d0ba6bd41d6f
This commit is contained in:
Tang Chen 2016-06-13 19:19:19 +08:00
parent 0695d1495e
commit c7e6973ff5

@ -644,6 +644,8 @@ class TestFlavorUnset(TestFlavor):
result = self.cmd.take_action(parsed_args)
self.flavors_mock.find.assert_called_with(name=parsed_args.flavor,
is_public=None)
self.flavor.unset_keys.assert_called_with(['property'])
self.flavor_access_mock.remove_tenant_access.assert_not_called()
self.assertIsNone(result)
def test_flavor_unset_project(self):
@ -660,24 +662,14 @@ class TestFlavorUnset(TestFlavor):
result = self.cmd.take_action(parsed_args)
self.assertIsNone(result)
self.flavors_mock.find.assert_called_with(name=parsed_args.flavor,
is_public=None)
self.flavor_access_mock.remove_tenant_access.assert_called_with(
self.flavor.id,
identity_fakes.project_id,
)
def test_flavor_unset_no_project(self):
arglist = [
'--project', '',
self.flavor.id,
]
verifylist = [
('project', ''),
('flavor', self.flavor.id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
parsed_args)
self.flavor.unset_keys.assert_not_called()
self.assertIsNone(result)
def test_flavor_unset_no_flavor(self):
arglist = [
@ -686,12 +678,8 @@ class TestFlavorUnset(TestFlavor):
verifylist = [
('project', identity_fakes.project_id),
]
self.assertRaises(tests_utils.ParserException,
self.check_parser,
self.cmd,
arglist,
verifylist)
self.assertRaises(tests_utils.ParserException, self.check_parser,
self.cmd, arglist, verifylist)
def test_flavor_unset_with_unexist_flavor(self):
self.flavors_mock.get.side_effect = exceptions.NotFound(None)
@ -706,9 +694,7 @@ class TestFlavorUnset(TestFlavor):
('flavor', 'unexist_flavor'),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.assertRaises(exceptions.CommandError,
self.cmd.take_action,
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
parsed_args)
def test_flavor_unset_nothing(self):
@ -718,7 +704,6 @@ class TestFlavorUnset(TestFlavor):
verifylist = [
('flavor', self.flavor.id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
parsed_args)