summaryrefslogtreecommitdiff
path: root/openstackclient/tests/compute
diff options
context:
space:
mode:
authorTang Chen <tangchen@cn.fujitsu.com>2015-12-02 17:24:41 +0800
committerTang Chen <tangchen@cn.fujitsu.com>2015-12-02 19:29:40 +0800
commitd7c3048f568ca59edf4db18c294d8d5d0573c178 (patch)
tree20756d84ec994547568c203478f2a07eee7d9360 /openstackclient/tests/compute
parentd37d27b2d6fd09b4b8ca111057f894a55725c579 (diff)
downloadpython-openstackclient-d7c3048f568ca59edf4db18c294d8d5d0573c178.tar.gz
Add class TestServerList to provide basic unit test for "server list" command.
This patch provide a class to test "server list" command. Only one simplest case in this patch. Some of the options in "server list" are complicated. And the server object contains lots of attributes need to be handled in specific ways. So other test cases will be added in other patches. Change-Id: Id9fdba8f149bd74187aa42516067dacebc6962b5 Implements: blueprint osc-unit-test-framework-improvement
Diffstat (limited to 'openstackclient/tests/compute')
-rw-r--r--openstackclient/tests/compute/v2/test_server.py81
1 files changed, 81 insertions, 0 deletions
diff --git a/openstackclient/tests/compute/v2/test_server.py b/openstackclient/tests/compute/v2/test_server.py
index 6cc314e8..359920f2 100644
--- a/openstackclient/tests/compute/v2/test_server.py
+++ b/openstackclient/tests/compute/v2/test_server.py
@@ -611,6 +611,87 @@ class TestServerImageCreate(TestServer):
self.assertEqual(datalist, data)
+class TestServerList(TestServer):
+
+ # Columns to be listed up.
+ columns = (
+ 'ID',
+ 'Name',
+ 'Status',
+ 'Networks',
+ )
+
+ # Data returned by corresponding Nova API. The elements in this list are
+ # tuples filled with server attributes.
+ data = []
+
+ # 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()
+
+ # The fake servers' attributes.
+ self.attrs = {
+ 'status': 'ACTIVE',
+ 'networks': {
+ u'public': [u'10.20.30.40', u'2001:db8::5']
+ },
+ }
+
+ # The servers to be listed.
+ self.servers = self.setup_servers_mock(3)
+
+ self.servers_mock.list.return_value = self.servers
+
+ # Get the command object to test
+ self.cmd = server.ListServer(self.app, None)
+
+ # Prepare data returned by fake Nova API.
+ for s in self.servers:
+ self.data.append((
+ s.id,
+ s.name,
+ s.status,
+ u'public=10.20.30.40, 2001:db8::5',
+ ))
+
+ def test_server_list_no_option(self):
+ arglist = []
+ verifylist = [
+ ('all_projects', False),
+ ('long', False),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.servers_mock.list.assert_called_with(**self.kwargs)
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(tuple(self.data), tuple(data))
+
+
class TestServerLock(TestServer):
def setUp(self):