Skip to content

Commit 9ebdee8

Browse files
committed
Address comments
1 parent 373eeba commit 9ebdee8

File tree

4 files changed

+24
-25
lines changed

4 files changed

+24
-25
lines changed

redis_sync/src/log_decorator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# NOSONAR
12
"""This module contains the logging decorator for sending the appropriate logs to Cloudwatch and Firehose.
23
The decorator log pattern is shared by filenameprocessor, recordprocessor, ack_backend and redis_sync modules.
34
and therefore could be moved to a common module in the future.

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: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -164,29 +164,28 @@ def test_handler_multi_record(self):
164164
with patch.object(self.mock_get_s3_records,
165165
"return_value",
166166
[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")
167+
168+
# Mock the return value for each record
169+
self.mock_record_processor.side_effect = [
170+
{'status': 'success', 'message': 'Processed successfully',
171+
'file_key': RedisCacheKey.DISEASE_MAPPING_FILE_KEY},
172+
{'status': 'success', 'message': 'Processed successfully',
173+
'file_key': RedisCacheKey.PERMISSIONS_CONFIG_FILE_KEY}
174+
]
175+
176+
handler(mock_event, None)
177+
178+
# Get put_record arguments
179+
args, kwargs = self.mock_firehose_client.put_record.call_args
180+
record = kwargs.get("Record") or args[1]
181+
data_bytes = record["Data"]
182+
log_json = data_bytes.decode("utf-8")
183+
log_dict = json.loads(log_json)
184+
# check expected content
185+
event = log_dict["event"]
186+
self.assertIn("function_name", event)
187+
self.assertEqual(event["function_name"], "redis_sync_handler")
188+
self.assertEqual(event["status"], "success")
190189

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

sonar-project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ sonar.projectKey=NHSDigital_immunisation-fhir-api
33
sonar.organization=nhsdigital
44
sonar.host.url=https://sonarcloud.io
55
sonar.python.version=3.11
6-
sonar.exclusions=**/e2e/**,**/e2e_batch/**,**/temporary_sandbox/**,**/devtools/**,**/proxies/**,**/scripts/**,**/terraform/**,**/tests/**,redis_sync/src/log_decorator.py
6+
sonar.exclusions=**/e2e/**,**/e2e_batch/**,**/temporary_sandbox/**,**/devtools/**,**/proxies/**,**/scripts/**,**/terraform/**,**/tests/**
77
sonar.python.coverage.reportPaths=backend-coverage.xml,delta-coverage.xml,ack-lambda-coverage.xml,filenameprocessor-coverage.xml,recordforwarder-coverage.xml,recordprocessor-coverage.xml,mesh_processor-coverage.xml,redis_sync-coverage.xml
88
sonar.issue.ignore.multicriteria=exclude_snomed_urls,exclude_hl7_urls
99
sonar.issue.ignore.multicriteria.exclude_snomed_urls.ruleKey=python:S5332

0 commit comments

Comments
 (0)