diff options
| author | Tang Chen <tangchen@cn.fujitsu.com> | 2015-12-09 19:42:52 +0800 |
|---|---|---|
| committer | Tang Chen <tangchen@cn.fujitsu.com> | 2015-12-09 19:42:52 +0800 |
| commit | 6a5be8c4c9abf25d7fa6a952ae466aedd056d353 (patch) | |
| tree | 28af2afad6042a4731b71ff982d7076a85e1ff8d /openstackclient/tests/compute | |
| parent | 85d6aeea32e1d208b4af1247012fe63e68922a7d (diff) | |
| download | python-openstackclient-6a5be8c4c9abf25d7fa6a952ae466aedd056d353.tar.gz | |
Add unit test for TestServerList to test --long option.
In two steps:
1. Setup all necessary attributes of a server in setUp(), including
the ones that are not faked in FaseServer by default.
2. Run a similar process with no option test case.
The future plan is to move all these attributes to FakeServer.
But it will cause some other changes which has nothing to do with
this patch. So leave this job to do later.
Change-Id: I1134812a0ea146ef737b0f0ffbef8ca23684accd
Implements: blueprint osc-unit-test-framework-improvement
Diffstat (limited to 'openstackclient/tests/compute')
| -rw-r--r-- | openstackclient/tests/compute/v2/test_server.py | 55 |
1 files changed, 50 insertions, 5 deletions
diff --git a/openstackclient/tests/compute/v2/test_server.py b/openstackclient/tests/compute/v2/test_server.py index ce2dcdf7..ec916b9f 100644 --- a/openstackclient/tests/compute/v2/test_server.py +++ b/openstackclient/tests/compute/v2/test_server.py @@ -620,10 +620,17 @@ class TestServerList(TestServer): 'Status', 'Networks', ) - - # Data returned by corresponding Nova API. The elements in this list are - # tuples filled with server attributes. - data = [] + columns_long = ( + 'ID', + 'Name', + 'Status', + 'Task State', + 'Power State', + 'Networks', + 'Availability Zone', + 'Host', + 'Properties', + ) # Default search options, in the case of no commandline option specified. search_opts = { @@ -652,12 +659,18 @@ class TestServerList(TestServer): def setUp(self): super(TestServerList, self).setUp() - # The fake servers' attributes. + # The fake servers' attributes. Use the original attributes names in + # nova, not the ones printed by "server list" command. self.attrs = { 'status': 'ACTIVE', + 'OS-EXT-STS:task_state': 'None', + 'OS-EXT-STS:power_state': 0x01, # Running 'networks': { u'public': [u'10.20.30.40', u'2001:db8::5'] }, + 'OS-EXT-AZ:availability_zone': 'availability-zone-xxx', + 'OS-EXT-SRV-ATTR:host': 'host-name-xxx', + 'Metadata': '', } # The servers to be listed. @@ -669,6 +682,9 @@ class TestServerList(TestServer): self.cmd = server.ListServer(self.app, None) # Prepare data returned by fake Nova API. + self.data = [] + self.data_long = [] + for s in self.servers: self.data.append(( s.id, @@ -676,6 +692,19 @@ class TestServerList(TestServer): s.status, server._format_servers_list_networks(s.networks), )) + self.data_long.append(( + s.id, + s.name, + s.status, + getattr(s, 'OS-EXT-STS:task_state'), + server._format_servers_list_power_state( + getattr(s, 'OS-EXT-STS:power_state') + ), + server._format_servers_list_networks(s.networks), + getattr(s, 'OS-EXT-AZ:availability_zone'), + getattr(s, 'OS-EXT-SRV-ATTR:host'), + s.Metadata, + )) def test_server_list_no_option(self): arglist = [] @@ -691,6 +720,22 @@ class TestServerList(TestServer): self.assertEqual(self.columns, columns) self.assertEqual(tuple(self.data), tuple(data)) + def test_server_list_long_option(self): + arglist = [ + '--long', + ] + verifylist = [ + ('all_projects', False), + ('long', True), + ] + 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_long, columns) + self.assertEqual(tuple(self.data_long), tuple(data)) + class TestServerLock(TestServer): |
