summaryrefslogtreecommitdiffstats
path: root/vio
diff options
context:
space:
mode:
authorEthan Lynn <ethanlynnl@vmware.com>2018-04-11 10:36:59 +0800
committerEthan Lynn <ethanlynnl@vmware.com>2018-04-11 10:46:01 +0800
commita95d7a201805edb593f35949bca2b50b976e3793 (patch)
treea8444d17adc556a15f46759e50011405474e494c /vio
parentbed78300674d7fc91eeca73fac25ee7ab056346b (diff)
Add test_post_from_image for CreateListVolumeView
Add test_post_from_image Change-Id: Ib16b35ee8f24d8913bb834168a4b1a12879223a6 Issue-ID: MULTICLOUD-199 Signed-off-by: Ethan Lynn <ethanlynnl@vmware.com>
Diffstat (limited to 'vio')
-rw-r--r--vio/vio/tests/test_volume_view.py39
1 files changed, 34 insertions, 5 deletions
diff --git a/vio/vio/tests/test_volume_view.py b/vio/vio/tests/test_volume_view.py
index 115cb99..88c8f59 100644
--- a/vio/vio/tests/test_volume_view.py
+++ b/vio/vio/tests/test_volume_view.py
@@ -16,6 +16,7 @@ import unittest
from vio.pub.msapi import extsys
from vio.swagger.views.volume import views
from vio.pub.vim.vimapi.cinder import OperateVolume
+from vio.pub.vim.vimapi.glance import OperateImage
class TestGetDeleteVolumeView(unittest.TestCase):
@@ -141,9 +142,37 @@ class TestCreateListVolumeView(unittest.TestCase):
mock_getvol.return_value = vol
mock_getvols.return_value = [vol]
req = mock.Mock()
- req.body = {
- "vol-name"
- }
- ret = self.view.get(
- mock.Mock(query_params=[]), "vmware_nova", "tenant1")
+ req.body = """{
+ "name": "vol-name"
+ }"""
+ ret = self.view.post(req, "vmware_nova", "tenant1")
self.assertEqual(200, ret.status_code)
+
+ @mock.patch.object(OperateImage.OperateImage, "find_vim_image")
+ @mock.patch.object(OperateVolume.OperateVolume, "create_vim_volume")
+ @mock.patch.object(OperateVolume.OperateVolume, "get_vim_volumes")
+ @mock.patch.object(extsys, "get_vim_by_id")
+ def test_post_from_image(self, mock_getvim, mock_getvols,
+ mock_createvol, mock_findimg):
+ mock_getvim.return_value = {
+ "tenant": "tenant-id"
+ }
+ mock_findimg.return_value = mock.Mock(id="image-id")
+ vol = mock.Mock()
+ vol.attachments = []
+ vol.id = "vol-id"
+ vol.name = "vol-name"
+ vol.created_at = "create time"
+ vol.status = "ok"
+ vol.volume_type = "vmdk"
+ vol.size = 1
+ vol.availability_zone = "nova"
+ mock_createvol.return_value = vol
+ mock_getvols.return_value = []
+ req = mock.Mock()
+ req.body = """{
+ "name": "vol-name",
+ "imageId": "image-id"
+ }"""
+ ret = self.view.post(req, "vmware_nova", "tenant1")
+ self.assertEqual(202, ret.status_code)