]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Add test for snapshot filtering by project id
authorDeepti Ramakrishna <deepti.ramakrishna@intel.com>
Wed, 11 Nov 2015 07:19:43 +0000 (23:19 -0800)
committerDeepti Ramakrishna <deepti.ramakrishna@intel.com>
Wed, 11 Nov 2015 07:20:11 +0000 (23:20 -0800)
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 <wytdahu@gmail.com>
cinder/tests/unit/api/v2/test_snapshots.py

index e37a3dccc81d8805c7f6bca80af7cf7247030ff5..e29d0375237004d65ce265efeae2f437489505a0 100644 (file)
@@ -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):