'Tests that the default filters from volume.api.API.get_all are set.
1. \'no_migration_status\'=True for non-admins and get_all_by_project is
invoked.
2. \'no_migration_status\' is not included for admins.
3. When \'all_tenants\' is not specified, then it is removed and
get_all_by_project is invoked for admins.
3. When \'all_tenants\' is specified, then it is removed and get_all
is invoked for admins.'

def test_volume_list_default_filters(self):

    def fake_volume_get_all_by_project(context, project_id, marker, limit, sort_keys=None, sort_dirs=None, filters=None, viewable_admin_meta=False, offset=0):
        self.assertTrue(filters['no_migration_targets'])
        self.assertNotIn('all_tenants', filters)
        return [v2_fakes.create_fake_volume(fake.VOLUME_ID, display_name='vol1')]
    def fake_volume_get_all(context, marker, limit, sort_keys=None, sort_dirs=None, filters=None, viewable_admin_meta=False, offset=0):
        return []
    self.mock_object(db, 'volume_get_all_by_project', fake_volume_get_all_by_project)
    self.mock_object(db, 'volume_get_all', fake_volume_get_all)
    for params in ['', '?all_tenants=1']:
        req = fakes.HTTPRequest.blank(('/v2/volumes%s' % params))
        resp = self.controller.index(req)
        self.assertEqual(1, len(resp['volumes']))
        self.assertEqual('vol1', resp['volumes'][0]['name'])
    def fake_volume_get_all_by_project2(context, project_id, marker, limit, sort_keys=None, sort_dirs=None, filters=None, viewable_admin_meta=False, offset=0):
        self.assertNotIn('no_migration_targets', filters)
        return [v2_fakes.create_fake_volume(fake.VOLUME_ID, display_name='vol2')]
    def fake_volume_get_all2(context, marker, limit, sort_keys=None, sort_dirs=None, filters=None, viewable_admin_meta=False, offset=0):
        return []
    self.mock_object(db, 'volume_get_all_by_project', fake_volume_get_all_by_project2)
    self.mock_object(db, 'volume_get_all', fake_volume_get_all2)
    req = fakes.HTTPRequest.blank('/v2/volumes', use_admin_context=True)
    resp = self.controller.index(req)
    self.assertEqual(1, len(resp['volumes']))
    self.assertEqual('vol2', resp['volumes'][0]['name'])
    def fake_volume_get_all_by_project3(context, project_id, marker, limit, sort_keys=None, sort_dirs=None, filters=None, viewable_admin_meta=False, offset=0):
        return []
    def fake_volume_get_all3(context, marker, limit, sort_keys=None, sort_dirs=None, filters=None, viewable_admin_meta=False, offset=0):
        self.assertNotIn('no_migration_targets', filters)
        self.assertNotIn('all_tenants', filters)
        return [v2_fakes.create_fake_volume(fake.VOLUME3_ID, display_name='vol3')]
    self.mock_object(db, 'volume_get_all_by_project', fake_volume_get_all_by_project3)
    self.mock_object(db, 'volume_get_all', fake_volume_get_all3)
    req = fakes.HTTPRequest.blank('/v2/volumes?all_tenants=1', use_admin_context=True)
    resp = self.controller.index(req)
    self.assertEqual(1, len(resp['volumes']))
    self.assertEqual('vol3', resp['volumes'][0]['name'])
