blob: 29e95581d70430da0ab67ce0e7ad0f6bdbb97249 [file] [log] [blame]
Helena McGough95b92b32017-10-01 12:03:53 +01001# Copyright 2017 Intel Research and Development Ireland Limited
2# *************************************************************
3
4# This file is part of OSM Monitoring module
5# All Rights Reserved to Intel Corporation
6
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
10
11# http://www.apache.org/licenses/LICENSE-2.0
12
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
17# under the License.
18
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
21##
22"""Tests for all common OpenStack methods."""
23
24import unittest
25
26import mock
27
28from plugins.OpenStack.common import Common
29
30import requests
31
32
33class TestCommon(unittest.TestCase):
34 """Test the common class for OpenStack plugins."""
35
36 def setUp(self):
37 """Test Setup."""
38 super(TestCommon, self).setUp()
39 self.common = Common()
40
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",
45 payload="payload")
46
47 post.assert_called_with("url", data="payload", headers=mock.ANY,
48 timeout=mock.ANY)
49
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")
55
56 get.assert_called_with("url", params=None, headers=mock.ANY,
57 timeout=mock.ANY)
58
59 # Test with some parameters specified
60 get.reset_mock()
61 self.common._perform_request("url", "auth_token", req_type="get",
62 params="some parameters")
63
64 get.assert_called_with("url", params="some parameters",
65 headers=mock.ANY, timeout=mock.ANY)
66
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",
71 payload="payload")
72 put.assert_called_with("url", data="payload", headers=mock.ANY,
73 timeout=mock.ANY)
74
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")
79
80 delete.assert_called_with("url", headers=mock.ANY, timeout=mock.ANY)