6cf4e3f72957ece645c7d67c8dd944ff700c3133
[osm/MON.git] / osm_mon / test / OpenStack / unit / test_responses.py
1 # Copyright 2017 iIntel 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 """Test that the correct responses are generated for each message."""
23
24 import logging
25
26 import unittest
27
28 import mock
29
30 from osm_mon.plugins.OpenStack import response as resp
31
32 log = logging.getLogger(__name__)
33
34
35 class TestOpenStackResponse(unittest.TestCase):
36 """Tests for responses generated by the OpenStack plugins."""
37
38 def setUp(self):
39 """Setup for testing OpenStack plugin responses."""
40 super(TestOpenStackResponse, self).setUp()
41 self.plugin_resp = resp.OpenStack_Response()
42
43 def test_invalid_key(self):
44 """Test if an invalid key is entered for a response."""
45 message = self.plugin_resp.generate_response("mock_invalid_key")
46 self.assertEqual(message, None)
47
48 @mock.patch.object(
49 resp.OpenStack_Response, "alarm_list_response")
50 def test_list_alarm_resp(self, alarm_list_resp):
51 """Test out a function call for a list alarm response."""
52 message = self.plugin_resp.generate_response("list_alarm_response")
53 self.assertEqual(alarm_list_resp.return_value, message)
54
55 @mock.patch.object(
56 resp.OpenStack_Response, "list_metric_response")
57 def test_list_metric_resp(self, metric_list_resp):
58 """Test list metric response function call."""
59 message = self.plugin_resp.generate_response("list_metric_response")
60 self.assertEqual(message, metric_list_resp.return_value)
61
62 @mock.patch.object(
63 resp.OpenStack_Response, "delete_alarm_response")
64 def test_delete_alarm_resp(self, del_alarm_resp):
65 """Test delete alarm response function call."""
66 message = self.plugin_resp.generate_response("delete_alarm_response")
67 self.assertEqual(message, del_alarm_resp.return_value)
68
69 @mock.patch.object(
70 resp.OpenStack_Response, "delete_metric_response")
71 def test_delete_metric_resp(self, del_metric_resp):
72 """Test the response functionality of delete metric response."""
73 message = self.plugin_resp.generate_response("delete_metric_response")
74 self.assertEqual(message, del_metric_resp.return_value)
75
76 @mock.patch.object(
77 resp.OpenStack_Response, "create_alarm_response")
78 def test_create_alarm_resp(self, config_alarm_resp):
79 """Test create alarm response function call."""
80 message = self.plugin_resp.generate_response("create_alarm_response")
81 self.assertEqual(message, config_alarm_resp.return_value)
82
83 @mock.patch.object(
84 resp.OpenStack_Response, "metric_create_response")
85 def test_create_metric_resp(self, config_metric_resp):
86 """Test create metric response function call."""
87 message = self.plugin_resp.generate_response("create_metric_response")
88 self.assertEqual(message, config_metric_resp.return_value)
89
90 @mock.patch.object(
91 resp.OpenStack_Response, "update_alarm_response")
92 def test_update_alarm_resp(self, up_alarm_resp):
93 """Test update alarm response function call."""
94 message = self.plugin_resp.generate_response("update_alarm_response")
95 self.assertEqual(message, up_alarm_resp.return_value)
96
97 @mock.patch.object(
98 resp.OpenStack_Response, "update_metric_response")
99 def test_update_metric_resp(self, up_metric_resp):
100 """Test update metric response function call."""
101 message = self.plugin_resp.generate_response("update_metric_response")
102 self.assertEqual(message, up_metric_resp.return_value)
103
104 @mock.patch.object(
105 resp.OpenStack_Response, "notify_alarm")
106 def test_notify_alarm(self, notify_alarm):
107 """Test notify alarm response function call."""
108 message = self.plugin_resp.generate_response("notify_alarm")
109 self.assertEqual(message, notify_alarm.return_value)
110
111 @mock.patch.object(
112 resp.OpenStack_Response, "read_metric_data_response")
113 def test_read_metric_data_resp(self, read_data_resp):
114 """Test read metric data response function call."""
115 message = self.plugin_resp.generate_response(
116 "read_metric_data_response")
117 self.assertEqual(message, read_data_resp.return_value)