Merge "Add testcases for compute.v2.service"

This commit is contained in:
Jenkins 2015-11-30 13:09:59 +00:00 committed by Gerrit Code Review
commit cbd4f67b04
2 changed files with 109 additions and 5 deletions

View File

@ -25,8 +25,6 @@ from openstackclient.tests import utils
from openstackclient.tests.volume.v2 import fakes as volume_fakes
service_id = '1'
extension_name = 'Multinic'
extension_namespace = 'http://docs.openstack.org/compute/ext/'\
'multinic/api/v1.1'
@ -80,6 +78,15 @@ QUOTA_data = tuple(QUOTA[x] for x in sorted(QUOTA))
block_device_mapping = 'vda=' + volume_fakes.volume_name + ':::0'
service_host = 'host_test'
service_binary = 'compute_test'
service_status = 'enabled'
SERVICE = {
'host': service_host,
'binary': service_binary,
'status': service_status,
}
class FakeComputev2Client(object):
def __init__(self, **kwargs):

View File

@ -13,8 +13,11 @@
# under the License.
#
import copy
from openstackclient.compute.v2 import service
from openstackclient.tests.compute.v2 import fakes as compute_fakes
from openstackclient.tests import fakes
class TestService(compute_fakes.TestComputev2):
@ -39,10 +42,10 @@ class TestServiceDelete(TestService):
def test_service_delete_no_options(self):
arglist = [
compute_fakes.service_id,
compute_fakes.service_binary,
]
verifylist = [
('service', compute_fakes.service_id),
('service', compute_fakes.service_binary),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -50,5 +53,99 @@ class TestServiceDelete(TestService):
self.cmd.take_action(parsed_args)
self.service_mock.delete.assert_called_with(
compute_fakes.service_id,
compute_fakes.service_binary,
)
class TestServiceList(TestService):
def setUp(self):
super(TestServiceList, self).setUp()
self.service_mock.list.return_value = [fakes.FakeResource(
None,
copy.deepcopy(compute_fakes.SERVICE),
loaded=True,
)]
# Get the command object to test
self.cmd = service.ListService(self.app, None)
def test_service_list(self):
arglist = [
'--host', compute_fakes.service_host,
'--service', compute_fakes.service_binary,
]
verifylist = [
('host', compute_fakes.service_host),
('service', compute_fakes.service_binary),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# DisplayCommandBase.take_action() returns two tuples
self.cmd.take_action(parsed_args)
self.service_mock.list.assert_called_with(
compute_fakes.service_host,
compute_fakes.service_binary,
)
class TestServiceSet(TestService):
def setUp(self):
super(TestServiceSet, self).setUp()
self.service_mock.enable.return_value = [fakes.FakeResource(
None,
copy.deepcopy(compute_fakes.SERVICE),
loaded=True,
)]
self.service_mock.disable.return_value = [fakes.FakeResource(
None,
copy.deepcopy(compute_fakes.SERVICE),
loaded=True,
)]
self.cmd = service.SetService(self.app, None)
def test_service_set_enable(self):
arglist = [
compute_fakes.service_host,
compute_fakes.service_binary,
'--enable',
]
verifylist = [
('host', compute_fakes.service_host),
('service', compute_fakes.service_binary),
('enabled', True),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
self.service_mock.enable.assert_called_with(
compute_fakes.service_host,
compute_fakes.service_binary,
)
def test_service_set_disable(self):
arglist = [
compute_fakes.service_host,
compute_fakes.service_binary,
'--disable',
]
verifylist = [
('host', compute_fakes.service_host),
('service', compute_fakes.service_binary),
('enabled', False),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
self.service_mock.disable.assert_called_with(
compute_fakes.service_host,
compute_fakes.service_binary,
)