Test take_action() instead of run() in unit tests

Some of the unit tests test run(), but not take_action().

For example, in openstackclient/tests/volume/v1/test_volume.py, there is:

    def test_volume_set_size_smaller(self):
        ......

        result = self.cmd.run(parsed_args)

        self.assertEqual(0, result)
        ......

run() is defined in class Command in cliff. We don't need to test it in OSC
unit tests. On the contrary, we should test take_action(), which is
overwritten in each command classes in OSC.

Change-Id: If07e89953d40ac530f08cbb1ec05f5805171364b
Closes-bug: #1553468
This commit is contained in:
Tang Chen 2016-03-05 17:12:42 +08:00
parent fa3a34322c
commit eb1574281b
11 changed files with 107 additions and 101 deletions

View File

@ -307,12 +307,12 @@ class TestProjectDelete(TestProject):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
self.projects_mock.delete.assert_called_with(
identity_fakes.project_id,
)
self.assertIsNone(result)
class TestProjectList(TestProject):
@ -406,8 +406,9 @@ class TestProjectSet(TestProject):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
self.assertIsNone(result)
def test_project_set_name(self):
arglist = [
@ -422,8 +423,7 @@ class TestProjectSet(TestProject):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
@ -435,6 +435,7 @@ class TestProjectSet(TestProject):
identity_fakes.project_id,
**kwargs
)
self.assertIsNone(result)
def test_project_set_description(self):
arglist = [
@ -449,8 +450,7 @@ class TestProjectSet(TestProject):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
@ -462,6 +462,7 @@ class TestProjectSet(TestProject):
identity_fakes.project_id,
**kwargs
)
self.assertIsNone(result)
def test_project_set_enable(self):
arglist = [
@ -475,8 +476,7 @@ class TestProjectSet(TestProject):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
@ -488,6 +488,7 @@ class TestProjectSet(TestProject):
identity_fakes.project_id,
**kwargs
)
self.assertIsNone(result)
def test_project_set_disable(self):
arglist = [
@ -501,8 +502,7 @@ class TestProjectSet(TestProject):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
@ -514,6 +514,7 @@ class TestProjectSet(TestProject):
identity_fakes.project_id,
**kwargs
)
self.assertIsNone(result)
def test_project_set_property(self):
arglist = [
@ -527,8 +528,7 @@ class TestProjectSet(TestProject):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
@ -542,6 +542,7 @@ class TestProjectSet(TestProject):
identity_fakes.project_id,
**kwargs
)
self.assertIsNone(result)
class TestProjectShow(TestProject):
@ -615,7 +616,7 @@ class TestProjectUnset(TestProject):
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.run(parsed_args)
self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
'description': identity_fakes.project_description,

View File

@ -558,8 +558,9 @@ class TestUserSet(TestUser):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
self.assertIsNone(result)
def test_user_set_name(self):
arglist = [

View File

@ -87,12 +87,12 @@ class TestConsumerDelete(TestOAuth1):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
self.consumers_mock.delete.assert_called_with(
identity_fakes.consumer_id,
)
self.assertIsNone(result)
class TestConsumerList(TestOAuth1):
@ -208,11 +208,12 @@ class TestConsumerSet(TestOAuth1):
('consumer', identity_fakes.consumer_id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
kwargs = {'description': new_description}
self.consumers_mock.update.assert_called_with(
identity_fakes.consumer_id,
**kwargs
)
self.assertIsNone(result)

View File

@ -194,12 +194,12 @@ class TestDomainDelete(TestDomain):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
self.domains_mock.delete.assert_called_with(
identity_fakes.domain_id,
)
self.assertIsNone(result)
class TestDomainList(TestDomain):
@ -269,10 +269,10 @@ class TestDomainSet(TestDomain):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
self.assertNotCalled(self.domains_mock.update)
self.assertIsNone(result)
def test_domain_set_name(self):
arglist = [
@ -285,8 +285,7 @@ class TestDomainSet(TestDomain):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
@ -296,6 +295,7 @@ class TestDomainSet(TestDomain):
identity_fakes.domain_id,
**kwargs
)
self.assertIsNone(result)
def test_domain_set_description(self):
arglist = [
@ -308,8 +308,7 @@ class TestDomainSet(TestDomain):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
@ -319,6 +318,7 @@ class TestDomainSet(TestDomain):
identity_fakes.domain_id,
**kwargs
)
self.assertIsNone(result)
def test_domain_set_enable(self):
arglist = [
@ -331,8 +331,7 @@ class TestDomainSet(TestDomain):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
@ -342,6 +341,7 @@ class TestDomainSet(TestDomain):
identity_fakes.domain_id,
**kwargs
)
self.assertIsNone(result)
def test_domain_set_disable(self):
arglist = [
@ -354,8 +354,7 @@ class TestDomainSet(TestDomain):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
@ -365,6 +364,7 @@ class TestDomainSet(TestDomain):
identity_fakes.domain_id,
**kwargs
)
self.assertIsNone(result)
class TestDomainShow(TestDomain):

View File

@ -277,12 +277,12 @@ class TestEndpointDelete(TestEndpoint):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
self.endpoints_mock.delete.assert_called_with(
identity_fakes.endpoint_id,
)
self.assertIsNone(result)
class TestEndpointList(TestEndpoint):
@ -483,10 +483,10 @@ class TestEndpointSet(TestEndpoint):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
self.assertNotCalled(self.endpoints_mock.update)
self.assertIsNone(result)
def test_endpoint_set_interface(self):
arglist = [
@ -499,8 +499,7 @@ class TestEndpointSet(TestEndpoint):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
@ -514,6 +513,7 @@ class TestEndpointSet(TestEndpoint):
identity_fakes.endpoint_id,
**kwargs
)
self.assertIsNone(result)
def test_endpoint_set_url(self):
arglist = [
@ -526,8 +526,7 @@ class TestEndpointSet(TestEndpoint):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
@ -541,6 +540,7 @@ class TestEndpointSet(TestEndpoint):
identity_fakes.endpoint_id,
**kwargs
)
self.assertIsNone(result)
def test_endpoint_set_service(self):
arglist = [
@ -553,8 +553,7 @@ class TestEndpointSet(TestEndpoint):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
@ -568,6 +567,7 @@ class TestEndpointSet(TestEndpoint):
identity_fakes.endpoint_id,
**kwargs
)
self.assertIsNone(result)
def test_endpoint_set_region(self):
arglist = [
@ -580,8 +580,7 @@ class TestEndpointSet(TestEndpoint):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
@ -595,6 +594,7 @@ class TestEndpointSet(TestEndpoint):
identity_fakes.endpoint_id,
**kwargs
)
self.assertIsNone(result)
def test_endpoint_set_enable(self):
arglist = [
@ -607,8 +607,7 @@ class TestEndpointSet(TestEndpoint):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
@ -622,6 +621,7 @@ class TestEndpointSet(TestEndpoint):
identity_fakes.endpoint_id,
**kwargs
)
self.assertIsNone(result)
def test_endpoint_set_disable(self):
arglist = [
@ -634,8 +634,7 @@ class TestEndpointSet(TestEndpoint):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
@ -649,6 +648,7 @@ class TestEndpointSet(TestEndpoint):
identity_fakes.endpoint_id,
**kwargs
)
self.assertIsNone(result)
class TestEndpointShow(TestEndpoint):

View File

@ -436,12 +436,12 @@ class TestProjectDelete(TestProject):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
self.projects_mock.delete.assert_called_with(
identity_fakes.project_id,
)
self.assertIsNone(result)
class TestProjectList(TestProject):
@ -593,8 +593,9 @@ class TestProjectSet(TestProject):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
self.assertIsNone(result)
def test_project_set_name(self):
arglist = [
@ -611,8 +612,7 @@ class TestProjectSet(TestProject):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
@ -624,6 +624,7 @@ class TestProjectSet(TestProject):
identity_fakes.project_id,
**kwargs
)
self.assertIsNone(result)
def test_project_set_description(self):
arglist = [
@ -640,8 +641,7 @@ class TestProjectSet(TestProject):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
@ -651,6 +651,7 @@ class TestProjectSet(TestProject):
identity_fakes.project_id,
**kwargs
)
self.assertIsNone(result)
def test_project_set_enable(self):
arglist = [
@ -666,8 +667,7 @@ class TestProjectSet(TestProject):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
@ -677,6 +677,7 @@ class TestProjectSet(TestProject):
identity_fakes.project_id,
**kwargs
)
self.assertIsNone(result)
def test_project_set_disable(self):
arglist = [
@ -692,8 +693,7 @@ class TestProjectSet(TestProject):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
@ -703,6 +703,7 @@ class TestProjectSet(TestProject):
identity_fakes.project_id,
**kwargs
)
self.assertIsNone(result)
def test_project_set_property(self):
arglist = [
@ -718,8 +719,7 @@ class TestProjectSet(TestProject):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
@ -730,6 +730,7 @@ class TestProjectSet(TestProject):
identity_fakes.project_id,
**kwargs
)
self.assertIsNone(result)
class TestProjectShow(TestProject):

View File

@ -157,12 +157,12 @@ class TestRegionDelete(TestRegion):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
self.regions_mock.delete.assert_called_with(
identity_fakes.region_id,
)
self.assertIsNone(result)
class TestRegionList(TestRegion):
@ -251,10 +251,10 @@ class TestRegionSet(TestRegion):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
self.assertNotCalled(self.regions_mock.update)
self.assertIsNone(result)
def test_region_set_description(self):
arglist = [
@ -267,8 +267,7 @@ class TestRegionSet(TestRegion):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
@ -278,6 +277,7 @@ class TestRegionSet(TestRegion):
identity_fakes.region_id,
**kwargs
)
self.assertIsNone(result)
def test_region_set_parent_region_id(self):
arglist = [
@ -290,8 +290,7 @@ class TestRegionSet(TestRegion):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
@ -301,6 +300,7 @@ class TestRegionSet(TestRegion):
identity_fakes.region_id,
**kwargs
)
self.assertIsNone(result)
class TestRegionShow(TestRegion):

View File

@ -116,8 +116,7 @@ class TestRoleAdd(TestRole):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
@ -130,6 +129,7 @@ class TestRoleAdd(TestRole):
identity_fakes.role_id,
**kwargs
)
self.assertIsNone(result)
def test_role_add_user_project(self):
arglist = [
@ -149,8 +149,7 @@ class TestRoleAdd(TestRole):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
@ -163,6 +162,7 @@ class TestRoleAdd(TestRole):
identity_fakes.role_id,
**kwargs
)
self.assertIsNone(result)
def test_role_add_group_domain(self):
arglist = [
@ -182,8 +182,7 @@ class TestRoleAdd(TestRole):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
@ -196,6 +195,7 @@ class TestRoleAdd(TestRole):
identity_fakes.role_id,
**kwargs
)
self.assertIsNone(result)
def test_role_add_group_project(self):
arglist = [
@ -215,8 +215,7 @@ class TestRoleAdd(TestRole):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
@ -229,6 +228,7 @@ class TestRoleAdd(TestRole):
identity_fakes.role_id,
**kwargs
)
self.assertIsNone(result)
class TestRoleAddInherited(TestRoleAdd, TestRoleInherited):

View File

@ -204,12 +204,12 @@ class TestServiceDelete(TestService):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
self.services_mock.delete.assert_called_with(
identity_fakes.service_id,
)
self.assertIsNone(result)
class TestServiceList(TestService):
@ -310,8 +310,9 @@ class TestServiceSet(TestService):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
self.assertIsNone(result)
def test_service_set_type(self):
arglist = [
@ -328,8 +329,7 @@ class TestServiceSet(TestService):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
@ -340,6 +340,7 @@ class TestServiceSet(TestService):
identity_fakes.service_id,
**kwargs
)
self.assertIsNone(result)
def test_service_set_name(self):
arglist = [
@ -356,8 +357,7 @@ class TestServiceSet(TestService):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
@ -368,6 +368,7 @@ class TestServiceSet(TestService):
identity_fakes.service_id,
**kwargs
)
self.assertIsNone(result)
def test_service_set_description(self):
arglist = [
@ -384,8 +385,7 @@ class TestServiceSet(TestService):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
@ -396,6 +396,7 @@ class TestServiceSet(TestService):
identity_fakes.service_id,
**kwargs
)
self.assertIsNone(result)
def test_service_set_enable(self):
arglist = [
@ -412,8 +413,7 @@ class TestServiceSet(TestService):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
@ -424,6 +424,7 @@ class TestServiceSet(TestService):
identity_fakes.service_id,
**kwargs
)
self.assertIsNone(result)
def test_service_set_disable(self):
arglist = [
@ -440,8 +441,7 @@ class TestServiceSet(TestService):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
@ -452,6 +452,7 @@ class TestServiceSet(TestService):
identity_fakes.service_id,
**kwargs
)
self.assertIsNone(result)
class TestServiceShow(TestService):

View File

@ -754,8 +754,9 @@ class TestUserSet(TestUser):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
self.assertEqual(0, result)
result = self.cmd.take_action(parsed_args)
self.assertIsNone(result)
def test_user_set_name(self):
arglist = [

View File

@ -577,11 +577,11 @@ class TestVolumeSet(TestVolume):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
result = self.cmd.take_action(parsed_args)
self.assertEqual(0, result)
self.assertEqual("No changes requested\n",
self.app.log.messages.get('error'))
self.assertIsNone(result)
def test_volume_set_name(self):
arglist = [
@ -673,12 +673,12 @@ class TestVolumeSet(TestVolume):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
result = self.cmd.take_action(parsed_args)
self.assertEqual(0, result)
self.assertEqual("New size must be greater than %s GB" %
volume_fakes.volume_size,
self.app.log.messages.get('error'))
self.assertIsNone(result)
def test_volume_set_size_not_available(self):
self.volumes_mock.get.return_value.status = 'error'
@ -695,12 +695,12 @@ class TestVolumeSet(TestVolume):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args)
result = self.cmd.take_action(parsed_args)
self.assertEqual(0, result)
self.assertEqual("Volume is in %s state, it must be available before "
"size can be extended" % 'error',
self.app.log.messages.get('error'))
self.assertIsNone(result)
def test_volume_set_property(self):
arglist = [