Skip to content

Commit 71c442a

Browse files
committed
lint & tests
1 parent 0f78417 commit 71c442a

File tree

8 files changed

+32
-14
lines changed

8 files changed

+32
-14
lines changed
File renamed without changes.
File renamed without changes.

lambdas/id_sync/src/id_sync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from common.clients import STREAM_NAME
33
from common.log_decorator import logging_decorator
44
from common.aws_lambda_event import AwsLambdaEvent
5-
from models.id_sync_exception import IdSyncException
5+
from exceptions.id_sync_exception import IdSyncException
66
from record_processor import process_record
77
'''
88
Lambda function handler for processing SQS events.Lambda for ID Sync. Fired by SQS

lambdas/id_sync/src/ieds_db_operations.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from os_vars import get_ieds_table_name
33
from common.aws_dynamodb import get_dynamodb_table
44
from common.clients import logger
5+
from exceptions.id_sync_exception import IdSyncException
56

67
ieds_table = None
78

@@ -58,5 +59,9 @@ def ieds_update_patient_id(old_id: str, new_id: str) -> dict:
5859

5960
except Exception as e:
6061
logger.exception("Error updating patient ID")
61-
# Handle any exceptions that occur during the update
62+
raise IdSyncException(
63+
message=f"Error updating patient Id from :{old_id} to {new_id}",
64+
nhs_numbers=[old_id, new_id],
65+
exception=e
66+
)
6267
raise e

lambdas/id_sync/src/pds_details.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from os_vars import get_pds_env
88
from common.pds_service import PdsService
99
from common.authentication import AppRestrictedAuth, Service
10-
from models.id_sync_exception import IdSyncException
10+
from exceptions.id_sync_exception import IdSyncException
1111

1212
pds_env = get_pds_env()
1313
safe_tmp_dir = tempfile.mkdtemp(dir="/tmp") # NOSONAR

lambdas/id_sync/tests/test_id_sync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
with patch('common.log_decorator.logging_decorator') as mock_decorator:
66
mock_decorator.return_value = lambda f: f # Pass-through decorator
77
from id_sync import handler
8-
from models.id_sync_exception import IdSyncException
8+
from exceptions.id_sync_exception import IdSyncException
99

1010

1111
class TestIdSyncHandler(unittest.TestCase):

lambdas/id_sync/tests/test_ieds_db_operations.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import unittest
22
from unittest.mock import patch, MagicMock
33
from boto3.dynamodb.conditions import Key
4+
from exceptions.id_sync_exception import IdSyncException
45

56
import ieds_db_operations
67

@@ -261,6 +262,7 @@ def test_get_ieds_table_exception_handling(self):
261262
self.mock_get_ieds_table_name.assert_called_once()
262263
self.mock_get_dynamodb_table.assert_called_once()
263264

265+
264266
class TestIedsCheckExists(TestIedsDbOperations):
265267

266268
def setUp(self):
@@ -662,20 +664,21 @@ def test_ieds_update_patient_id_update_exception(self):
662664
# Arrange
663665
old_id = "old-patient-error"
664666
new_id = "new-patient-error"
665-
self.mock_table.update_item.side_effect = Exception("DynamoDB update failed")
667+
test_exception = Exception("DynamoDB update failed")
668+
self.mock_table.update_item.side_effect = test_exception
666669

667670
# Act & Assert
668671
with self.assertRaises(Exception) as context:
669672
ieds_db_operations.ieds_update_patient_id(old_id, new_id)
670673

671-
self.assertEqual(str(context.exception), "DynamoDB update failed")
674+
exception = context.exception
675+
676+
self.assertEqual(exception.message, "Error updating patient Id from :old-patient-error to new-patient-error")
677+
self.assertEqual(exception.nhs_numbers, ["old-patient-error", "new-patient-error"])
678+
self.assertEqual(exception.inner_exception, test_exception)
672679

673680
# Verify update was attempted
674-
self.mock_table.update_item.assert_called_once_with(
675-
Key={"PK": f"Patient#{old_id}"},
676-
UpdateExpression="SET PK = :new_id",
677-
ExpressionAttributeValues={":new_id": f"Patient#{new_id}"}
678-
)
681+
self.mock_table.update_item.assert_called_once()
679682

680683
# Verify logger exception was called
681684
self.mock_logger.exception.assert_called_once_with("Error updating patient ID")
@@ -685,13 +688,18 @@ def test_ieds_update_patient_id_get_table_exception(self):
685688
# Arrange
686689
old_id = "old-patient-123"
687690
new_id = "new-patient-456"
688-
self.mock_get_ieds_table_patcher.side_effect = Exception("Failed to get IEDS table")
691+
test_exception = Exception("Failed to get IEDS table")
692+
self.mock_get_ieds_table_patcher.side_effect = test_exception
689693

690694
# Act & Assert
691695
with self.assertRaises(Exception) as context:
692696
ieds_db_operations.ieds_update_patient_id(old_id, new_id)
693697

694-
self.assertEqual(str(context.exception), "Failed to get IEDS table")
698+
exception = context.exception
699+
700+
self.assertEqual(exception.message, "Error updating patient Id from :old-patient-123 to new-patient-456")
701+
self.assertEqual(exception.nhs_numbers, [old_id, new_id])
702+
self.assertEqual(exception.inner_exception, test_exception)
695703

696704
# Verify get_ieds_table was called
697705
self.mock_get_ieds_table_patcher.assert_called_once()
@@ -713,6 +721,11 @@ def test_ieds_update_patient_id_missing_response_metadata(self):
713721
with self.assertRaises(Exception) as context:
714722
ieds_db_operations.ieds_update_patient_id(old_id, new_id)
715723

724+
exception = context.exception
725+
self.assertIsInstance(exception, IdSyncException)
726+
self.assertEqual(exception.message, f"Error updating patient Id from :{old_id} to {new_id}")
727+
self.assertEqual(exception.nhs_numbers, [old_id, new_id])
728+
716729
# Verify update was attempted
717730
self.mock_table.update_item.assert_called_once()
718731

lambdas/id_sync/tests/test_pds_details.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import unittest
22
from unittest.mock import patch, MagicMock
33
from pds_details import pds_get_patient_details, pds_get_patient_id
4-
from models.id_sync_exception import IdSyncException
4+
from exceptions.id_sync_exception import IdSyncException
55

66

77
class TestGetPdsPatientDetails(unittest.TestCase):

0 commit comments

Comments
 (0)