Skip to content

Commit a15a2bc

Browse files
committed
add move_file
1 parent 2929db1 commit a15a2bc

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

lambdas/filenameprocessor/src/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
ODS_CODE_TO_SUPPLIER_SYSTEM_HASH_KEY = "ods_code_to_supplier"
2424
EXTENDED_ATTRIBUTES_FILE_PREFIX = "Vaccination_Extended_Attributes"
2525
EXTENDED_ATTRIBUTES_VACC_TYPE = "COVID"
26-
DPS_DESTINATION_PREFIX = "dps_destination/"
26+
DPS_DESTINATION_PREFIX = "dps_destination"
2727
VALID_EA_VERSIONS = "V1_5"
2828
ERROR_TYPE_TO_STATUS_CODE_MAP = {
2929
VaccineTypePermissionsError: 403,

lambdas/filenameprocessor/src/file_name_processor.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
from audit_table import upsert_audit_table
1313
from common.aws_s3_utils import (
1414
copy_file_to_external_bucket,
15-
delete_file,
1615
move_file,
1716
)
1817
from common.clients import STREAM_NAME, get_s3_client, logger
1918
from common.log_decorator import logging_decorator
2019
from common.models.errors import UnhandledAuditTableError
2120
from constants import (
2221
DPS_DESTINATION_BUCKET_NAME,
22+
DPS_DESTINATION_PREFIX,
2323
ERROR_TYPE_TO_STATUS_CODE_MAP,
2424
EXPECTED_BUCKET_OWNER_ACCOUNT,
2525
EXTENDED_ATTRIBUTES_FILE_PREFIX,
@@ -262,7 +262,7 @@ def handle_extended_attributes_file(
262262
)
263263

264264
# TODO: agree the prefix with DPS
265-
dest_file_key = f"dps_destination/{file_key}"
265+
dest_file_key = f"{DPS_DESTINATION_PREFIX}/{file_key}"
266266
copy_file_to_external_bucket(
267267
bucket_name,
268268
file_key,
@@ -271,7 +271,8 @@ def handle_extended_attributes_file(
271271
EXPECTED_BUCKET_OWNER_ACCOUNT,
272272
EXPECTED_BUCKET_OWNER_ACCOUNT,
273273
)
274-
delete_file(bucket_name, dest_file_key, EXPECTED_BUCKET_OWNER_ACCOUNT)
274+
275+
move_file(bucket_name, file_key, f"extended-attributes-archive/{file_key}")
275276

276277
upsert_audit_table(
277278
message_id,

lambdas/filenameprocessor/tests/test_lambda_handler.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,12 @@ def test_lambda_handler_extended_attributes_success(self, mock_get_redis_client)
284284
),
285285
),
286286
patch(
287-
"file_name_processor.delete_file",
288-
side_effect=lambda src_bucket, key, exp_owner: (
289-
s3_client.delete_object(
290-
Bucket=BucketNames.SOURCE,
291-
Key=key,
287+
"file_name_processor.move_file",
288+
side_effect=lambda source_bucket, source_key, destination_key: (
289+
s3_client.put_object(
290+
Bucket=source_bucket,
291+
Key=destination_key,
292+
Body=s3_client.get_object(Bucket=source_bucket, Key=source_key)["Body"].read(),
292293
),
293294
),
294295
),
@@ -308,6 +309,7 @@ def test_lambda_handler_extended_attributes_success(self, mock_get_redis_client)
308309
self.assertEqual(item[AuditTableKeys.TIMESTAMP]["S"], test_cases[0].created_at_formatted_string)
309310
self.assertEqual(item[AuditTableKeys.EXPIRES_AT]["N"], str(test_cases[0].expires_at))
310311
# File should be moved to destination/
312+
# The implementation constructs the destination key with a double slash. Reflect that here.
311313
dest_key = f"dps_destination/{test_cases[0].file_key}"
312314
print(f" destination file is at {s3_client.list_objects(Bucket=BucketNames.DESTINATION)}")
313315
retrieved = s3_client.get_object(Bucket=BucketNames.DESTINATION, Key=dest_key)
@@ -350,6 +352,17 @@ def test_lambda_handler_extended_attributes_failure(self, mock_get_redis_client)
350352
with (
351353
patch("file_name_processor.uuid4", return_value=test_cases[0].message_id),
352354
patch("file_name_processor.copy_file_to_external_bucket", side_effect=Exception("Test ClientError")),
355+
patch(
356+
"file_name_processor.move_file",
357+
side_effect=lambda bucket, key, dst_key: (
358+
s3_client.put_object(
359+
Bucket=bucket,
360+
Key=dst_key,
361+
Body=s3_client.get_object(Bucket=bucket, Key=key)["Body"].read(),
362+
),
363+
s3_client.delete_object(Bucket=bucket, Key=key),
364+
),
365+
),
353366
):
354367
lambda_handler(self.make_event([self.make_record(test_cases[0].file_key)]), None)
355368

0 commit comments

Comments
 (0)