|
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 |
@@ -826,6 +827,8 @@ def setUp(self): |
826 | 827 | 'tenant_id': None, |
827 | 828 | 'all_tenants': False, |
828 | 829 | 'user_id': None, |
| 830 | + 'deleted': False, |
| 831 | + 'changes_since': None, |
829 | 832 | } |
830 | 833 |
|
831 | 834 | # Default params of the core function of the command in the case of no |
@@ -902,6 +905,7 @@ def test_server_list_no_option(self): |
902 | 905 | verifylist = [ |
903 | 906 | ('all_projects', False), |
904 | 907 | ('long', False), |
| 908 | + ('deleted', False), |
905 | 909 | ] |
906 | 910 | parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
907 | 911 |
|
@@ -967,6 +971,48 @@ def test_server_list_with_flavor(self): |
967 | 971 | self.assertEqual(self.columns, columns) |
968 | 972 | self.assertEqual(tuple(self.data), tuple(data)) |
969 | 973 |
|
| 974 | + def test_server_list_with_changes_since(self): |
| 975 | + |
| 976 | + arglist = [ |
| 977 | + '--changes-since', '2016-03-04T06:27:59Z', |
| 978 | + '--deleted' |
| 979 | + ] |
| 980 | + verifylist = [ |
| 981 | + ('changes_since', '2016-03-04T06:27:59Z'), |
| 982 | + ('deleted', True), |
| 983 | + ] |
| 984 | + |
| 985 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 986 | + columns, data = self.cmd.take_action(parsed_args) |
| 987 | + |
| 988 | + self.search_opts['changes_since'] = '2016-03-04T06:27:59Z' |
| 989 | + self.search_opts['deleted'] = True |
| 990 | + self.servers_mock.list.assert_called_with(**self.kwargs) |
| 991 | + |
| 992 | + self.assertEqual(self.columns, columns) |
| 993 | + self.assertEqual(tuple(self.data), tuple(data)) |
| 994 | + |
| 995 | + @mock.patch.object(timeutils, 'parse_isotime', side_effect=ValueError) |
| 996 | + def test_server_list_with_invalid_changes_since(self, mock_parse_isotime): |
| 997 | + |
| 998 | + arglist = [ |
| 999 | + '--changes-since', 'Invalid time value', |
| 1000 | + ] |
| 1001 | + verifylist = [ |
| 1002 | + ('changes_since', 'Invalid time value'), |
| 1003 | + ] |
| 1004 | + |
| 1005 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 1006 | + try: |
| 1007 | + self.cmd.take_action(parsed_args) |
| 1008 | + self.fail('CommandError should be raised.') |
| 1009 | + except exceptions.CommandError as e: |
| 1010 | + self.assertEqual('Invalid changes-since value: Invalid time ' |
| 1011 | + 'value', str(e)) |
| 1012 | + mock_parse_isotime.assert_called_once_with( |
| 1013 | + 'Invalid time value' |
| 1014 | + ) |
| 1015 | + |
970 | 1016 |
|
971 | 1017 | class TestServerLock(TestServer): |
972 | 1018 |
|
|
0 commit comments