Add some test cases for "server list" command
Add some test cases that test 'server list' command when specifying flavor or image. Because I add some attribution to fake.py, I have to change some code in create server test. Despite all this, I think it's good for testing. Change-Id: I714deac1f6f940b790a3c20af5f7ffa724ac44d1
This commit is contained in:
parent
e5fe9a7071
commit
e0b6cab09b
openstackclient/tests/compute/v2
@ -377,6 +377,12 @@ class FakeServer(object):
|
||||
'id': 'server-id-' + uuid.uuid4().hex,
|
||||
'name': 'server-name-' + uuid.uuid4().hex,
|
||||
'metadata': {},
|
||||
'image': {
|
||||
'id': 'image-id-' + uuid.uuid4().hex,
|
||||
},
|
||||
'flavor': {
|
||||
'id': 'flavor-id-' + uuid.uuid4().hex,
|
||||
}
|
||||
}
|
||||
|
||||
# Overwrite default attributes.
|
||||
|
@ -12,7 +12,6 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
import mock
|
||||
|
||||
from mock import call
|
||||
@ -92,6 +91,7 @@ class TestServerCreate(TestServer):
|
||||
'addresses',
|
||||
'flavor',
|
||||
'id',
|
||||
'image',
|
||||
'name',
|
||||
'networks',
|
||||
'properties',
|
||||
@ -100,8 +100,9 @@ class TestServerCreate(TestServer):
|
||||
def datalist(self):
|
||||
datalist = (
|
||||
'',
|
||||
self.flavor.name + ' ()',
|
||||
self.flavor.name + ' (' + self.new_server.flavor.get('id') + ')',
|
||||
self.new_server.id,
|
||||
self.image.name + ' (' + self.new_server.image.get('id') + ')',
|
||||
self.new_server.name,
|
||||
self.new_server.networks,
|
||||
'',
|
||||
@ -617,33 +618,32 @@ class TestServerList(TestServer):
|
||||
'Properties',
|
||||
)
|
||||
|
||||
# Default search options, in the case of no commandline option specified.
|
||||
search_opts = {
|
||||
'reservation_id': None,
|
||||
'ip': None,
|
||||
'ip6': None,
|
||||
'name': None,
|
||||
'instance_name': None,
|
||||
'status': None,
|
||||
'flavor': None,
|
||||
'image': None,
|
||||
'host': None,
|
||||
'tenant_id': None,
|
||||
'all_tenants': False,
|
||||
'user_id': None,
|
||||
}
|
||||
|
||||
# Default params of the core function of the command in the case of no
|
||||
# commandline option specified.
|
||||
kwargs = {
|
||||
'search_opts': search_opts,
|
||||
'marker': None,
|
||||
'limit': None,
|
||||
}
|
||||
|
||||
def setUp(self):
|
||||
super(TestServerList, self).setUp()
|
||||
|
||||
self.search_opts = {
|
||||
'reservation_id': None,
|
||||
'ip': None,
|
||||
'ip6': None,
|
||||
'name': None,
|
||||
'instance_name': None,
|
||||
'status': None,
|
||||
'flavor': None,
|
||||
'image': None,
|
||||
'host': None,
|
||||
'tenant_id': None,
|
||||
'all_tenants': False,
|
||||
'user_id': None,
|
||||
}
|
||||
|
||||
# Default params of the core function of the command in the case of no
|
||||
# commandline option specified.
|
||||
self.kwargs = {
|
||||
'search_opts': self.search_opts,
|
||||
'marker': None,
|
||||
'limit': None,
|
||||
}
|
||||
|
||||
# The fake servers' attributes. Use the original attributes names in
|
||||
# nova, not the ones printed by "server list" command.
|
||||
self.attrs = {
|
||||
@ -660,9 +660,14 @@ class TestServerList(TestServer):
|
||||
|
||||
# The servers to be listed.
|
||||
self.servers = self.setup_servers_mock(3)
|
||||
|
||||
self.servers_mock.list.return_value = self.servers
|
||||
|
||||
self.image = image_fakes.FakeImage.create_one_image()
|
||||
self.cimages_mock.get.return_value = self.image
|
||||
|
||||
self.flavor = compute_fakes.FakeFlavor.create_one_flavor()
|
||||
self.flavors_mock.get.return_value = self.flavor
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = server.ListServer(self.app, None)
|
||||
|
||||
@ -721,6 +726,46 @@ class TestServerList(TestServer):
|
||||
self.assertEqual(self.columns_long, columns)
|
||||
self.assertEqual(tuple(self.data_long), tuple(data))
|
||||
|
||||
def test_server_list_with_image(self):
|
||||
|
||||
arglist = [
|
||||
'--image', self.image.id
|
||||
]
|
||||
verifylist = [
|
||||
('image', self.image.id)
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.cimages_mock.get.assert_called_with(self.image.id)
|
||||
|
||||
self.search_opts['image'] = self.image.id
|
||||
self.servers_mock.list.assert_called_with(**self.kwargs)
|
||||
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(tuple(self.data), tuple(data))
|
||||
|
||||
def test_server_list_with_flavor(self):
|
||||
|
||||
arglist = [
|
||||
'--flavor', self.flavor.id
|
||||
]
|
||||
verifylist = [
|
||||
('flavor', self.flavor.id)
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.flavors_mock.get.assert_called_with(self.flavor.id)
|
||||
|
||||
self.search_opts['flavor'] = self.flavor.id
|
||||
self.servers_mock.list.assert_called_with(**self.kwargs)
|
||||
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(tuple(self.data), tuple(data))
|
||||
|
||||
|
||||
class TestServerLock(TestServer):
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user