Merge "Fix _list_view function for count"

This commit is contained in:
Zuul 2019-09-20 02:24:36 +00:00 committed by Gerrit Code Review
commit c1f575ec05
3 changed files with 44 additions and 1 deletions

View File

@ -178,7 +178,7 @@ class ViewBuilder(common.ViewBuilder):
self._collection_name)
shares_dict = dict(shares=shares_list)
if count:
if count is not None:
shares_dict['count'] = count
if shares_links:
shares_dict['shares_links'] = shares_links

View File

@ -1643,6 +1643,45 @@ class ShareAPITest(test.TestCase):
api_version.APIVersionRequest('2.42')):
self.assertEqual(3, result['count'])
@ddt.data({'use_admin_context': True, 'version': '2.42'},
{'use_admin_context': False, 'version': '2.42'})
@ddt.unpack
def test_share_list_summary_with_search_opt_count_0(self,
use_admin_context,
version):
search_opts = {
'sort_key': 'fake_sort_key',
'sort_dir': 'fake_sort_dir',
'with_count': 'true'
}
if use_admin_context:
search_opts['host'] = 'fake_host'
# fake_key should be filtered
url = '/shares?fake_key=fake_value'
for k, v in search_opts.items():
url = url + '&' + k + '=' + v
req = fakes.HTTPRequest.blank(url, version=version,
use_admin_context=use_admin_context)
self.mock_object(share_api.API, 'get_all',
mock.Mock(return_value=[]))
result = self.controller.index(req)
search_opts_expected = {}
if use_admin_context:
search_opts_expected.update({'fake_key': 'fake_value'})
search_opts_expected['host'] = search_opts['host']
share_api.API.get_all.assert_called_once_with(
req.environ['manila.context'],
sort_key=search_opts['sort_key'],
sort_dir=search_opts['sort_dir'],
search_opts=search_opts_expected,
)
self.assertEqual(0, len(result['shares']))
self.assertEqual(0, result['count'])
def test_share_list_summary(self):
self.mock_object(share_api.API, 'get_all',
stubs.stub_share_get_all_by_project)

View File

@ -0,0 +1,4 @@
fixes:
- Launchpad bug `1822815 <https://bugs.launchpad.net/manila/+bug/1822815>`_
has been fixed. The user no longer gets an error if the list command has
no rows when executing `manila list --count True`.