From d8cb6904d26e199079344e012da73ab87248cde8 Mon Sep 17 00:00:00 2001 From: Joel Davies Date: Mon, 30 Sep 2024 09:44:54 +0000 Subject: [PATCH] Slight clean up #17 --- object_storage_api/stores/attachment.py | 1 - test/mock_data.py | 26 ++++++++++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/object_storage_api/stores/attachment.py b/object_storage_api/stores/attachment.py index d5a9974..1e97793 100644 --- a/object_storage_api/stores/attachment.py +++ b/object_storage_api/stores/attachment.py @@ -39,7 +39,6 @@ def create(self, attachment: AttachmentPostSchema) -> tuple[AttachmentIn, Attach object_key = f"attachments/{attachment.entity_id}/{attachment_id}" logger.info("Generating a presigned URL for uploading the attachment") - # TODO: Handle failure here before creating the AttachmentPostUploadInfoSchema? presigned_post_response = s3_client.generate_presigned_post( Bucket=object_storage_config.bucket_name.get_secret_value(), Key=object_key, diff --git a/test/mock_data.py b/test/mock_data.py index 2b9b415..143f1fd 100644 --- a/test/mock_data.py +++ b/test/mock_data.py @@ -20,6 +20,21 @@ # Used for _GET_DATA's as when comparing these will not be possible to know at runtime CREATED_MODIFIED_GET_DATA_EXPECTED = {"created_time": ANY, "modified_time": ANY} +# Used for _POST_RESPONSE_DATA's as when comparing most of these are not possible to know at runtime arguably we dont +# need to put the fields in but it ensures we capture potential changes to how boto3 functions +ATTACHMENT_UPLOAD_INFO_POST_RESPONSE_DATA_EXPECTED = { + "upload_info": { + "url": ANY, + "fields": { + "AWSAccessKeyId": ANY, + "Content-Type": "multipart/form-data", + "key": ANY, + "policy": ANY, + "signature": ANY, + }, + } +} + # ---------------------------- ATTACHMENTS ----------------------------- # Required values only @@ -29,15 +44,11 @@ "file_name": "report.txt", } -# TODO: Create UPLOAD_INFO structure for these? ATTACHMENT_POST_RESPONSE_DATA_REQUIRED_VALUES_ONLY = { **ATTACHMENT_POST_DATA_REQUIRED_VALUES_ONLY, **CREATED_MODIFIED_GET_DATA_EXPECTED, + **ATTACHMENT_UPLOAD_INFO_POST_RESPONSE_DATA_EXPECTED, "id": ANY, - "upload_info": { - "url": ANY, - "fields": ANY, - }, "title": None, "description": None, } @@ -60,9 +71,6 @@ ATTACHMENT_POST_RESPONSE_DATA_ALL_VALUES = { **ATTACHMENT_POST_DATA_ALL_VALUES, **CREATED_MODIFIED_GET_DATA_EXPECTED, + **ATTACHMENT_UPLOAD_INFO_POST_RESPONSE_DATA_EXPECTED, "id": ANY, - "upload_info": { - "url": ANY, - "fields": ANY, - }, }