Add test_check_capacity_success
[multicloud/framework.git] / multivimbroker / multivimbroker / tests / test_check_capacity.py
1 # Copyright (c) 2017-2018 VMware, Inc.
2 #
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:
6 #
7 #       http://www.apache.org/licenses/LICENSE-2.0
8 #
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
13 import mock
14 import unittest
15
16 from rest_framework import status
17
18 from multivimbroker.forwarder.views import CheckCapacity
19
20
21 class CheckCapacityTest(unittest.TestCase):
22
23     def setUp(self):
24         self.view = CheckCapacity()
25         super(CheckCapacityTest, self).setUp()
26
27     def tearDown(self):
28         pass
29
30     def test_check_capacity_success(self):
31         req = mock.Mock()
32         req.body = """
33         {
34             "vCPU": 1,
35             "Memory": 1,
36             "Storage": 500,
37             "VIMs": ["openstack_RegionOne"]
38         }"""
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.body = """{
44                 "result": true
45             }"""
46             plugin_resp.status_code = status.HTTP_200_OK
47             send.return_value = plugin_resp
48
49             resp = self.view.post(req)
50             expect_body = {
51                 "VIMs": ["openstack_RegionOne"]
52             }
53             self.assertEqual(status.HTTP_200_OK, resp.status_code)
54             self.assertDictEqual(expect_body, resp.data)