From: Liang Ke Date: Fri, 23 Mar 2018 02:28:55 +0000 (+0000) Subject: Merge "Ingore swp file in git" X-Git-Tag: v1.1.2~55 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=multicloud%2Fframework.git;a=commitdiff_plain;h=7850f681fb63a7dca983accd42433926334fd287;hp=92afa9c5b18de12d2ba3b7420c109b09445a163f Merge "Ingore swp file in git" --- diff --git a/multivimbroker/multivimbroker/forwarder/views.py b/multivimbroker/multivimbroker/forwarder/views.py index c77fe94..83d3172 100644 --- a/multivimbroker/multivimbroker/forwarder/views.py +++ b/multivimbroker/multivimbroker/forwarder/views.py @@ -104,7 +104,7 @@ class CheckCapacity(BaseServer): def post(self, request): try: body = json.loads(request.body) - except json.JSONDecodeError as e: + except ValueError as e: return Response( data={'error': 'Invalidate request body %s.' % e}, status=status.HTTP_400_BAD_REQUEST) @@ -123,7 +123,7 @@ class CheckCapacity(BaseServer): continue try: resp_body = json.loads(resp.body) - except json.JSONDecodeError: + except ValueError: continue if not resp_body.get("result", False): continue diff --git a/multivimbroker/multivimbroker/tests/test_check_capacity.py b/multivimbroker/multivimbroker/tests/test_check_capacity.py index 0a852e8..60035e0 100644 --- a/multivimbroker/multivimbroker/tests/test_check_capacity.py +++ b/multivimbroker/multivimbroker/tests/test_check_capacity.py @@ -52,3 +52,42 @@ class CheckCapacityTest(unittest.TestCase): } self.assertEqual(status.HTTP_200_OK, resp.status_code) self.assertDictEqual(expect_body, resp.data) + + def test_check_capacity_no_suitable_vim(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": false + }""" + plugin_resp.status_code = status.HTTP_200_OK + send.return_value = plugin_resp + + resp = self.view.post(req) + expect_body = { + "VIMs": [] + } + self.assertEqual(status.HTTP_200_OK, resp.status_code) + self.assertDictEqual(expect_body, resp.data) + + def test_check_capacity_invalid_input(self): + req = mock.Mock() + req.body = "hello world" + req.get_full_path.return_value = ("http://msb.onap.org/api/multicloud" + "/v0/check_vim_capacity") + expect_body = { + "error": ("Invalidate request body " + "No JSON object could be decoded.") + } + resp = self.view.post(req) + self.assertEqual(status.HTTP_400_BAD_REQUEST, resp.status_code) + self.assertDictEqual(expect_body, resp.data) diff --git a/multivimbroker/multivimbroker/tests/test_restcall.py b/multivimbroker/multivimbroker/tests/test_restcall.py new file mode 100644 index 0000000..b76b0a6 --- /dev/null +++ b/multivimbroker/multivimbroker/tests/test_restcall.py @@ -0,0 +1,24 @@ +# 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 unittest + +from multivimbroker.pub.utils import restcall + + +class TestRestCall(unittest.TestCase): + + def test_combine_url(self): + url = ["http://a.com/test/", "http://a.com/test/", + "http://a.com/test"] + res = ["/resource", "resource", "/resource"] + expected = "http://a.com/test/resource" + for i in range(len(url)): + self.assertEqual(expected, restcall.combine_url(url[i], res[i]))