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."""
29 from osm_mon
.plugins
.OpenStack
import response
as resp
31 log
= logging
.getLogger(__name__
)
34 class TestOpenStackResponse(unittest
.TestCase
):
35 """Tests for responses generated by the OpenStack plugins."""
38 """Setup for testing OpenStack plugin responses."""
39 super(TestOpenStackResponse
, self
).setUp()
40 self
.plugin_resp
= resp
.OpenStackResponseBuilder()
42 def test_invalid_key(self
):
43 """Test if an invalid key is entered for a response."""
44 message
= self
.plugin_resp
.generate_response("mock_invalid_key")
45 self
.assertEqual(message
, None)
48 resp
.OpenStackResponseBuilder
, "alarm_list_response")
49 def test_list_alarm_resp(self
, alarm_list_resp
):
50 """Test out a function call for a list alarm response."""
51 message
= self
.plugin_resp
.generate_response("list_alarm_response")
52 self
.assertEqual(alarm_list_resp
.return_value
, message
)
55 resp
.OpenStackResponseBuilder
, "list_metric_response")
56 def test_list_metric_resp(self
, metric_list_resp
):
57 """Test list metric response function call."""
58 message
= self
.plugin_resp
.generate_response("list_metric_response")
59 self
.assertEqual(message
, metric_list_resp
.return_value
)
62 resp
.OpenStackResponseBuilder
, "delete_alarm_response")
63 def test_delete_alarm_resp(self
, del_alarm_resp
):
64 """Test delete alarm response function call."""
65 message
= self
.plugin_resp
.generate_response("delete_alarm_response")
66 self
.assertEqual(message
, del_alarm_resp
.return_value
)
69 resp
.OpenStackResponseBuilder
, "delete_metric_response")
70 def test_delete_metric_resp(self
, del_metric_resp
):
71 """Test the response functionality of delete metric response."""
72 message
= self
.plugin_resp
.generate_response("delete_metric_response")
73 self
.assertEqual(message
, del_metric_resp
.return_value
)
76 resp
.OpenStackResponseBuilder
, "create_alarm_response")
77 def test_create_alarm_resp(self
, config_alarm_resp
):
78 """Test create alarm response function call."""
79 message
= self
.plugin_resp
.generate_response("create_alarm_response")
80 self
.assertEqual(message
, config_alarm_resp
.return_value
)
83 resp
.OpenStackResponseBuilder
, "metric_create_response")
84 def test_create_metric_resp(self
, config_metric_resp
):
85 """Test create metric response function call."""
86 message
= self
.plugin_resp
.generate_response("create_metric_response")
87 self
.assertEqual(message
, config_metric_resp
.return_value
)
90 resp
.OpenStackResponseBuilder
, "update_alarm_response")
91 def test_update_alarm_resp(self
, up_alarm_resp
):
92 """Test update alarm response function call."""
93 message
= self
.plugin_resp
.generate_response("update_alarm_response")
94 self
.assertEqual(message
, up_alarm_resp
.return_value
)
97 resp
.OpenStackResponseBuilder
, "update_metric_response")
98 def test_update_metric_resp(self
, up_metric_resp
):
99 """Test update metric response function call."""
100 message
= self
.plugin_resp
.generate_response("update_metric_response")
101 self
.assertEqual(message
, up_metric_resp
.return_value
)
104 resp
.OpenStackResponseBuilder
, "notify_alarm")
105 def test_notify_alarm(self
, notify_alarm
):
106 """Test notify alarm response function call."""
107 message
= self
.plugin_resp
.generate_response("notify_alarm")
108 self
.assertEqual(message
, notify_alarm
.return_value
)
111 resp
.OpenStackResponseBuilder
, "read_metric_data_response")
112 def test_read_metric_data_resp(self
, read_data_resp
):
113 """Test read metric data response function call."""
114 message
= self
.plugin_resp
.generate_response(
115 "read_metric_data_response")
116 self
.assertEqual(message
, read_data_resp
.return_value
)