diff --git a/lambdas/models/document_reference.py b/lambdas/models/document_reference.py index 902837cc2..ff1b164d2 100644 --- a/lambdas/models/document_reference.py +++ b/lambdas/models/document_reference.py @@ -45,7 +45,6 @@ class DocumentReference(BaseModel): uploaded: bool uploading: bool last_updated: int - # file_size: int def get_file_name_path(self): return pathlib.Path(self.file_name) diff --git a/lambdas/services/document_reference_search_service.py b/lambdas/services/document_reference_search_service.py index 8f1f4c2bd..37361365d 100644 --- a/lambdas/services/document_reference_search_service.py +++ b/lambdas/services/document_reference_search_service.py @@ -49,10 +49,21 @@ def get_document_references(self, nhs_number: str): 423, LambdaError.UploadInProgressError ) results.extend( - document.model_dump( - include={"file_name", "created", "virus_scanner_result", "id"}, - by_alias=True, - ) + { + **document.model_dump( + include={ + "file_name", + "created", + "virus_scanner_result", + "id", + }, + by_alias=True, + ), + "fileSize": self.s3_service.get_file_size( + bucket_name=document.get_file_bucket(), + object_key=document.get_file_key(), + ), + } for document in documents ) return results diff --git a/lambdas/tests/unit/services/test_document_reference_search_service.py b/lambdas/tests/unit/services/test_document_reference_search_service.py index c55396133..e64dbf213 100644 --- a/lambdas/tests/unit/services/test_document_reference_search_service.py +++ b/lambdas/tests/unit/services/test_document_reference_search_service.py @@ -12,18 +12,22 @@ DocumentReference.model_validate(MOCK_SEARCH_RESPONSE["Items"][0]) ] +MOCK_FILE_SIZE = 24000 + EXPECTED_RESPONSE = { "created": "2024-01-01T12:00:00.000Z", "fileName": "document.csv", "virusScannerResult": "Clean", "ID": "3d8683b9-1665-40d2-8499-6e8302d507ff", + "fileSize": MOCK_FILE_SIZE, } @pytest.fixture def patched_service(mocker, set_env): service = DocumentReferenceSearchService() - mocker.patch.object(service, "s3_service") + mock_s3_service = mocker.patch.object(service, "s3_service") + mocker.patch.object(mock_s3_service, "get_file_size", return_value=MOCK_FILE_SIZE) mocker.patch.object(service, "dynamo_service") mocker.patch.object(service, "fetch_documents_from_table_with_filter") mocker.patch.object(service, "is_upload_in_process", return_value=False) @@ -83,10 +87,10 @@ def test_get_document_references_dynamo_return_successful_response_single_table( patched_service, monkeypatch ): monkeypatch.setenv("DYNAMODB_TABLE_LIST", json.dumps(["test_table"])) - patched_service.fetch_documents_from_table_with_filter.return_value = ( MOCK_DOCUMENT_REFERENCE ) + expected_results = [EXPECTED_RESPONSE] actual = patched_service.get_document_references("1111111111")