Skip to content

Commit 30b474e

Browse files
committed
address comments
1 parent 08254f1 commit 30b474e

File tree

3 files changed

+25
-27
lines changed

3 files changed

+25
-27
lines changed

redis_sync/src/log_decorator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
The decorator log pattern is shared by filenameprocessor, recordprocessor, ack_backend and redis_sync modules.
33
and therefore could be moved to a common module in the future.
44
TODO: refactor to a common module.
5+
TODO: Duplication check has been suppressed in sonar-project.properties. Remove once refactored.
56
"""
67
import json
78
import time

redis_sync/tests/test_handler.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def tearDown(self):
3939
self.logger_error_patcher.stop()
4040
self.logger_exception_patcher.stop()
4141

42-
# @patch("log_decorator.logging_decorator", lambda prefix=None: (lambda f: f))
4342
def test_handler_success(self):
4443
with patch("log_decorator.logging_decorator", lambda prefix=None: (lambda f: f)):
4544
importlib.reload(redis_sync)

redis_sync/tests/test_handler_with_decorator.py renamed to redis_sync/tests/test_handler_decorator.py

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -161,32 +161,30 @@ def test_handler_with_empty_event(self):
161161
def test_handler_multi_record(self):
162162
mock_event = {'Records': [self.s3_vaccine, self.s3_supplier]}
163163

164-
with patch.object(self.mock_get_s3_records,
165-
"return_value",
166-
[S3EventRecord(self.s3_vaccine), S3EventRecord(self.s3_supplier)]):
167-
# repatch mock_record_processor
168-
with patch("redis_sync.process_record") as mock_record_processor:
169-
# Mock the return value for each record
170-
mock_record_processor.side_effect = [
171-
{'status': 'success', 'message': 'Processed successfully',
172-
'file_key': RedisCacheKey.DISEASE_MAPPING_FILE_KEY},
173-
{'status': 'success', 'message': 'Processed successfully',
174-
'file_key': RedisCacheKey.PERMISSIONS_CONFIG_FILE_KEY}
175-
]
176-
177-
handler(mock_event, None)
178-
179-
# Get put_record arguments
180-
args, kwargs = self.mock_firehose_client.put_record.call_args
181-
record = kwargs.get("Record") or args[1]
182-
data_bytes = record["Data"]
183-
log_json = data_bytes.decode("utf-8")
184-
log_dict = json.loads(log_json)
185-
# check expected content
186-
event = log_dict["event"]
187-
self.assertIn("function_name", event)
188-
self.assertEqual(event["function_name"], "redis_sync_handler")
189-
self.assertEqual(event["status"], "success")
164+
self.mock_get_s3_records.return_value = [
165+
S3EventRecord(self.s3_vaccine), S3EventRecord(self.s3_supplier)]
166+
167+
# Mock the return value for each record
168+
self.mock_record_processor.side_effect = [
169+
{'status': 'success', 'message': 'Processed successfully',
170+
'file_key': RedisCacheKey.DISEASE_MAPPING_FILE_KEY},
171+
{'status': 'success', 'message': 'Processed successfully',
172+
'file_key': RedisCacheKey.PERMISSIONS_CONFIG_FILE_KEY}
173+
]
174+
175+
handler(mock_event, None)
176+
177+
# Get put_record arguments
178+
args, kwargs = self.mock_firehose_client.put_record.call_args
179+
record = kwargs.get("Record") or args[1]
180+
data_bytes = record["Data"]
181+
log_json = data_bytes.decode("utf-8")
182+
log_dict = json.loads(log_json)
183+
# check expected content
184+
event = log_dict["event"]
185+
self.assertIn("function_name", event)
186+
self.assertEqual(event["function_name"], "redis_sync_handler")
187+
self.assertEqual(event["status"], "success")
190188

191189
# test to check that event_read is called when "read" key is passed in the event
192190
def test_handler_read_event(self):

0 commit comments

Comments
 (0)