Add test_check_capacity_success 55/33955/3
authorEthan Lynn <ethanlynnl@vmware.com>
Sun, 4 Mar 2018 21:51:01 +0000 (21:51 +0000)
committerEthan Lynn <ethanlynnl@vmware.com>
Mon, 19 Mar 2018 07:42:19 +0000 (15:42 +0800)
Add test_check_capacity_success for check_vim_capacity API

Change-Id: I8b0ffb3b907b25f06d8267c7ec941ce83d636d95
Issue-ID: MULTICLOUD-166
Signed-off-by: Ethan Lynn <ethanlynnl@vmware.com>
multivimbroker/multivimbroker/tests/test_check_capacity.py [new file with mode: 0644]

diff --git a/multivimbroker/multivimbroker/tests/test_check_capacity.py b/multivimbroker/multivimbroker/tests/test_check_capacity.py
new file mode 100644 (file)
index 0000000..0a852e8
--- /dev/null
@@ -0,0 +1,54 @@
+# Copyright (c) 2017-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
+
+from rest_framework import status
+
+from multivimbroker.forwarder.views import CheckCapacity
+
+
+class CheckCapacityTest(unittest.TestCase):
+
+    def setUp(self):
+        self.view = CheckCapacity()
+        super(CheckCapacityTest, self).setUp()
+
+    def tearDown(self):
+        pass
+
+    def test_check_capacity_success(self):
+        req = mock.Mock()
+        req.body = """
+        {
+            "vCPU": 1,
+            "Memory": 1,
+            "Storage": 500,
+            "VIMs": ["openstack_RegionOne"]
+        }"""
+        req.get_full_path.return_value = ("http://msb.onap.org/api/multicloud"
+                                          "/v0/check_vim_capacity")
+        with mock.patch.object(self.view, "send") as send:
+            plugin_resp = mock.Mock()
+            plugin_resp.body = """{
+                "result": true
+            }"""
+            plugin_resp.status_code = status.HTTP_200_OK
+            send.return_value = plugin_resp
+
+            resp = self.view.post(req)
+            expect_body = {
+                "VIMs": ["openstack_RegionOne"]
+            }
+            self.assertEqual(status.HTTP_200_OK, resp.status_code)
+            self.assertDictEqual(expect_body, resp.data)