Adding tests for v1/shell.py.

This patch includes unit test cases for all
commands in v1/shell.py.

Closes-bug: #1421082
Change-Id: I63e1d42f22874d30ad3c890fd4676b99a06717b0
This commit is contained in:
Madhuri Kumari
2015-02-13 07:56:59 +00:00
parent 104937fe38
commit b765567e02

View File

@@ -31,6 +31,228 @@ class ShellTest(base.TestCase):
def setUp(self):
super(ShellTest, self).setUp()
def test_do_bay_list(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
shell.do_bay_list(client_mock, args)
client_mock.bays.list.assert_called_once_with()
def test_do_bay_create(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
node_count = 1
args.node_count = node_count
name = "test_bay"
args.name = name
baymodel_id = "test_baymodel_id"
args.baymodel_id = baymodel_id
shell.do_bay_create(client_mock, args)
client_mock.bays.create.assert_called_once_with(
name=name, node_count=node_count, baymodel_id=baymodel_id)
def test_do_bay_delete(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
bay_id = 'id'
args.id = bay_id
shell.do_bay_delete(client_mock, args)
client_mock.bays.delete.assert_called_once_with(bay_id)
def test_do_bay_show(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
bay_id = 'id'
args.id = bay_id
shell.do_bay_show(client_mock, args)
client_mock.bays.get.assert_called_once_with(bay_id)
def test_do_baymodel_create(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
name = "test_baymodel"
args.name = name
image_id = "test_image"
args.image_id = image_id
flavor_id = "test_flavor"
args.flavor_id = flavor_id
keypair_id = "test_keypair"
args.keypair_id = keypair_id
external_network_id = "test_external_network_id"
args.external_network_id = external_network_id
dns_nameserver = "test_dns_nameserver"
args.dns_nameserver = dns_nameserver
shell.do_baymodel_create(client_mock, args)
client_mock.baymodels.create.assert_called_once_with(
name=name, image_id=image_id, flavor_id=flavor_id,
keypair_id=keypair_id, external_network_id=external_network_id,
dns_nameserver=dns_nameserver)
def test_do_baymodel_delete(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
baymodel_id = 'id'
args.id = baymodel_id
shell.do_baymodel_delete(client_mock, args)
client_mock.baymodels.delete.assert_called_once_with(baymodel_id)
def test_do_baymodel_show(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
baymodel_id = 'id'
args.id = baymodel_id
shell.do_baymodel_show(client_mock, args)
client_mock.baymodels.get.assert_called_once_with(baymodel_id)
def test_do_baymodel_list(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
shell.do_baymodel_list(client_mock, args)
client_mock.baymodels.list.assert_called_once_with()
def test_do_node_list(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
shell.do_node_list(client_mock, args)
client_mock.nodes.list.assert_called_once_with()
def test_do_node_create(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
type = "test_type"
args.type = type
image_id = "test_image"
args.image_id = image_id
shell.do_node_create(client_mock, args)
client_mock.nodes.create.assert_called_once_with(
type=type, image_id=image_id)
def test_do_pod_list(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
shell.do_pod_list(client_mock, args)
client_mock.pods.list.assert_called_once_with()
def test_do_pod_create(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
manifest_url = "test_url"
args.manifest_url = manifest_url
bay_id = "xxx"
args.bay_id = bay_id
manifest = "test_manifest"
args.manifest = manifest
shell.do_pod_create(client_mock, args)
client_mock.pods.create.assert_called_once_with(
manifest_url=manifest_url, bay_uuid=bay_id)
def test_do_pod_delete(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
pod_id = 'id'
args.id = pod_id
shell.do_pod_delete(client_mock, args)
client_mock.pods.delete.assert_called_once_with(pod_id)
def test_do_pod_show(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
pod_id = 'id'
args.id = pod_id
shell.do_pod_show(client_mock, args)
client_mock.pods.get.assert_called_once_with(pod_id)
def test_do_rc_list(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
shell.do_rc_list(client_mock, args)
client_mock.rcs.list.assert_called_once_with()
def test_do_rc_create(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
manifest_url = "test_url"
args.manifest_url = manifest_url
bay_id = "xxx"
args.bay_id = bay_id
manifest = "test_manifest"
args.manifest = manifest
shell.do_rc_create(client_mock, args)
client_mock.rcs.create.assert_called_once_with(
manifest_url=manifest_url, bay_uuid=bay_id)
def test_do_rc_delete(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
rc_id = 'id'
args.id = rc_id
shell.do_rc_delete(client_mock, args)
client_mock.rcs.delete.assert_called_once_with(rc_id)
def test_do_rc_show(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
rc_id = 'id'
args.id = rc_id
shell.do_rc_show(client_mock, args)
client_mock.rcs.get.assert_called_once_with(rc_id)
def test_do_service_list(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
shell.do_service_list(client_mock, args)
client_mock.services.list.assert_called_once_with()
def test_do_service_create(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
manifest_url = "test_url"
args.manifest_url = manifest_url
bay_id = "xxx"
args.bay_id = bay_id
manifest = "test_manifest"
args.manifest = manifest
shell.do_service_create(client_mock, args)
client_mock.services.create.assert_called_once_with(
manifest_url=manifest_url, bay_uuid=bay_id)
def test_do_service_delete(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
service_id = 'id'
args.id = service_id
shell.do_service_delete(client_mock, args)
client_mock.services.delete.assert_called_once_with(service_id)
def test_do_service_show(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
service_id = 'id'
args.id = service_id
shell.do_service_show(client_mock, args)
client_mock.services.get.assert_called_once_with(service_id)
def test_do_container_create(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
@@ -65,3 +287,69 @@ class ShellTest(base.TestCase):
shell.do_container_show(client_mock, args)
client_mock.containers.get.assert_called_once_with(container_id)
def test_do_container_reboot(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
container_id = 'id'
args.id = container_id
shell.do_container_reboot(client_mock, args)
client_mock.containers.reboot.assert_called_once_with(container_id)
def test_do_container_stop(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
container_id = 'id'
args.id = container_id
shell.do_container_stop(client_mock, args)
client_mock.containers.stop.assert_called_once_with(container_id)
def test_do_container_start(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
container_id = 'id'
args.id = container_id
shell.do_container_start(client_mock, args)
client_mock.containers.start.assert_called_once_with(container_id)
def test_do_container_pause(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
container_id = 'id'
args.id = container_id
shell.do_container_pause(client_mock, args)
client_mock.containers.pause.assert_called_once_with(container_id)
def test_do_container_unpause(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
container_id = 'id'
args.id = container_id
shell.do_container_unpause(client_mock, args)
client_mock.containers.unpause.assert_called_once_with(container_id)
def test_do_container_logs(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
container_id = 'id'
args.id = container_id
shell.do_container_logs(client_mock, args)
client_mock.containers.logs.assert_called_once_with(container_id)
def test_do_container_execute(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
container_id = 'id'
args.id = container_id
command = 'ls'
args.command = command
shell.do_container_execute(client_mock, args)
client_mock.containers.execute.assert_called_once_with(
container_id, command)