Skip to content

Commit c7e6973

Browse files
author
Tang Chen
committed
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
1 parent 0695d14 commit c7e6973

1 file changed

Lines changed: 9 additions & 24 deletions

File tree

openstackclient/tests/compute/v2/test_flavor.py

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,8 @@ def test_flavor_unset_property(self):
644644
result = self.cmd.take_action(parsed_args)
645645
self.flavors_mock.find.assert_called_with(name=parsed_args.flavor,
646646
is_public=None)
647+
self.flavor.unset_keys.assert_called_with(['property'])
648+
self.flavor_access_mock.remove_tenant_access.assert_not_called()
647649
self.assertIsNone(result)
648650

649651
def test_flavor_unset_project(self):
@@ -660,24 +662,14 @@ def test_flavor_unset_project(self):
660662
result = self.cmd.take_action(parsed_args)
661663
self.assertIsNone(result)
662664

665+
self.flavors_mock.find.assert_called_with(name=parsed_args.flavor,
666+
is_public=None)
663667
self.flavor_access_mock.remove_tenant_access.assert_called_with(
664668
self.flavor.id,
665669
identity_fakes.project_id,
666670
)
667-
668-
def test_flavor_unset_no_project(self):
669-
arglist = [
670-
'--project', '',
671-
self.flavor.id,
672-
]
673-
verifylist = [
674-
('project', ''),
675-
('flavor', self.flavor.id),
676-
]
677-
678-
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
679-
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
680-
parsed_args)
671+
self.flavor.unset_keys.assert_not_called()
672+
self.assertIsNone(result)
681673

682674
def test_flavor_unset_no_flavor(self):
683675
arglist = [
@@ -686,12 +678,8 @@ def test_flavor_unset_no_flavor(self):
686678
verifylist = [
687679
('project', identity_fakes.project_id),
688680
]
689-
690-
self.assertRaises(tests_utils.ParserException,
691-
self.check_parser,
692-
self.cmd,
693-
arglist,
694-
verifylist)
681+
self.assertRaises(tests_utils.ParserException, self.check_parser,
682+
self.cmd, arglist, verifylist)
695683

696684
def test_flavor_unset_with_unexist_flavor(self):
697685
self.flavors_mock.get.side_effect = exceptions.NotFound(None)
@@ -706,9 +694,7 @@ def test_flavor_unset_with_unexist_flavor(self):
706694
('flavor', 'unexist_flavor'),
707695
]
708696
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
709-
710-
self.assertRaises(exceptions.CommandError,
711-
self.cmd.take_action,
697+
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
712698
parsed_args)
713699

714700
def test_flavor_unset_nothing(self):
@@ -718,7 +704,6 @@ def test_flavor_unset_nothing(self):
718704
verifylist = [
719705
('flavor', self.flavor.id),
720706
]
721-
722707
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
723708
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
724709
parsed_args)

0 commit comments

Comments
 (0)