def test_put_v2_config_success(self, mock_alert_source_get, mock_alert_source_update): req = fakes.HTTPRequest.blank('/storages/fake_id/alert-source') fake_storage_id = 'abcd-1234-5678' mock_alert_source_update.return_value = fakes.fake_v2_alert_source() mock_alert_source_get.return_value = fakes.fake_v2_alert_source() expected_alert_source = { 'storage_id': 'abcd-1234-5678', 'host': '127.0.0.1', 'community_string': 'public', 'version': 'snmpv2c', 'engine_id': None, 'security_level': None, 'username': None, 'auth_protocol': None, 'privacy_protocol': None, 'port': 161, 'context_name': "", 'retry_num': 1, 'expiration': 1, "created_at": '2020-06-15T09:50:31.698956', "updated_at": '2020-06-15T09:50:31.698956' } alert_controller_inst = self._get_alert_controller() body = fakes.fake_v2_alert_source_config() output_alert_source = alert_controller_inst.put(req, fake_storage_id, body=body) self.assertDictEqual(expected_alert_source, output_alert_source)
def test_put_v2_config_success(self, mock_alert_source_get, mock_alert_source_update): req = fakes.HTTPRequest.blank('/storages/fake_id/snmp-config') fake_storage_id = 'abcd-1234-5678' return_v2_alert_source = fakes.fake_v2_alert_source() return_v2_alert_source['community_string'] = cryptor.encode( return_v2_alert_source['community_string']) mock_alert_source_update.return_value = return_v2_alert_source mock_alert_source_get.return_value = return_v2_alert_source expected_alert_source = {'storage_id': 'abcd-1234-5678', 'host': '127.0.0.1', 'community_string': 'public', 'version': 'snmpv2c', 'port': 161, "retry_num": 1, "expiration": 1, "created_at": '2020-06-15T09:50:31.698956', "updated_at": '2020-06-15T09:50:31.698956' } alert_controller_inst = self._get_alert_controller() body = fakes.fake_v2_alert_source_config() output_alert_source = alert_controller_inst.put(req, fake_storage_id, body=body) self.assertDictEqual(expected_alert_source, output_alert_source)
def test_put_without_community_str(self, mock_alert_source_get, mock_alert_source_update): req = fakes.HTTPRequest.blank('/storages/fake_id/snmp-config') fake_storage_id = 'abcd-1234-5678' mock_alert_source_update.return_value = {} mock_alert_source_get.return_value = fakes.fake_v2_alert_source() alert_controller_inst = self._get_alert_controller() body = fakes.fake_v2_alert_source_config() body['community_string'] = '' self.assertRaisesRegex(exception.InvalidInput, "Invalid input " "received. Invalid " "input for " "field/attribute " "community_string.", alert_controller_inst.put, req, fake_storage_id, body=body)