From 9a0d43b54519c8e08683e522255370ccba137902 Mon Sep 17 00:00:00 2001 From: Ethan Lynn Date: Sun, 4 Mar 2018 21:51:01 +0000 Subject: [PATCH] Add test_check_capacity_success Add test_check_capacity_success for check_vim_capacity API Change-Id: I8b0ffb3b907b25f06d8267c7ec941ce83d636d95 Issue-ID: MULTICLOUD-166 Signed-off-by: Ethan Lynn --- .../multivimbroker/tests/test_check_capacity.py | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 multivimbroker/multivimbroker/tests/test_check_capacity.py diff --git a/multivimbroker/multivimbroker/tests/test_check_capacity.py b/multivimbroker/multivimbroker/tests/test_check_capacity.py new file mode 100644 index 0000000..0a852e8 --- /dev/null +++ b/multivimbroker/multivimbroker/tests/test_check_capacity.py @@ -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) -- 2.16.6