diff options
author | Ethan Lynn <ethanlynnl@vmware.com> | 2018-09-19 07:19:47 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-09-19 07:19:47 +0000 |
commit | 126a7fd121fce7872303ae353a7cbc1531ef573a (patch) | |
tree | 191a0dd6c58c71ea9e2e5c1deee6b694b9f7a131 /vio | |
parent | 84a1147ce313c6105f3d5154614ca9e75662bad0 (diff) | |
parent | 0d794019fbdb3049dccb3cc71652735edfdb3fad (diff) |
Merge "Add UT for infra_workload"
Diffstat (limited to 'vio')
-rw-r--r-- | vio/vio/swagger/views/workload/views.py | 9 | ||||
-rw-r--r-- | vio/vio/tests/test_infraworkload_view.py | 74 |
2 files changed, 78 insertions, 5 deletions
diff --git a/vio/vio/swagger/views/workload/views.py b/vio/vio/swagger/views/workload/views.py index 84b4057..17b5223 100644 --- a/vio/vio/swagger/views/workload/views.py +++ b/vio/vio/swagger/views/workload/views.py @@ -37,12 +37,11 @@ def handle_directives(body): for attr in dd["attributes"]: params[attr[ "attribute_name"]] = attr["attribute_value"] + for k, v in params.items(): + if k in stack_params_keys: + stack_params[k] = v except KeyError as ex: logger.debug("Error handle directives: %s" % str(ex)) - return {} - for k, v in params.items(): - if k in stack_params_keys: - stack_params[k] = v return body @@ -117,7 +116,7 @@ class GetDelStackViewV1(APIView): try: stack_op = OperateStack.OperateStack(vim_info) stack_op.delete_vim_stack(workload_id) - return Response(status=status.HTTP_202_ACCEPTED) + return Response(status=status.HTTP_204_NO_CONTENT) except Exception as e: if hasattr(e, "http_status"): return Response(data={'error': str(e)}, status=e.http_status) diff --git a/vio/vio/tests/test_infraworkload_view.py b/vio/vio/tests/test_infraworkload_view.py new file mode 100644 index 0000000..74d6951 --- /dev/null +++ b/vio/vio/tests/test_infraworkload_view.py @@ -0,0 +1,74 @@ +# 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 +import json + +from vio.pub.msapi import extsys +from vio.swagger.views.workload import views +from vio.pub.vim.vimapi.heat import OperateStack + + +class TestGetDeleteStackView(unittest.TestCase): + + def setUp(self): + self.view = views.GetDelStackViewV1() + + @mock.patch.object(OperateStack.OperateStack, "get_vim_stack") + @mock.patch.object(extsys, "get_vim_by_id") + def test_get(self, mock_getvim, mock_getstk): + mock_getvim.return_value = {} + stk = mock.Mock(id="stack-id", status="CREATE_COMPLETE") + # stk.to_dict.return_value = { + # "id": "stack-id" + # } + mock_getstk.return_value = stk + resp = self.view.get(mock.Mock(), "vmware", "nova", "stack1") + self.assertEqual(200, resp.status_code) + self.assertEqual("stack-id", resp.data.get('workload_id')) + self.assertEqual("CREATE_COMPLETE", resp.data.get('workload_status')) + + @mock.patch.object(OperateStack.OperateStack, "delete_vim_stack") + @mock.patch.object(extsys, "get_vim_by_id") + def test_delete(self, mock_getvim, mock_delstk): + mock_getvim.return_value = {} + resp = self.view.delete( + mock.Mock(), "vmware", "nova", "stack1") + self.assertEqual(204, resp.status_code) + mock_delstk.assert_called_once() + + +class TestCreateStackView(unittest.TestCase): + + def setUp(self): + self.view = views.CreateStackViewV1() + + @mock.patch.object(OperateStack.OperateStack, "create_vim_stack") + @mock.patch.object(extsys, "get_vim_by_id") + def test_post(self, mock_getvim, mock_createstk): + mock_getvim.return_value = { + "tenant": "tenant-id" + } + stk = mock.Mock() + stk.id = "stack-id" + mock_createstk.return_value = stk + req = mock.Mock() + req.body = json.dumps({ + "template_type": "heat", + "template_data": { + "parameters": {} + } + }) + resp = self.view.post(req, "vmware", "nova") + self.assertEqual(201, resp.status_code) + self.assertEqual("stack-id", resp.data["workload_id"]) |