diff options
author | Liang Ke <lokyse@163.com> | 2018-03-29 08:57:24 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-03-29 08:57:24 +0000 |
commit | 2a770fe320f5c4386664310fa040ae75e202b9cb (patch) | |
tree | 0161e63ff278253469c978b72d6346ad5531855d | |
parent | e8ac214f8c8a6be2b803eab55e710265fb0a9d9e (diff) | |
parent | c5efd2e3e99d11c6fa80a9f05ac94091a56b11ba (diff) |
Merge changes from topic 'test-3'
* changes:
Add test_get for ListImageView
Add test_delete for ImageView
Add test_get for ImageView
-rw-r--r-- | vio/vio/tests/test_image_view.py | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/vio/vio/tests/test_image_view.py b/vio/vio/tests/test_image_view.py new file mode 100644 index 0000000..968826f --- /dev/null +++ b/vio/vio/tests/test_image_view.py @@ -0,0 +1,71 @@ +# Copyright (c) 2018 VMware, Inc. +# +# 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. + +import mock +import unittest + +from vio.pub.msapi import extsys +from vio.swagger.views.image import views +from vio.pub.vim.vimapi.glance import OperateImage + + +class TestGetDeleteImageView(unittest.TestCase): + + def setUp(self): + self.view = views.GetDeleteImageView() + + @mock.patch.object(OperateImage.OperateImage, "get_vim_image") + @mock.patch.object(extsys, "get_vim_by_id") + def test_get(self, mock_getvim, mock_getimg): + mock_getvim.return_value = { + "tenant": "tenant-id" + } + img = mock.Mock() + img.to_dict.return_value = { + "id": "image-id" + } + mock_getimg.return_value = img + resp = self.view.get(mock.Mock(), "vmware_nova", "tenant1", "image1") + self.assertEqual(200, resp.status_code) + self.assertEqual("image-id", resp.data.get('id')) + + @mock.patch.object(OperateImage.OperateImage, "delete_vim_image") + @mock.patch.object(extsys, "get_vim_by_id") + def test_delete(self, mock_getvim, mock_delimg): + mock_getvim.return_value = { + "tenant": "tenant-id" + } + resp = self.view.delete( + mock.Mock(), "vmware_nova", "tenant1", "image1") + self.assertEqual(204, resp.status_code) + mock_delimg.assert_called_once() + + +class TestCreateListImagesView(unittest.TestCase): + + def setUp(self): + self.view = views.CreateListImagesView() + + @mock.patch.object(OperateImage.OperateImage, "get_vim_images") + @mock.patch.object(extsys, "get_vim_by_id") + def test_get(self, mock_getvim, mock_getimgs): + mock_getvim.return_value = { + "tenant": "tenant-id" + } + img = mock.Mock() + img.to_dict.return_value = { + "id": "image-id" + } + mock_getimgs.return_value = [img] + resp = self.view.get( + mock.Mock(query_params=[]), "vmware_nova", "tenant1") + self.assertEqual(200, resp.status_code) |