29e95581d70430da0ab67ce0e7ad0f6bdbb97249
1 # Copyright 2017 Intel Research and Development Ireland Limited
2 # *************************************************************
4 # This file is part of OSM Monitoring module
5 # All Rights Reserved to Intel Corporation
7 # Licensed under the Apache License, Version 2.0 (the "License"); you may
8 # not use this file except in compliance with the License. You may obtain
9 # a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16 # License for the specific language governing permissions and limitations
19 # For those usages not covered by the Apache License, Version 2.0 please
20 # contact: helena.mcgough@intel.com or adrian.hoban@intel.com
22 """Tests for all common OpenStack methods."""
28 from plugins
.OpenStack
.common
import Common
33 class TestCommon(unittest
.TestCase
):
34 """Test the common class for OpenStack plugins."""
38 super(TestCommon
, self
).setUp()
39 self
.common
= Common()
41 @mock.patch
.object(requests
, 'post')
42 def test_post_req(self
, post
):
43 """Testing a post request."""
44 self
.common
._perform
_request
("url", "auth_token", req_type
="post",
47 post
.assert_called_with("url", data
="payload", headers
=mock
.ANY
,
50 @mock.patch
.object(requests
, 'get')
51 def test_get_req(self
, get
):
52 """Testing a get request."""
53 # Run the defualt get request without any parameters
54 self
.common
._perform
_request
("url", "auth_token", req_type
="get")
56 get
.assert_called_with("url", params
=None, headers
=mock
.ANY
,
59 # Test with some parameters specified
61 self
.common
._perform
_request
("url", "auth_token", req_type
="get",
62 params
="some parameters")
64 get
.assert_called_with("url", params
="some parameters",
65 headers
=mock
.ANY
, timeout
=mock
.ANY
)
67 @mock.patch
.object(requests
, 'put')
68 def test_put_req(self
, put
):
69 """Testing a put request."""
70 self
.common
._perform
_request
("url", "auth_token", req_type
="put",
72 put
.assert_called_with("url", data
="payload", headers
=mock
.ANY
,
75 @mock.patch
.object(requests
, 'delete')
76 def test_delete_req(self
, delete
):
77 """Testing a delete request."""
78 self
.common
._perform
_request
("url", "auth_token", req_type
="delete")
80 delete
.assert_called_with("url", headers
=mock
.ANY
, timeout
=mock
.ANY
)