for k, v in search_opts.iteritems():
try:
search_opts[k] = ast.literal_eval(v)
- except ValueError:
+ except (ValueError, SyntaxError):
LOG.debug('Could not evaluate value %s, assuming string', v)
context = req.environ['cinder.context']
for k, v in filters.iteritems():
try:
filters[k] = ast.literal_eval(v)
- except ValueError:
+ except (ValueError, SyntaxError):
LOG.debug('Could not evaluate value %s, assuming string', v)
volumes = self.volume_api.get_all(context, marker, limit, sort_key,
self.assertIn('volumes', res)
self.assertEqual(1, len(res['volumes']))
- @mock.patch('cinder.utils.add_visible_admin_metadata')
@mock.patch('cinder.volume.api.API.get_all')
- def test_get_volumes_filter_with_string(self, get_all, add_meta):
+ def test_get_volumes_filter_with_string(self, get_all):
req = mock.MagicMock()
req.GET.copy.return_value = {'display_name': 'Volume-573108026'}
context = mock.Mock()
req.environ = {'cinder.context': context}
self.controller._items(req, mock.Mock)
- get_all.assert_any_call(context, sort_dir='desc',
- viewable_admin_meta=True,
- sort_key='created_at',
- limit=None,
- filters={'display_name': 'Volume-573108026'},
- marker=None)
-
- @mock.patch('cinder.utils.add_visible_admin_metadata')
+ get_all.assert_called_once_with(
+ context, sort_dir='desc', viewable_admin_meta=True,
+ sort_key='created_at', limit=None,
+ filters={'display_name': 'Volume-573108026'}, marker=None)
+
@mock.patch('cinder.volume.api.API.get_all')
- def test_get_volumes_filter_with_list(self, get_all, add_meta):
+ def test_get_volumes_filter_with_list(self, get_all):
req = mock.MagicMock()
req.GET.copy.return_value = {'id': "['1', '2', '3']"}
context = mock.Mock()
req.environ = {'cinder.context': context}
self.controller._items(req, mock.Mock)
- get_all.assert_any_call(context, sort_dir='desc',
- viewable_admin_meta=True,
- sort_key='created_at',
- limit=None, filters={'id': ['1', '2', '3']},
- marker=None)
+ get_all.assert_called_once_with(
+ context, sort_dir='desc', viewable_admin_meta=True,
+ sort_key='created_at', limit=None,
+ filters={'id': ['1', '2', '3']}, marker=None)
+
+ @mock.patch('cinder.volume.api.API.get_all')
+ def test_get_volumes_filter_with_expression(self, get_all):
+ req = mock.MagicMock()
+ req.GET.copy.return_value = {'id': "d+"}
+ context = mock.Mock()
+ req.environ = {'cinder.context': context}
+ self.controller._items(req, mock.Mock)
+ get_all.assert_called_once_with(
+ context, sort_dir='desc', viewable_admin_meta=True,
+ sort_key='created_at', limit=None, filters={'id': 'd+'},
+ marker=None)
class VolumeSerializerTest(test.TestCase):
body = {'volume': 'string'}
self._create_volume_bad_request(body=body)
- @mock.patch('cinder.utils.add_visible_admin_metadata')
@mock.patch('cinder.volume.api.API.get_all')
- def test_get_volumes_filter_with_string(self, get_all, add_meta):
+ def test_get_volumes_filter_with_string(self, get_all):
req = mock.MagicMock()
context = mock.Mock()
req.environ = {'cinder.context': context}
req.params = {'display_name': 'Volume-573108026'}
self.controller._view_builder.detail_list = mock.Mock()
self.controller._get_volumes(req, True)
- get_all.assert_any_call(context, None, None, 'created_at', 'desc',
- {'display_name': 'Volume-573108026'},
- viewable_admin_meta=True)
+ get_all.assert_called_once_with(
+ context, None, None, 'created_at', 'desc',
+ {'display_name': 'Volume-573108026'}, viewable_admin_meta=True)
- @mock.patch('cinder.utils.add_visible_admin_metadata')
@mock.patch('cinder.volume.api.API.get_all')
- def test_get_volumes_filter_with_list(self, get_all, add_meta):
+ def test_get_volumes_filter_with_list(self, get_all):
req = mock.MagicMock()
context = mock.Mock()
req.environ = {'cinder.context': context}
req.params = {'id': "['1', '2', '3']"}
self.controller._view_builder.detail_list = mock.Mock()
self.controller._get_volumes(req, True)
- get_all.assert_any_call(context, None, None, 'created_at', 'desc',
- {'id': ['1', '2', '3']},
- viewable_admin_meta=True)
+ get_all.assert_called_once_with(
+ context, None, None, 'created_at', 'desc',
+ {'id': ['1', '2', '3']}, viewable_admin_meta=True)
+
+ @mock.patch('cinder.volume.api.API.get_all')
+ def test_get_volumes_filter_with_expression(self, get_all):
+ req = mock.MagicMock()
+ context = mock.Mock()
+ req.environ = {'cinder.context': context}
+ req.params = {'name': "d-"}
+ self.controller._view_builder.detail_list = mock.Mock()
+ self.controller._get_volumes(req, True)
+ get_all.assert_called_once_with(
+ context, None, None, 'created_at', 'desc',
+ {'display_name': 'd-'}, viewable_admin_meta=True)
class VolumeSerializerTest(test.TestCase):