@@ -331,20 +331,16 @@ def test_ieds_update_patient_id_success(self):
331331
332332 # Mock items to update
333333 mock_items = [
334- {"PK" : "Patient#old-patient-123" , "PatientPK" : "Patient#old-patient-123" },
335- {
336- "PK" : "Patient#old-patient-123#record1" ,
337- "PatientPK" : "Patient#old-patient-123" ,
338- },
334+ {"PK" : "Immunization#old-patient-123" , "PatientPK" : "Patient#old-patient-123" },
335+ {"PK" : "Patient#old-patient-123#record1" , "PatientPK" : "Patient#old-patient-123" },
339336 ]
340- self .mock_get_items_from_patient_id .return_value = mock_items
341337
342338 # Mock successful transact_write_items response
343339 mock_transact_response = {"ResponseMetadata" : {"HTTPStatusCode" : 200 }}
344340 self .mock_dynamodb_client_patcher .transact_write_items .return_value = mock_transact_response
345341
346342 # Act
347- result = ieds_db_operations .ieds_update_patient_id (old_id , new_id )
343+ result = ieds_db_operations .ieds_update_patient_id (old_id , new_id , mock_items )
348344
349345 # Assert - Update expected message to match actual implementation
350346 expected_result = {
@@ -353,9 +349,6 @@ def test_ieds_update_patient_id_success(self):
353349 }
354350 self .assertEqual (result , expected_result )
355351
356- # Verify get_items_from_patient_id was called
357- self .mock_get_items_from_patient_id .assert_called_once_with (old_id )
358-
359352 # Verify transact_write_items was called
360353 self .mock_dynamodb_client_patcher .transact_write_items .assert_called_once ()
361354
@@ -367,14 +360,13 @@ def test_ieds_update_patient_id_non_200_response(self):
367360
368361 # Mock items to update
369362 mock_items = [{"PK" : "Patient#old-patient-123" , "PatientPK" : "Patient#old-patient-123" }]
370- self .mock_get_items_from_patient_id .return_value = mock_items
371363
372364 # Mock failed transact_write_items response (not update_item)
373365 mock_transact_response = {"ResponseMetadata" : {"HTTPStatusCode" : 400 }}
374366 self .mock_dynamodb_client_patcher .transact_write_items .return_value = mock_transact_response
375367
376368 # Act
377- result = ieds_db_operations .ieds_update_patient_id (old_id , new_id )
369+ result = ieds_db_operations .ieds_update_patient_id (old_id , new_id , mock_items )
378370
379371 # Assert
380372 expected_result = {
@@ -392,11 +384,8 @@ def test_ieds_update_patient_id_no_items_found(self):
392384 old_id = "old-patient-123"
393385 new_id = "new-patient-456"
394386
395- # Mock empty items list
396- self .mock_get_items_from_patient_id .return_value = []
397-
398387 # Act
399- result = ieds_db_operations .ieds_update_patient_id (old_id , new_id )
388+ result = ieds_db_operations .ieds_update_patient_id (old_id , new_id , [] )
400389
401390 # Assert
402391 expected_result = {
@@ -405,71 +394,9 @@ def test_ieds_update_patient_id_no_items_found(self):
405394 }
406395 self .assertEqual (result , expected_result )
407396
408- # Verify get_items_from_patient_id was called
409- self .mock_get_items_from_patient_id .assert_called_once_with (old_id )
410-
411397 # Verify no transact operation was attempted
412398 self .mock_table .transact_write_items .assert_not_called ()
413399
414- def test_ieds_update_patient_id_empty_old_id (self ):
415- """Test update with empty old_id"""
416- # Arrange
417- old_id = ""
418- new_id = "new-patient-456"
419-
420- # Act
421- result = ieds_db_operations .ieds_update_patient_id (old_id , new_id )
422-
423- # Assert
424- expected_result = {
425- "status" : "error" ,
426- "message" : "Old ID and New ID cannot be empty" ,
427- }
428- self .assertEqual (result , expected_result )
429-
430- # Verify no update was attempted
431- self .mock_table .transact_write_items .assert_not_called ()
432- self .mock_get_ieds_table_patcher .assert_not_called ()
433-
434- def test_ieds_update_patient_id_empty_new_id (self ):
435- """Test update with empty new_id"""
436- # Arrange
437- old_id = "old-patient-123"
438- new_id = ""
439-
440- # Act
441- result = ieds_db_operations .ieds_update_patient_id (old_id , new_id )
442-
443- # Assert
444- expected_result = {
445- "status" : "error" ,
446- "message" : "Old ID and New ID cannot be empty" ,
447- }
448- self .assertEqual (result , expected_result )
449-
450- # Verify no update was attempted
451- self .mock_table .transact_write_items .assert_not_called ()
452- self .mock_get_ieds_table_patcher .assert_not_called ()
453-
454- def test_ieds_update_patient_id_same_old_and_new_id (self ):
455- """Test update when old_id and new_id are the same"""
456- # Arrange
457- patient_id = "same-patient-id"
458-
459- # Act
460- result = ieds_db_operations .ieds_update_patient_id (patient_id , patient_id )
461-
462- # Assert
463- expected_result = {
464- "status" : "success" ,
465- "message" : "No change in patient ID" ,
466- }
467- self .assertEqual (result , expected_result )
468-
469- # Verify no update was attempted
470- self .mock_table .transact_write_items .assert_not_called ()
471- self .mock_get_ieds_table_patcher .assert_not_called ()
472-
473400 def test_ieds_update_patient_id_update_exception (self ):
474401 """Test exception handling during transact_write_items"""
475402 # Arrange
@@ -483,52 +410,24 @@ def test_ieds_update_patient_id_update_exception(self):
483410 "PatientPK" : "Patient#old-patient-error" ,
484411 }
485412 ]
486- self .mock_get_items_from_patient_id .return_value = mock_items
487413
488414 test_exception = Exception ("DynamoDB transact failed" )
489415 self .mock_dynamodb_client_patcher .transact_write_items .side_effect = test_exception
490416
491417 # Act & Assert
492418 with self .assertRaises (Exception ) as context :
493- ieds_db_operations .ieds_update_patient_id (old_id , new_id )
419+ ieds_db_operations .ieds_update_patient_id (old_id , new_id , mock_items )
494420
495421 exception = context .exception
496422 self .assertIsInstance (exception , IdSyncException )
497423 self .assertEqual (exception .message , "Error updating patient ID" )
498- self .assertEqual (exception .inner_exception , test_exception )
499424
500425 # Verify transact was attempted
501426 self .mock_dynamodb_client_patcher .transact_write_items .assert_called_once ()
502427
503428 # Verify logger exception was called
504429 self .mock_logger .exception .assert_called_once_with ("Error updating patient ID" )
505430
506- def test_ieds_update_patient_id_special_characters (self ):
507- """Test update with special characters in IDs"""
508- # Arrange
509- old_id = "old-patient@123#$%"
510- new_id = "new-patient&456*()+"
511-
512- # Mock items to update
513- mock_items = [{"PK" : f"Patient#{ old_id } " , "PatientPK" : f"Patient#{ old_id } " }]
514- self .mock_get_items_from_patient_id .return_value = mock_items
515-
516- mock_transact_response = {"ResponseMetadata" : {"HTTPStatusCode" : 200 }}
517- self .mock_dynamodb_client_patcher .transact_write_items .return_value = mock_transact_response
518-
519- # Act
520- result = ieds_db_operations .ieds_update_patient_id (old_id , new_id )
521-
522- # Assert
523- self .assertEqual (result ["status" ], "success" )
524- self .assertEqual (
525- result ["message" ],
526- f"IEDS update. { len (mock_items )} item(s) updated in 1 batch(es)." ,
527- )
528-
529- # Verify transact_write_items was called with special characters
530- self .mock_dynamodb_client_patcher .transact_write_items .assert_called_once ()
531-
532431
533432class TestGetItemsToUpdate (TestIedsDbOperations ):
534433 def setUp (self ):
@@ -601,14 +500,6 @@ def setUp(self):
601500 def tearDown (self ):
602501 patch .stopall ()
603502
604- def test_ieds_update_patient_id_empty_inputs (self ):
605- res = ieds_db_operations .ieds_update_patient_id ("" , "" )
606- self .assertEqual (res ["status" ], "error" )
607-
608- def test_ieds_update_patient_id_same_ids (self ):
609- res = ieds_db_operations .ieds_update_patient_id ("a" , "a" )
610- self .assertEqual (res ["status" ], "success" )
611-
612503 def test_ieds_update_with_items_to_update_uses_provided_list (self ):
613504 items = [{"PK" : "Patient#1" }, {"PK" : "Patient#1#r2" }]
614505 # patch transact_write_items to return success
0 commit comments