1 # Copyright (c) 2019 Wind River Systems, Inc.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
18 from rest_framework import status
20 from multivimbroker.forwarder.views import APIv1CheckCapacity
23 class V1CheckCapacityTest(unittest.TestCase):
26 self.view = APIv1CheckCapacity()
27 super(V1CheckCapacityTest, self).setUp()
32 def test_check_capacity_success(self):
39 "VIMs": [{"cloud-owner": "openstack",
40 "cloud-region-id": "RegionOne"}]
42 req.get_full_path.return_value = ("http://msb.onap.org/api/multicloud"
43 "/v1/check_vim_capacity")
44 req.META.items.return_value = [("Project", "projectname1")]
45 with mock.patch.object(self.view, "send") as send:
46 plugin_resp = mock.Mock()
47 plugin_resp.content = """{
50 plugin_resp.status_code = str(status.HTTP_200_OK)
51 send.return_value = plugin_resp
53 resp = self.view.post(req)
55 "VIMs": [{"cloud-owner": "openstack",
56 "cloud-region-id": "RegionOne",
59 self.assertEqual(status.HTTP_200_OK, resp.status_code)
60 self.assertDictEqual(expect_body, resp.data)
62 def test_check_capacity_no_suitable_vim(self):
69 "VIMs": [{"cloud-owner": "openstack",
70 "cloud-region-id": "RegionOne"}]
72 req.get_full_path.return_value = ("http://msb.onap.org/api/multicloud"
73 "/v1/check_vim_capacity")
74 req.META.items.return_value = [("Project", "projectname1")]
76 with mock.patch.object(self.view, "send") as send:
77 plugin_resp = mock.Mock()
78 plugin_resp.content = """{
81 plugin_resp.status_code = str(status.HTTP_200_OK)
82 send.return_value = plugin_resp
84 resp = self.view.post(req)
88 self.assertEqual(status.HTTP_200_OK, resp.status_code)
89 self.assertDictEqual(expect_body, resp.data)
91 def test_check_capacity_invalid_input(self):
93 req.body = "hello world"
94 req.get_full_path.return_value = ("http://msb.onap.org/api/multicloud"
95 "/v1/check_vim_capacity")
96 req.META.items.return_value = [("Project", "projectname1")]
98 # "error": ("Invalidate request body "
99 # "No JSON object could be decoded.")
101 resp = self.view.post(req)
102 self.assertEqual(status.HTTP_400_BAD_REQUEST, resp.status_code)
103 # self.assertDictEqual(expect_body, resp.data)