--- /dev/null
+# Copyright 2015 SimpliVity Corp.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+import mock
+
+from cinder import objects
+from cinder.tests import fake_volume
+from cinder.tests.objects import test_objects
+
+
+class TestVolume(test_objects._LocalTest):
+ @staticmethod
+ def _compare(test, db, obj):
+ for field, value in db.items():
+ test.assertEqual(db[field], obj[field])
+
+ @mock.patch('cinder.db.volume_get')
+ def test_get_by_id(self, volume_get):
+ db_volume = fake_volume.fake_db_volume()
+ volume_get.return_value = db_volume
+ volume = objects.Volume.get_by_id(self.context, 1)
+ self._compare(self, db_volume, volume)
+
+ @mock.patch('cinder.db.volume_create')
+ def test_create(self, volume_create):
+ db_volume = fake_volume.fake_db_volume()
+ volume_create.return_value = db_volume
+ volume = objects.Volume(context=self.context)
+ volume.create()
+ self.assertEqual(db_volume['id'], volume.id)
+
+ @mock.patch('cinder.db.volume_update')
+ def test_save(self, volume_update):
+ db_volume = fake_volume.fake_db_volume()
+ volume = objects.Volume._from_db_object(self.context,
+ objects.Volume(), db_volume)
+ volume.display_name = 'foobar'
+ volume.save()
+ volume_update.assert_called_once_with(self.context, volume.id,
+ {'display_name': 'foobar'})
+
+ @mock.patch('cinder.db.volume_destroy')
+ def test_destroy(self, volume_destroy):
+ db_volume = fake_volume.fake_db_volume()
+ volume = objects.Volume._from_db_object(self.context,
+ objects.Volume(), db_volume)
+ volume.destroy()
+ volume_destroy.assert_called_once_with(self.context, '1')
+
+
+class TestVolumeList(test_objects._LocalTest):
+ @mock.patch('cinder.db.volume_get_all')
+ def test_get_all(self, volume_get_all):
+ db_volume = fake_volume.fake_db_volume()
+ volume_get_all.return_value = [db_volume]
+
+ volumes = objects.VolumeList.get_all(self.context,
+ mock.sentinel.marker,
+ mock.sentinel.limit,
+ mock.sentinel.sort_key,
+ mock.sentinel.sort_dir)
+ self.assertEqual(1, len(volumes))
+ TestVolume._compare(self, db_volume, volumes[0])