upload: Content-type is always defined.

This commit is contained in:
Alex Vandiver 2024-06-20 16:19:25 +00:00 committed by Tim Abbott
parent 17fb23746f
commit 2eaf098c5d
5 changed files with 4 additions and 16 deletions

View File

@ -119,7 +119,7 @@ def sanitize_name(value: str) -> str:
def upload_message_attachment( def upload_message_attachment(
uploaded_file_name: str, uploaded_file_name: str,
uploaded_file_size: int, uploaded_file_size: int,
content_type: Optional[str], content_type: str,
file_data: bytes, file_data: bytes,
user_profile: UserProfile, user_profile: UserProfile,
target_realm: Optional[Realm] = None, target_realm: Optional[Realm] = None,

View File

@ -38,7 +38,7 @@ class ZulipUploadBackend:
self, self,
path_id: str, path_id: str,
uploaded_file_size: int, uploaded_file_size: int,
content_type: Optional[str], content_type: str,
file_data: bytes, file_data: bytes,
user_profile: UserProfile, user_profile: UserProfile,
target_realm: Realm, target_realm: Realm,

View File

@ -81,7 +81,7 @@ class LocalUploadBackend(ZulipUploadBackend):
self, self,
path_id: str, path_id: str,
uploaded_file_size: int, uploaded_file_size: int,
content_type: Optional[str], content_type: str,
file_data: bytes, file_data: bytes,
user_profile: UserProfile, user_profile: UserProfile,
target_realm: Realm, target_realm: Realm,

View File

@ -205,7 +205,7 @@ class S3UploadBackend(ZulipUploadBackend):
self, self,
path_id: str, path_id: str,
uploaded_file_size: int, uploaded_file_size: int,
content_type: Optional[str], content_type: str,
file_data: bytes, file_data: bytes,
user_profile: UserProfile, user_profile: UserProfile,
target_realm: Realm, target_realm: Realm,

View File

@ -95,18 +95,6 @@ class S3Test(ZulipTestCase):
# Ensure the correct realm id of the target realm is used instead of the bot's realm. # Ensure the correct realm id of the target realm is used instead of the bot's realm.
self.assertTrue(url.startswith(f"/user_uploads/{zulip_realm.id}/")) self.assertTrue(url.startswith(f"/user_uploads/{zulip_realm.id}/"))
@use_s3_backend
def test_upload_message_attachment_s3_with_undefined_content_type(self) -> None:
bucket = create_s3_buckets(settings.S3_AUTH_UPLOADS_BUCKET)[0]
user_profile = self.example_user("hamlet")
url = upload_message_attachment("dummy.txt", len(b"zulip!"), None, b"zulip!", user_profile)
path_id = re.sub(r"/user_uploads/", "", url)
self.assertEqual(b"zulip!", bucket.Object(path_id).get()["Body"].read())
uploaded_file = Attachment.objects.get(owner=user_profile, path_id=path_id)
self.assert_length(b"zulip!", uploaded_file.size)
@use_s3_backend @use_s3_backend
def test_delete_message_attachment(self) -> None: def test_delete_message_attachment(self) -> None:
bucket = create_s3_buckets(settings.S3_AUTH_UPLOADS_BUCKET)[0] bucket = create_s3_buckets(settings.S3_AUTH_UPLOADS_BUCKET)[0]