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 req.META.items.return_value = [("Project", "projectname1")]
42 with mock.patch.object(self.view, "send") as send:
43 plugin_resp = mock.Mock()
44 plugin_resp.content = """{
47 plugin_resp.status_code = str(status.HTTP_200_OK)
48 send.return_value = plugin_resp
50 resp = self.view.post(req)
52 "VIMs": ["openstack_RegionOne"]
54 self.assertEqual(status.HTTP_200_OK, resp.status_code)
55 self.assertDictEqual(expect_body, resp.data)
57 def test_check_capacity_no_suitable_vim(self):
64 "VIMs": ["openstack_RegionOne"]
66 req.get_full_path.return_value = ("http://msb.onap.org/api/multicloud"
67 "/v0/check_vim_capacity")
68 req.META.items.return_value = [("Project", "projectname1")]
70 with mock.patch.object(self.view, "send") as send:
71 plugin_resp = mock.Mock()
72 plugin_resp.content = """{
75 plugin_resp.status_code = str(status.HTTP_200_OK)
76 send.return_value = plugin_resp
78 resp = self.view.post(req)
82 self.assertEqual(status.HTTP_200_OK, resp.status_code)
83 self.assertDictEqual(expect_body, resp.data)
85 def test_check_capacity_invalid_input(self):
87 req.body = "hello world"
88 req.get_full_path.return_value = ("http://msb.onap.org/api/multicloud"
89 "/v0/check_vim_capacity")
90 req.META.items.return_value = [("Project", "projectname1")]
92 # "error": ("Invalidate request body "
93 # "No JSON object could be decoded.")
95 resp = self.view.post(req)
96 self.assertEqual(status.HTTP_400_BAD_REQUEST, resp.status_code)
97 # self.assertDictEqual(expect_body, resp.data)