From: Deepti Ramakrishna Date: Wed, 11 Nov 2015 07:19:43 +0000 (-0800) Subject: Add test for snapshot filtering by project id X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=cc86e575e1764b7a9cbbd8bc19cd29ead3227b47;p=openstack-build%2Fcinder-build.git Add test for snapshot filtering by project id Cinder API already supports listing snapshots by project id. But a test case is missing to validate this feature. Hence added that in this patch. https://review.openstack.org/#/c/242391/ --> adds this support on the python-cinderclient side. Change-Id: I70606abf2fe5eca43cd0a3d15f7b9e12bb979b3b Co-Authored-By: wuyuting --- diff --git a/cinder/tests/unit/api/v2/test_snapshots.py b/cinder/tests/unit/api/v2/test_snapshots.py index e37a3dccc..e29d03752 100644 --- a/cinder/tests/unit/api/v2/test_snapshots.py +++ b/cinder/tests/unit/api/v2/test_snapshots.py @@ -519,6 +519,26 @@ class SnapshotApiTest(test.TestCase): self.assertIn('snapshots', res) self.assertEqual(3, len(res['snapshots'])) + @mock.patch.object(db, 'snapshot_get_all') + @mock.patch('cinder.db.snapshot_metadata_get', return_value=dict()) + def test_admin_list_snapshots_by_tenant_id(self, snapshot_metadata_get, + snapshot_get_all): + def get_all(context, filters=None, marker=None, limit=None, + sort_keys=None, sort_dirs=None, offset=None): + if 'project_id' in filters and 'tenant1' in filters['project_id']: + return [stubs.stub_snapshot(1, tenant_id='tenant1')] + else: + return [] + + snapshot_get_all.side_effect = get_all + + req = fakes.HTTPRequest.blank('/v2/fake/snapshots?all_tenants=1' + '&project_id=tenant1', + use_admin_context=True) + res = self.controller.index(req) + self.assertIn('snapshots', res) + self.assertEqual(1, len(res['snapshots'])) + @mock.patch('cinder.db.snapshot_metadata_get', return_value=dict()) def test_all_tenants_non_admin_gets_all_tenants(self, snapshot_metadata_get):