1 # Copyright 2017 iIntel 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 """Test that the correct responses are generated for each message."""
30 from osm_mon
.plugins
.OpenStack
import response
as resp
32 log
= logging
.getLogger(__name__
)
35 class TestOpenStackResponse(unittest
.TestCase
):
36 """Tests for responses generated by the OpenStack plugins."""
39 """Setup for testing OpenStack plugin responses."""
40 super(TestOpenStackResponse
, self
).setUp()
41 self
.plugin_resp
= resp
.OpenStack_Response()
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)
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
)
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
)
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
)
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
)
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
)
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
)
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
)
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
)
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
)
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
)