def test_get_sources_msg_data_malformed(self): """Test to get sources details from Application.create event with malformed data.""" test_topic = 'platform.sources.event-stream' test_event_type = 'Application.create' test_offset = 5 cost_management_app_type = 2 test_auth_header = 'testheader' test_value = {'id': 1, 'source_id': 1, 'application_type_id': 2} msg = ConsumerRecord(topic=test_topic, offset=test_offset, event_type=test_event_type, auth_header=test_auth_header, value=test_value) with self.assertRaises(source_integration.SourcesIntegrationError): source_integration.get_sources_msg_data(msg, cost_management_app_type)
def test_get_sources_msg_data_other(self): """Test to get sources details from other message.""" test_topic = 'platform.sources.event-stream' test_offset = 5 cost_management_app_type = 2 test_auth_header = 'testheader' test_value = '{"id":1,"source_id":1,"application_type_id":2}' source_events = [{ 'event': 'Source.create', 'expected_response': {} }, { 'event': 'Source.update', 'expected_response': { 'source_id': 1, 'offset': test_offset, 'event_type': 'Source.update', 'auth_header': test_auth_header } }] for test in source_events: msg = ConsumerRecord(topic=test_topic, offset=test_offset, event_type=test.get('event'), auth_header=test_auth_header, value=bytes(test_value, encoding='utf-8')) response = source_integration.get_sources_msg_data( msg, cost_management_app_type) self.assertEqual(response, test.get('expected_response'))
def test_get_sources_msg_data_other(self): """Test to get sources details from other message.""" test_topic = "platform.sources.event-stream" test_offset = 5 cost_management_app_type = 2 test_auth_header = "testheader" test_value = '{"id":1,"source_id":1,"application_type_id":2}' source_events = [ {"event": "Source.create", "expected_response": {}}, { "event": "Source.update", "expected_response": { "source_id": 1, "offset": test_offset, "event_type": "Source.update", "auth_header": test_auth_header, }, }, ] for test in source_events: msg = ConsumerRecord( topic=test_topic, offset=test_offset, event_type=test.get("event"), auth_header=test_auth_header, value=bytes(test_value, encoding="utf-8"), ) response = source_integration.get_sources_msg_data(msg, cost_management_app_type) self.assertEqual(response, test.get("expected_response"))
def test_get_sources_msg_data_other_app_type(self): """Test to get sources details from Application.create event type for a non-Cost Management app.""" test_topic = 'platform.sources.event-stream' test_event_type = 'Application.create' test_offset = 5 cost_management_app_type = 2 test_auth_header = 'testheader' test_value = '{"id":1,"source_id":1,"application_type_id":1}' # 1 is not Cost Management msg = ConsumerRecord(topic=test_topic, offset=test_offset, event_type=test_event_type, auth_header=test_auth_header, value=bytes(test_value, encoding='utf-8')) response = source_integration.get_sources_msg_data(msg, cost_management_app_type) self.assertEqual(response, {})
def test_get_sources_msg_authentication(self): """Test to get sources details from msg for Authentication.create event.""" test_topic = 'platform.sources.event-stream' authentication_events = ['Authentication.create', 'Authentication.update'] test_offset = 5 cost_management_app_type = 2 test_auth_header = 'testheader' test_value = '{"id":1,"resource_id":1,"resource_type": "Endpoint"}' for event in authentication_events: msg = ConsumerRecord(topic=test_topic, offset=test_offset, event_type=event, auth_header=test_auth_header, value=bytes(test_value, encoding='utf-8')) response = source_integration.get_sources_msg_data(msg, cost_management_app_type) self.assertEqual(response.get('event_type'), event) self.assertEqual(response.get('resource_id'), 1) self.assertEqual(response.get('auth_header'), test_auth_header)
def test_get_sources_msg_data(self): """Test to get sources details from msg.""" test_topic = 'platform.sources.event-stream' test_event_type = 'Application.create' test_offset = 5 cost_management_app_type = 2 test_auth_header = 'testheader' test_value = '{"id":1,"source_id":1,"application_type_id":2}' msg = ConsumerRecord(topic=test_topic, offset=test_offset, event_type=test_event_type, auth_header=test_auth_header, value=bytes(test_value, encoding='utf-8')) response = source_integration.get_sources_msg_data(msg, cost_management_app_type) self.assertEqual(response.get('event_type'), test_event_type) self.assertEqual(response.get('offset'), test_offset) self.assertEqual(response.get('source_id'), 1) self.assertEqual(response.get('auth_header'), test_auth_header)
def test_get_sources_msg_data(self): """Test to get sources details from msg.""" test_topic = "platform.sources.event-stream" test_event_type = "Application.create" test_offset = 5 cost_management_app_type = 2 test_auth_header = "testheader" test_value = '{"id":1,"source_id":1,"application_type_id":2}' msg = ConsumerRecord( topic=test_topic, offset=test_offset, event_type=test_event_type, auth_header=test_auth_header, value=bytes(test_value, encoding="utf-8"), ) response = source_integration.get_sources_msg_data(msg, cost_management_app_type) self.assertEqual(response.get("event_type"), test_event_type) self.assertEqual(response.get("offset"), test_offset) self.assertEqual(response.get("source_id"), 1) self.assertEqual(response.get("auth_header"), test_auth_header)