@@ -68,44 +68,6 @@ def service(set_env, mock_virus_scan_service):
6868 return service
6969
7070
71- @pytest .fixture
72- def mock_pdm_document_reference ():
73- """Create a mock document reference"""
74- doc_ref = Mock (spec = DocumentReference )
75- doc_ref .id = "test-doc-id"
76- doc_ref .nhs_number = "9000000001"
77- doc_ref .s3_file_key = (
78- f"fhir_upload/{ SnomedCodes .PATIENT_DATA .value .code } /9000000001/test-doc-id"
79- )
80- doc_ref .s3_bucket_name = "test-staging-bucket"
81- doc_ref .virus_scanner_result = None
82- doc_ref .file_size = 1234567890
83- doc_ref .doc_status = "uploading"
84- doc_ref ._build_s3_location = Mock (
85- return_value = f"s3://test-staging-bucket/fhir_upload/{ SnomedCodes .PATIENT_DATA .value .code } /9000000001/test-doc-id"
86- )
87- return doc_ref
88-
89-
90- @pytest .fixture
91- def pdm_service (set_env , mock_virus_scan_service ):
92- with patch .multiple (
93- "services.upload_document_reference_service" ,
94- DocumentService = Mock (),
95- DynamoDBService = Mock (),
96- S3Service = Mock (),
97- ):
98- service = UploadDocumentReferenceService ()
99- service .document_service = Mock ()
100- service .dynamo_service = Mock ()
101- service .virus_scan_service = MockVirusScanService ()
102- service .s3_service = Mock ()
103- service .table_name = MOCK_PDM_TABLE_NAME
104- service .destination_bucket_name = MOCK_PDM_BUCKET
105- service .doc_type = SnomedCodes .PATIENT_DATA .value
106- return service
107-
108-
10971def test_handle_upload_document_reference_request_with_empty_object_key (service ):
11072 """Test handling of an empty object key"""
11173 service .handle_upload_document_reference_request ("" , 122 )
@@ -167,6 +129,7 @@ def test_handle_upload_document_reference_request_with_exception(service):
167129def test_fetch_preliminary_document_reference_success (service , mock_document_reference ):
168130 """Test successful document reference fetching"""
169131 document_key = "test-doc-id"
132+ service .table_name = "dev_LloydGeorgeReferenceMetadata"
170133 service .document_service .fetch_documents_from_table .return_value = [
171134 mock_document_reference
172135 ]
@@ -175,7 +138,7 @@ def test_fetch_preliminary_document_reference_success(service, mock_document_ref
175138
176139 assert result == mock_document_reference
177140 service .document_service .fetch_documents_from_table .assert_called_once_with (
178- table_name = MOCK_LG_TABLE_NAME ,
141+ table_name = "dev_LloydGeorgeReferenceMetadata" ,
179142 search_condition = document_key ,
180143 search_key = "ID" ,
181144 query_filter = PreliminaryStatus ,
@@ -400,10 +363,11 @@ def test_delete_file_from_staging_bucket_client_error(service):
400363
401364def test_update_dynamo_table_clean_scan_result (service , mock_document_reference ):
402365 """Test updating DynamoDB table with a clean scan result"""
366+ service .table_name = "dev_LloydGeorgeReferenceMetadata"
403367 service ._update_dynamo_table (mock_document_reference )
404368
405369 service .document_service .update_document .assert_called_once_with (
406- table_name = MOCK_LG_TABLE_NAME ,
370+ table_name = "dev_LloydGeorgeReferenceMetadata" ,
407371 document = mock_document_reference ,
408372 key_pair = None ,
409373 update_fields_name = {
@@ -472,13 +436,13 @@ def test_document_key_extraction_from_object_key_for_lg(
472436
473437 # Check first call (preliminary document)
474438 first_call = service .document_service .fetch_documents_from_table .call_args_list [0 ]
475- assert first_call [1 ]["table_name" ] == MOCK_LG_TABLE_NAME
439+ assert first_call [1 ]["table_name" ] == "dev_LloydGeorgeReferenceMetadata"
476440 assert first_call [1 ]["search_condition" ] == expected_document_key
477441 assert first_call [1 ]["search_key" ] == "ID"
478442
479443 # Check second call (existing final documents)
480444 second_call = service .document_service .fetch_documents_from_table .call_args_list [1 ]
481- assert second_call [1 ]["table_name" ] == MOCK_LG_TABLE_NAME
445+ assert second_call [1 ]["table_name" ] == "dev_LloydGeorgeReferenceMetadata"
482446 assert second_call [1 ]["index_name" ] == "S3FileKeyIndex"
483447 assert second_call [1 ]["search_condition" ] == mock_document_reference .s3_file_key
484448 assert second_call [1 ]["search_key" ] == "S3FileKey"
@@ -500,6 +464,7 @@ def test_finalize_and_supersede_with_transaction_with_existing_finals(
500464 existing_final_doc .doc_status = "final"
501465 existing_final_doc .version = "1"
502466
467+ service .table_name = "dev_LloydGeorgeReferenceMetadata"
503468 service .document_service .fetch_documents_from_table .return_value = [
504469 existing_final_doc
505470 ]
@@ -511,7 +476,7 @@ def test_finalize_and_supersede_with_transaction_with_existing_finals(
511476
512477 # Assert fetch was called with the correct parameters
513478 service .document_service .fetch_documents_from_table .assert_called_once_with (
514- table_name = MOCK_LG_TABLE_NAME ,
479+ table_name = "dev_LloydGeorgeReferenceMetadata" ,
515480 index_name = "S3FileKeyIndex" ,
516481 search_condition = new_doc .s3_file_key ,
517482 search_key = "S3FileKey" ,
@@ -523,7 +488,7 @@ def test_finalize_and_supersede_with_transaction_with_existing_finals(
523488
524489 # Assert the first call is for the new document with correct fields
525490 first_call = service .dynamo_service .build_update_transaction_item .call_args_list [0 ]
526- assert first_call [1 ]["table_name" ] == MOCK_LG_TABLE_NAME
491+ assert first_call [1 ]["table_name" ] == "dev_LloydGeorgeReferenceMetadata"
527492 assert first_call [1 ]["document_key" ] == {"ID" : new_doc .id }
528493 update_fields = first_call [1 ]["update_fields" ]
529494 assert "S3VersionID" in update_fields
@@ -534,7 +499,7 @@ def test_finalize_and_supersede_with_transaction_with_existing_finals(
534499
535500 # Assert the second call is for superseding the existing final document
536501 second_call = service .dynamo_service .build_update_transaction_item .call_args_list [1 ]
537- assert second_call [1 ]["table_name" ] == MOCK_LG_TABLE_NAME
502+ assert second_call [1 ]["table_name" ] == "dev_LloydGeorgeReferenceMetadata"
538503 assert second_call [1 ]["document_key" ] == {"ID" : existing_final_doc .id }
539504 assert second_call [1 ]["update_fields" ] == {
540505 "Status" : "superseded" ,
@@ -703,8 +668,10 @@ def test_process_preliminary_document_reference_exception_during_processing(
703668
704669
705670def test_get_infrastructure_for_document_key_non_pdm (service ):
671+ assert service .table_name == ""
706672 infra = service ._get_infrastructure_for_document_key (object_parts = ["1234" , "123" ])
707673 assert infra is None
674+ assert service .table_name == "dev_LloydGeorgeReferenceMetadata"
708675
709676
710677def test_get_infra_invalid_doc_type (monkeypatch , service ):
0 commit comments