900d8fe1b95fa017eba6f756c311bd0bce1c9653
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 plugins
.OpenStack
import response
as resp
32 __author__
= "Helena McGough"
34 log
= logging
.getLogger(__name__
)
37 class TestOpenStackResponse(unittest
.TestCase
):
38 """Tests for responses generated by the OpenStack plugins."""
41 """Setup for testing OpenStack plugin responses."""
42 super(TestOpenStackResponse
, self
).setUp()
43 self
.plugin_resp
= resp
.OpenStack_Response()
45 def test_invalid_key(self
):
46 """Test if an invalid key is entered for a response."""
47 message
= self
.plugin_resp
.generate_response("mock_invalid_key")
48 self
.assertEqual(message
, None)
51 resp
.OpenStack_Response
, "alarm_list_response")
52 def test_list_alarm_resp(self
, alarm_list_resp
):
53 """Test out a function call for a list alarm response."""
54 message
= self
.plugin_resp
.generate_response("list_alarm_response")
55 self
.assertEqual(alarm_list_resp
.return_value
, message
)
58 resp
.OpenStack_Response
, "list_metric_response")
59 def test_list_metric_resp(self
, metric_list_resp
):
60 """Test list metric response function call."""
61 message
= self
.plugin_resp
.generate_response("list_metric_response")
62 self
.assertEqual(message
, metric_list_resp
.return_value
)
65 resp
.OpenStack_Response
, "delete_alarm_response")
66 def test_delete_alarm_resp(self
, del_alarm_resp
):
67 """Test delete alarm response function call."""
68 message
= self
.plugin_resp
.generate_response("delete_alarm_response")
69 self
.assertEqual(message
, del_alarm_resp
.return_value
)
72 resp
.OpenStack_Response
, "delete_metric_response")
73 def test_delete_metric_resp(self
, del_metric_resp
):
74 """Test the response functionality of delete metric response."""
75 message
= self
.plugin_resp
.generate_response("delete_metric_response")
76 self
.assertEqual(message
, del_metric_resp
.return_value
)
79 resp
.OpenStack_Response
, "create_alarm_response")
80 def test_create_alarm_resp(self
, config_alarm_resp
):
81 """Test create alarm response function call."""
82 message
= self
.plugin_resp
.generate_response("create_alarm_response")
83 self
.assertEqual(message
, config_alarm_resp
.return_value
)
86 resp
.OpenStack_Response
, "metric_create_response")
87 def test_create_metric_resp(self
, config_metric_resp
):
88 """Test create metric response function call."""
89 message
= self
.plugin_resp
.generate_response("create_metric_response")
90 self
.assertEqual(message
, config_metric_resp
.return_value
)
93 resp
.OpenStack_Response
, "update_alarm_response")
94 def test_update_alarm_resp(self
, up_alarm_resp
):
95 """Test update alarm response function call."""
96 message
= self
.plugin_resp
.generate_response("update_alarm_response")
97 self
.assertEqual(message
, up_alarm_resp
.return_value
)
100 resp
.OpenStack_Response
, "update_metric_response")
101 def test_update_metric_resp(self
, up_metric_resp
):
102 """Test update metric response function call."""
103 message
= self
.plugin_resp
.generate_response("update_metric_response")
104 self
.assertEqual(message
, up_metric_resp
.return_value
)
107 resp
.OpenStack_Response
, "notify_alarm")
108 def test_notify_alarm(self
, notify_alarm
):
109 """Test notify alarm response function call."""
110 message
= self
.plugin_resp
.generate_response("notify_alarm")
111 self
.assertEqual(message
, notify_alarm
.return_value
)
114 resp
.OpenStack_Response
, "read_metric_data_response")
115 def test_read_metric_data_resp(self
, read_data_resp
):
116 """Test read metric data response function call."""
117 message
= self
.plugin_resp
.generate_response(
118 "read_metric_data_response")
119 self
.assertEqual(message
, read_data_resp
.return_value
)