| Helena McGough | fe92f84 | 2017-11-17 14:57:08 +0000 | [diff] [blame] | 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 plugins.OpenStack import response as resp |
| 31 | |
| 32 | __author__ = "Helena McGough" |
| 33 | |
| 34 | log = logging.getLogger(__name__) |
| 35 | |
| 36 | |
| 37 | class TestOpenStackResponse(unittest.TestCase): |
| 38 | """Tests for responses generated by the OpenStack plugins.""" |
| 39 | |
| 40 | def setUp(self): |
| 41 | """Setup for testing OpenStack plugin responses.""" |
| 42 | super(TestOpenStackResponse, self).setUp() |
| 43 | self.plugin_resp = resp.OpenStack_Response() |
| 44 | |
| 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) |
| 49 | |
| 50 | @mock.patch.object( |
| 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) |
| 56 | |
| 57 | @mock.patch.object( |
| 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) |
| 63 | |
| 64 | @mock.patch.object( |
| 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) |
| 70 | |
| 71 | @mock.patch.object( |
| 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) |
| 77 | |
| 78 | @mock.patch.object( |
| 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) |
| 84 | |
| 85 | @mock.patch.object( |
| 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) |
| 91 | |
| 92 | @mock.patch.object( |
| 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) |
| 98 | |
| 99 | @mock.patch.object( |
| 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) |
| 105 | |
| 106 | @mock.patch.object( |
| 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) |
| 112 | |
| 113 | @mock.patch.object( |
| 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) |