1 # Copyright (c) 2017-2018 VMware, 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.
16 from rest_framework import status
18 from multivimbroker.forwarder.views import CheckCapacity
21 class CheckCapacityTest(unittest.TestCase):
24 self.view = CheckCapacity()
25 super(CheckCapacityTest, self).setUp()
30 def test_check_capacity_success(self):
37 "VIMs": ["openstack_RegionOne"]
39 req.get_full_path.return_value = ("http://msb.onap.org/api/multicloud"
40 "/v0/check_vim_capacity")
41 with mock.patch.object(self.view, "send") as send:
42 plugin_resp = mock.Mock()
43 plugin_resp.content = """{
46 plugin_resp.status_code = str(status.HTTP_200_OK)
47 send.return_value = plugin_resp
49 resp = self.view.post(req)
51 "VIMs": ["openstack_RegionOne"]
53 self.assertEqual(status.HTTP_200_OK, resp.status_code)
54 self.assertDictEqual(expect_body, resp.data)
56 def test_check_capacity_no_suitable_vim(self):
63 "VIMs": ["openstack_RegionOne"]
65 req.get_full_path.return_value = ("http://msb.onap.org/api/multicloud"
66 "/v0/check_vim_capacity")
67 with mock.patch.object(self.view, "send") as send:
68 plugin_resp = mock.Mock()
69 plugin_resp.content = """{
72 plugin_resp.status_code = str(status.HTTP_200_OK)
73 send.return_value = plugin_resp
75 resp = self.view.post(req)
79 self.assertEqual(status.HTTP_200_OK, resp.status_code)
80 self.assertDictEqual(expect_body, resp.data)
82 def test_check_capacity_invalid_input(self):
84 req.body = "hello world"
85 req.get_full_path.return_value = ("http://msb.onap.org/api/multicloud"
86 "/v0/check_vim_capacity")
88 "error": ("Invalidate request body "
89 "No JSON object could be decoded.")
91 resp = self.view.post(req)
92 self.assertEqual(status.HTTP_400_BAD_REQUEST, resp.status_code)
93 self.assertDictEqual(expect_body, resp.data)