diff options
| author | jiahui.qiang <jiahui.qiang@easystack.cn> | 2016-11-24 17:05:25 +0800 |
|---|---|---|
| committer | Dean Troyer <dtroyer@gmail.com> | 2017-01-25 21:31:45 +0000 |
| commit | c46f9dc501441ef449f41e726ec3cfbbe9f3de9d (patch) | |
| tree | a1a85ad25a26a9c5c235543208b104f60db76cd8 /openstackclient/tests | |
| parent | b69b539a422860bfb402093ff9d93a1b6e338b26 (diff) | |
| download | python-openstackclient-c46f9dc501441ef449f41e726ec3cfbbe9f3de9d.tar.gz | |
Add options to "server list" command
Add "--deleted" and "--changes-since" options to "server list" command.
Change-Id: Id94f6e5831a60b172b6cfcfca29b1d89de8db621
Closes-Bug:#1647242
Diffstat (limited to 'openstackclient/tests')
| -rw-r--r-- | openstackclient/tests/unit/compute/v2/test_server.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/openstackclient/tests/unit/compute/v2/test_server.py b/openstackclient/tests/unit/compute/v2/test_server.py index 54f36209..deba4435 100644 --- a/openstackclient/tests/unit/compute/v2/test_server.py +++ b/openstackclient/tests/unit/compute/v2/test_server.py @@ -19,6 +19,7 @@ from mock import call from osc_lib import exceptions from osc_lib import utils as common_utils +from oslo_utils import timeutils from openstackclient.compute.v2 import server from openstackclient.tests.unit.compute.v2 import fakes as compute_fakes @@ -826,6 +827,8 @@ class TestServerList(TestServer): 'tenant_id': None, 'all_tenants': False, 'user_id': None, + 'deleted': False, + 'changes_since': None, } # Default params of the core function of the command in the case of no @@ -902,6 +905,7 @@ class TestServerList(TestServer): verifylist = [ ('all_projects', False), ('long', False), + ('deleted', False), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -967,6 +971,48 @@ class TestServerList(TestServer): self.assertEqual(self.columns, columns) self.assertEqual(tuple(self.data), tuple(data)) + def test_server_list_with_changes_since(self): + + arglist = [ + '--changes-since', '2016-03-04T06:27:59Z', + '--deleted' + ] + verifylist = [ + ('changes_since', '2016-03-04T06:27:59Z'), + ('deleted', True), + ] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + columns, data = self.cmd.take_action(parsed_args) + + self.search_opts['changes_since'] = '2016-03-04T06:27:59Z' + self.search_opts['deleted'] = True + self.servers_mock.list.assert_called_with(**self.kwargs) + + self.assertEqual(self.columns, columns) + self.assertEqual(tuple(self.data), tuple(data)) + + @mock.patch.object(timeutils, 'parse_isotime', side_effect=ValueError) + def test_server_list_with_invalid_changes_since(self, mock_parse_isotime): + + arglist = [ + '--changes-since', 'Invalid time value', + ] + verifylist = [ + ('changes_since', 'Invalid time value'), + ] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + try: + self.cmd.take_action(parsed_args) + self.fail('CommandError should be raised.') + except exceptions.CommandError as e: + self.assertEqual('Invalid changes-since value: Invalid time ' + 'value', str(e)) + mock_parse_isotime.assert_called_once_with( + 'Invalid time value' + ) + class TestServerLock(TestServer): |
