1 # Copyright (c) 2017-2018 VMware, Inc.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
5 # http://www.apache.org/licenses/LICENSE-2.0
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS,
9 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 from multivimbroker.pub.utils import restcall
17 class TestRestCall(unittest.TestCase):
19 def test_combine_url(self):
20 url = ["http://a.com/test/", "http://a.com/test/",
22 res = ["/resource", "resource", "/resource"]
23 expected = "http://a.com/test/resource"
24 for i in range(len(url)):
25 self.assertEqual(expected, restcall.combine_url(url[i], res[i]))
27 @mock.patch.object(restcall, "call_req")
28 def test_get_res_from_aai(self, mock_call):
31 expect_url = "https://aai.api.simpledemo.openecomp.org:8443/aai/v13"
35 'X-FromAppId': 'MultiCloud',
36 'X-TransactionId': '9001',
37 'content-type': 'application/json',
38 'accept': 'application/json'
40 restcall.get_res_from_aai(res, content=content)
41 mock_call.assert_called_once_with(
42 expect_url, expect_user, expect_pass, restcall.rest_no_auth,
43 res, "GET", content, expect_headers)
45 @mock.patch.object(restcall, "call_req")
46 def test_req_by_msb(self, mock_call):
49 content = "no content"
51 restcall.req_by_msb(res, method, content=content, headers=headers)
52 expect_url = "http://127.0.0.1:10080/"
53 mock_call.assert_called_once_with(
54 expect_url, "", "", restcall.rest_no_auth, res, method,