コード例 #1
0
    def _snapshot_list_summary_with_search_opts(self, use_admin_context):
        search_opts = fake_share.search_opts()
        # fake_key should be filtered for non-admin
        url = '/snapshots?fake_key=fake_value'
        for k, v in search_opts.items():
            url = url + '&' + k + '=' + v
        req = fakes.HTTPRequest.blank(url, use_admin_context=use_admin_context)

        snapshots = [
            {'id': 'id1', 'display_name': 'n1', 'status': 'fake_status', },
            {'id': 'id2', 'display_name': 'n2', 'status': 'fake_status', },
            {'id': 'id3', 'display_name': 'n3', 'status': 'fake_status', },
        ]
        self.mock_object(share_api.API, 'get_all_snapshots',
                         mock.Mock(return_value=snapshots))

        result = self.controller.index(req)

        search_opts_expected = {
            'display_name': search_opts['name'],
            'status': search_opts['status'],
            'share_id': search_opts['share_id'],
        }
        if use_admin_context:
            search_opts_expected.update({'fake_key': 'fake_value'})
        share_api.API.get_all_snapshots.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(1, len(result['snapshots']))
        self.assertEqual(snapshots[1]['id'], result['snapshots'][0]['id'])
        self.assertEqual(
            snapshots[1]['display_name'], result['snapshots'][0]['name'])
コード例 #2
0
    def _snapshot_list_summary_with_search_opts(self, use_admin_context):
        search_opts = fake_share.search_opts()
        # fake_key should be filtered for non-admin
        url = '/snapshots?fake_key=fake_value'
        for k, v in search_opts.items():
            url = url + '&' + k + '=' + v
        req = fakes.HTTPRequest.blank(url, use_admin_context=use_admin_context)

        snapshots = [
            {
                'id': 'id1',
                'display_name': 'n1',
                'status': 'fake_status',
                'share_id': 'fake_share_id'
            },
            {
                'id': 'id2',
                'display_name': 'n2',
                'status': 'fake_status',
                'share_id': 'fake_share_id'
            },
            {
                'id': 'id3',
                'display_name': 'n3',
                'status': 'fake_status',
                'share_id': 'fake_share_id'
            },
        ]
        self.mock_object(share_api.API, 'get_all_snapshots',
                         mock.Mock(return_value=snapshots))

        result = self.controller.index(req)

        search_opts_expected = {
            'display_name': search_opts['name'],
            'status': search_opts['status'],
            'share_id': search_opts['share_id'],
        }
        if use_admin_context:
            search_opts_expected.update({'fake_key': 'fake_value'})
        share_api.API.get_all_snapshots.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(1, len(result['snapshots']))
        self.assertEqual(snapshots[1]['id'], result['snapshots'][0]['id'])
        self.assertEqual(snapshots[1]['display_name'],
                         result['snapshots'][0]['name'])
コード例 #3
0
    def _snapshot_list_summary_with_search_opts(self, version,
                                                use_admin_context):
        search_opts = fake_share.search_opts()
        if (api_version.APIVersionRequest(version) >=
                api_version.APIVersionRequest('2.36')):
            search_opts.pop('name')
            search_opts['display_name~'] = 'fake_name'
        # fake_key should be filtered for non-admin
        url = '/v2/fake/snapshots?fake_key=fake_value'
        for k, v in search_opts.items():
            url = url + '&' + k + '=' + v
        req = fakes.HTTPRequest.blank(url,
                                      use_admin_context=use_admin_context,
                                      version=version)

        db_snapshots = [
            {
                'id': 'id1',
                'display_name': 'n1',
                'status': 'fake_status',
            },
            {
                'id': 'id2',
                'display_name': 'n2',
                'status': 'fake_status',
            },
            {
                'id': 'id3',
                'display_name': 'n3',
                'status': 'fake_status',
            },
        ]
        snapshots = [db_snapshots[1]]
        self.mock_object(share_api.API, 'get_all_snapshots',
                         mock.Mock(return_value=snapshots))

        result = self.controller.index(req)

        search_opts_expected = {
            'status': search_opts['status'],
            'share_id': search_opts['share_id'],
        }
        if (api_version.APIVersionRequest(version) >=
                api_version.APIVersionRequest('2.36')):
            search_opts_expected['display_name~'] = 'fake_name'
        else:
            search_opts_expected['display_name'] = search_opts['name']
        if use_admin_context:
            search_opts_expected.update({'fake_key': 'fake_value'})
        share_api.API.get_all_snapshots.assert_called_once_with(
            req.environ['manila.context'],
            limit=int(search_opts['limit']),
            offset=int(search_opts['offset']),
            sort_key=search_opts['sort_key'],
            sort_dir=search_opts['sort_dir'],
            search_opts=search_opts_expected,
        )
        self.assertEqual(1, len(result['snapshots']))
        self.assertEqual(snapshots[0]['id'], result['snapshots'][0]['id'])
        self.assertEqual(snapshots[0]['display_name'],
                         result['snapshots'][0]['name'])