Skip to content

Commit 800d6bb

Browse files
[PRMT-71] - removed commented code
1 parent 14da9a4 commit 800d6bb

File tree

2 files changed

+2
-115
lines changed

2 files changed

+2
-115
lines changed

lambdas/services/generate_document_manifest_zip_service.py

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,15 @@ class DocumentManifestZipService:
2020
def __init__(self, zip_trace: DocumentManifestZipTrace):
2121
self.s3_service = S3Service()
2222
self.dynamo_service = DynamoDBService()
23-
# self.temp_output_dir = tempfile.mkdtemp()
24-
# self.temp_downloads_dir = tempfile.mkdtemp()
2523
self.zip_trace_object = zip_trace
2624
self.zip_output_bucket = os.environ["ZIPPED_STORE_BUCKET_NAME"]
2725
self.zip_trace_table = os.environ["ZIPPED_STORE_DYNAMODB_NAME"]
2826
self.zip_file_name = f"patient-record-{zip_trace.job_id}.zip"
29-
# self.zip_file_path = os.path.join(self.temp_output_dir, self.zip_file_name)
3027

3128
def handle_zip_request(self):
3229
self.update_processing_status()
33-
# self.download_documents_to_be_zipped()
34-
# Stream and zip the documents in memory
3530
zip_buffer = self.stream_zip_documents()
36-
# Upload the zip file to S3
3731
self.upload_zip_file(zip_buffer)
38-
39-
# self.zip_files()
40-
# self.upload_zip_file()
41-
# self.cleanup_temp_files()
4232
self.update_dynamo_with_fields({"job_status", "zip_file_location"})
4333

4434
def stream_zip_documents(self) -> io.BytesIO:
@@ -87,27 +77,6 @@ def stream_zip_documents(self) -> io.BytesIO:
8777
status_code=500, error=LambdaError.ZipCreationError
8878
)
8979

90-
# def download_documents_to_be_zipped(self):
91-
# logger.info("Downloading documents to be zipped")
92-
# documents = self.zip_trace_object.files_to_download
93-
# for document_location, document_name in documents.items():
94-
# self.download_file_from_s3(document_name, document_location)
95-
#
96-
# def download_file_from_s3(self, document_name: str, document_location: str):
97-
# download_path = os.path.join(self.temp_downloads_dir, document_name)
98-
# file_bucket, file_key = self.get_file_bucket_and_key(document_location)
99-
# try:
100-
# self.s3_service.download_file(file_bucket, file_key, download_path)
101-
# except ClientError as e:
102-
# self.update_failed_status()
103-
# msg = f"{file_key} may reference missing file in s3 bucket: {file_bucket}"
104-
# logger.error(
105-
# f"{LambdaError.ZipServiceClientError.to_str()} {msg + str(e)}",
106-
# {"Result": "Failed to create document manifest"},
107-
# )
108-
# raise GenerateManifestZipException(
109-
# status_code=500, error=LambdaError.ZipServiceClientError
110-
11180
def get_file_bucket_and_key(self, file_location: str):
11281
try:
11382
file_bucket, file_key = file_location.replace("s3://", "").split("/", 1)
@@ -140,36 +109,6 @@ def upload_zip_file(self, zip_buffer: io.BytesIO):
140109

141110
self.zip_trace_object.job_status = TraceStatus.COMPLETED
142111

143-
# def upload_zip_file(self):
144-
# logger.info("Uploading zip file to s3")
145-
# self.zip_trace_object.zip_file_location = (
146-
# f"s3://{self.zip_output_bucket}/{self.zip_file_name}"
147-
# )
148-
#
149-
# try:
150-
# self.s3_service.upload_file(
151-
# file_name=self.zip_file_path,
152-
# s3_bucket_name=self.zip_output_bucket,
153-
# file_key=f"{self.zip_file_name}",
154-
# )
155-
# except ClientError as e:
156-
# self.update_failed_status()
157-
# logger.error(e, {"Result": "Failed to create document manifest"})
158-
# raise GenerateManifestZipException(
159-
# status_code=500, error=LambdaError.ZipServiceClientError
160-
# )
161-
#
162-
# self.zip_trace_object.job_status = TraceStatus.COMPLETED
163-
164-
# def zip_files(self):
165-
# logger.info("Creating zip from files")
166-
# with zipfile.ZipFile(self.zip_file_path, "w", zipfile.ZIP_DEFLATED) as zipf:
167-
# for root, _, files in os.walk(self.temp_downloads_dir):
168-
# for file in files:
169-
# file_path = os.path.join(root, file)
170-
# arc_name = os.path.relpath(file_path, self.temp_downloads_dir)
171-
# zipf.write(file_path, arc_name)
172-
173112
def update_dynamo_with_fields(self, fields: set):
174113
logger.info("Writing zip trace to db")
175114
self.dynamo_service.update_item(
@@ -187,7 +126,3 @@ def update_processing_status(self):
187126
def update_failed_status(self):
188127
self.zip_trace_object.job_status = TraceStatus.FAILED
189128
self.update_dynamo_with_fields({"job_status"})
190-
191-
# def cleanup_temp_files(self):
192-
# shutil.rmtree(self.temp_downloads_dir)
193-
# shutil.rmtree(self.temp_output_dir)

lambdas/tests/unit/services/test_generate_document_manifest_zip_service.py

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
TEST_UUID,
2121
)
2222

23-
# from unittest.mock import call
24-
25-
2623
TEST_TIME = "2024-07-02T15:00:00.000000Z"
2724
TEST_DYNAMO_RESPONSE = {
2825
"ID": TEST_UUID,
@@ -48,11 +45,8 @@ def mock_service(mocker, set_env, mock_temp_folder):
4845

4946

5047
@pytest.fixture
51-
def mock_s3_service(mock_service, mocker):
52-
mock_s3_service = mock_service.s3_service
53-
# mocker.patch.object(mock_s3_service, "download_file")
54-
# mocker.patch.object(mock_s3_service, "upload_file")
55-
yield mock_s3_service
48+
def mock_s3_service(mock_service):
49+
yield mock_service.s3_service
5650

5751

5852
@pytest.fixture
@@ -77,48 +71,6 @@ def __exit__(self, exc_type, exc_val, exc_tb):
7771
return _stream_context_manager
7872

7973

80-
# def test_download_documents_to_be_zipped(mocker, mock_service):
81-
# mock_service.download_file_from_s3 = mocker.MagicMock()
82-
# mock_service.download_documents_to_be_zipped()
83-
#
84-
# calls = [
85-
# call(TEST_FILE_NAME, TEST_DOCUMENT_LOCATION),
86-
# call(f"{TEST_FILE_KEY}2", f"{TEST_DOCUMENT_LOCATION}2"),
87-
# ]
88-
#
89-
# mock_service.download_file_from_s3.assert_has_calls(calls)
90-
91-
92-
# def test_download_file_from_s3(mock_service, mock_s3_service):
93-
# mock_service.download_file_from_s3(TEST_FILE_NAME, TEST_DOCUMENT_LOCATION)
94-
#
95-
# mock_s3_service.download_file.assert_called_once_with(
96-
# MOCK_BUCKET,
97-
# TEST_FILE_KEY,
98-
# f"{mock_service.temp_downloads_dir}/{TEST_FILE_NAME}",
99-
# )
100-
# assert mock_service.zip_trace_object.job_status != TraceStatus.FAILED
101-
#
102-
#
103-
# def test_download_file_from_s3_raises_exception(mock_service, mock_s3_service):
104-
# mock_s3_service.download_file.side_effect = ClientError(
105-
# {"Error": {"Code": "500", "Message": "test error"}}, "testing"
106-
# )
107-
#
108-
# with pytest.raises(GenerateManifestZipException) as e:
109-
# mock_service.download_file_from_s3(TEST_FILE_NAME, TEST_DOCUMENT_LOCATION)
110-
#
111-
# mock_s3_service.download_file.assert_called_once_with(
112-
# MOCK_BUCKET,
113-
# TEST_FILE_KEY,
114-
# f"{mock_service.temp_downloads_dir}/{TEST_FILE_NAME}",
115-
# )
116-
# assert e.value == GenerateManifestZipException(
117-
# 500, LambdaError.ZipServiceClientError
118-
# )
119-
# assert mock_service.zip_trace_object.job_status == TraceStatus.FAILED
120-
121-
12274
def test_get_file_bucket_and_key_returns_correct_items(mock_service):
12375
zip_trace_object = mock_service.zip_trace_object
12476
documents = zip_trace_object.files_to_download

0 commit comments

Comments
 (0)