|
19 | 19 |
|
20 | 20 | from osc_lib import exceptions |
21 | 21 | from osc_lib import utils as common_utils |
| 22 | +from oslo_utils import timeutils |
22 | 23 |
|
23 | 24 | from openstackclient.compute.v2 import server |
24 | 25 | from openstackclient.tests.unit.compute.v2 import fakes as compute_fakes |
@@ -831,6 +832,8 @@ def setUp(self): |
831 | 832 | 'tenant_id': None, |
832 | 833 | 'all_tenants': False, |
833 | 834 | 'user_id': None, |
| 835 | + 'deleted': False, |
| 836 | + 'changes_since': None, |
834 | 837 | } |
835 | 838 |
|
836 | 839 | # Default params of the core function of the command in the case of no |
@@ -907,6 +910,7 @@ def test_server_list_no_option(self): |
907 | 910 | verifylist = [ |
908 | 911 | ('all_projects', False), |
909 | 912 | ('long', False), |
| 913 | + ('deleted', False), |
910 | 914 | ] |
911 | 915 | parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
912 | 916 |
|
@@ -972,6 +976,48 @@ def test_server_list_with_flavor(self): |
972 | 976 | self.assertEqual(self.columns, columns) |
973 | 977 | self.assertEqual(tuple(self.data), tuple(data)) |
974 | 978 |
|
| 979 | + def test_server_list_with_changes_since(self): |
| 980 | + |
| 981 | + arglist = [ |
| 982 | + '--changes-since', '2016-03-04T06:27:59Z', |
| 983 | + '--deleted' |
| 984 | + ] |
| 985 | + verifylist = [ |
| 986 | + ('changes_since', '2016-03-04T06:27:59Z'), |
| 987 | + ('deleted', True), |
| 988 | + ] |
| 989 | + |
| 990 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 991 | + columns, data = self.cmd.take_action(parsed_args) |
| 992 | + |
| 993 | + self.search_opts['changes_since'] = '2016-03-04T06:27:59Z' |
| 994 | + self.search_opts['deleted'] = True |
| 995 | + self.servers_mock.list.assert_called_with(**self.kwargs) |
| 996 | + |
| 997 | + self.assertEqual(self.columns, columns) |
| 998 | + self.assertEqual(tuple(self.data), tuple(data)) |
| 999 | + |
| 1000 | + @mock.patch.object(timeutils, 'parse_isotime', side_effect=ValueError) |
| 1001 | + def test_server_list_with_invalid_changes_since(self, mock_parse_isotime): |
| 1002 | + |
| 1003 | + arglist = [ |
| 1004 | + '--changes-since', 'Invalid time value', |
| 1005 | + ] |
| 1006 | + verifylist = [ |
| 1007 | + ('changes_since', 'Invalid time value'), |
| 1008 | + ] |
| 1009 | + |
| 1010 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 1011 | + try: |
| 1012 | + self.cmd.take_action(parsed_args) |
| 1013 | + self.fail('CommandError should be raised.') |
| 1014 | + except exceptions.CommandError as e: |
| 1015 | + self.assertEqual('Invalid changes-since value: Invalid time ' |
| 1016 | + 'value', str(e)) |
| 1017 | + mock_parse_isotime.assert_called_once_with( |
| 1018 | + 'Invalid time value' |
| 1019 | + ) |
| 1020 | + |
975 | 1021 |
|
976 | 1022 | class TestServerLock(TestServer): |
977 | 1023 |
|
|
0 commit comments