|
6 | 6 | from common.log_decorator import ( |
7 | 7 | generate_and_send_logs, |
8 | 8 | logging_decorator, |
9 | | - send_log_to_firehose, |
10 | 9 | ) |
| 10 | +from common.log_firehose import send_log_to_firehose |
11 | 11 |
|
12 | 12 |
|
13 | 13 | class TestLogDecorator(unittest.TestCase): |
14 | 14 | def setUp(self): |
15 | 15 | self.test_stream = "test-stream" |
16 | 16 | self.test_prefix = "test" |
17 | | - self.logger_info_patcher = patch("common.log_decorator.logger.info") |
18 | | - self.mock_logger_info = self.logger_info_patcher.start() |
19 | | - self.logger_exception_patcher = patch("common.log_decorator.logger.exception") |
20 | | - self.mock_logger_exception = self.logger_exception_patcher.start() |
21 | 17 | self.logger_error_patcher = patch("common.log_decorator.logger.error") |
22 | 18 | self.mock_logger_error = self.logger_error_patcher.start() |
23 | | - self.firehose_client_patcher = patch("common.log_decorator.firehose_client") |
24 | | - self.mock_firehose_client = self.firehose_client_patcher.start() |
25 | 19 | # patch common.log_decorator.time |
26 | 20 | self.mock_generate_send = patch("common.log_decorator.generate_and_send_logs").start() |
27 | 21 |
|
28 | 22 | def tearDown(self): |
29 | 23 | patch.stopall() |
30 | 24 |
|
31 | | - def test_send_log_to_firehose_success(self): |
32 | | - """Test send_log_to_firehose with successful firehose response""" |
33 | | - # Arrange |
34 | | - test_log_data = {"function_name": "test_func", "result": "success"} |
35 | | - mock_response = {"ResponseMetadata": {"HTTPStatusCode": 200}} |
36 | | - self.mock_firehose_client.put_record.return_value = mock_response |
37 | | - |
38 | | - # Act |
39 | | - send_log_to_firehose(self.test_stream, test_log_data) |
40 | | - |
41 | | - # Assert |
42 | | - expected_record = {"Data": json.dumps({"event": test_log_data}).encode("utf-8")} |
43 | | - self.mock_firehose_client.put_record.assert_called_once_with( |
44 | | - DeliveryStreamName=self.test_stream, Record=expected_record |
45 | | - ) |
46 | | - |
47 | | - def test_send_log_to_firehose_exception(self): |
48 | | - """Test send_log_to_firehose with firehose exception""" |
49 | | - # Arrange |
50 | | - test_log_data = {"function_name": "test_func", "result": "error"} |
51 | | - self.mock_firehose_client.put_record.side_effect = Exception("Firehose error") |
52 | | - |
53 | | - # Act |
54 | | - send_log_to_firehose(self.test_stream, test_log_data) |
55 | | - |
56 | | - # Assert |
57 | | - self.mock_firehose_client.put_record.assert_called_once() |
58 | | - self.mock_logger_exception.assert_called_once_with( |
59 | | - "Error sending log to Firehose: %s", |
60 | | - self.mock_firehose_client.put_record.side_effect, |
61 | | - ) |
62 | | - |
63 | 25 | @patch("time.time") |
64 | 26 | @patch("common.log_decorator.send_log_to_firehose") |
65 | 27 | def test_generate_and_send_logs_success(self, mock_send_log, mock_time): |
@@ -217,23 +179,3 @@ def documented_function(): |
217 | 179 | # Act & Assert |
218 | 180 | self.assertEqual(documented_function.__name__, "documented_function") |
219 | 181 | self.assertEqual(documented_function.__doc__, "This is a test function with documentation") |
220 | | - |
221 | | - def test_send_log_to_firehose_exception_logging(self): |
222 | | - """Test that logger.exception is called when firehose_client.put_record throws an error""" |
223 | | - # Arrange |
224 | | - test_log_data = {"function_name": "test_func", "result": "error"} |
225 | | - test_error = Exception("Firehose connection failed") |
226 | | - self.mock_firehose_client.put_record.side_effect = test_error |
227 | | - |
228 | | - # Act |
229 | | - send_log_to_firehose(self.test_stream, test_log_data) |
230 | | - |
231 | | - # Assert |
232 | | - # Verify firehose_client.put_record was called |
233 | | - expected_record = {"Data": json.dumps({"event": test_log_data}).encode("utf-8")} |
234 | | - self.mock_firehose_client.put_record.assert_called_once_with( |
235 | | - DeliveryStreamName=self.test_stream, Record=expected_record |
236 | | - ) |
237 | | - |
238 | | - # Verify logger.exception was called with the correct message and error |
239 | | - self.mock_logger_exception.assert_called_once_with("Error sending log to Firehose: %s", test_error) |
0 commit comments