upload: Start storing content-type for new uploads.

This commit is contained in:
Alex Vandiver 2024-06-20 16:54:49 +00:00 committed by Tim Abbott
parent 45afdc2d35
commit 0a296b2a6e
4 changed files with 27 additions and 8 deletions

View File

@ -204,7 +204,12 @@ class AnalyticsTestCase(ZulipTestCase):
return Message.objects.create(**kwargs)
def create_attachment(
self, user_profile: UserProfile, filename: str, size: int, create_time: datetime
self,
user_profile: UserProfile,
filename: str,
size: int,
create_time: datetime,
content_type: str,
) -> Attachment:
return Attachment.objects.create(
file_name=filename,
@ -213,6 +218,7 @@ class AnalyticsTestCase(ZulipTestCase):
realm=user_profile.realm,
size=size,
create_time=create_time,
content_type=content_type,
)
# kwargs should only ever be a UserProfile or Stream.
@ -551,9 +557,9 @@ class TestCountStats(AnalyticsTestCase):
user2 = self.create_user()
user_second_realm = self.create_user(realm=self.second_realm)
self.create_attachment(user1, "file1", 100, self.TIME_LAST_HOUR)
attachment2 = self.create_attachment(user2, "file2", 200, self.TIME_LAST_HOUR)
self.create_attachment(user_second_realm, "file3", 10, self.TIME_LAST_HOUR)
self.create_attachment(user1, "file1", 100, self.TIME_LAST_HOUR, "text/plain")
attachment2 = self.create_attachment(user2, "file2", 200, self.TIME_LAST_HOUR, "text/plain")
self.create_attachment(user_second_realm, "file3", 10, self.TIME_LAST_HOUR, "text/plain")
do_fill_count_stat_at_hour(stat, self.TIME_ZERO)

View File

@ -41,7 +41,12 @@ def check_upload_within_quota(realm: Realm, uploaded_file_size: int) -> None:
def create_attachment(
file_name: str, path_id: str, user_profile: UserProfile, realm: Realm, file_size: int
file_name: str,
path_id: str,
user_profile: UserProfile,
realm: Realm,
file_size: int,
content_type: str,
) -> None:
assert (user_profile.realm_id == realm.id) or is_cross_realm_bot_email(
user_profile.delivery_email
@ -52,6 +57,7 @@ def create_attachment(
owner=user_profile,
realm=realm,
size=file_size,
content_type=content_type,
)
from zerver.actions.uploads import notify_attachment_update
@ -143,6 +149,7 @@ def upload_message_attachment(
user_profile,
target_realm,
uploaded_file_size,
content_type,
)
return f"/user_uploads/{path_id}"

View File

@ -4526,7 +4526,9 @@ class MessageHasKeywordsTest(ZulipTestCase):
]
for file_name, path_id, size in dummy_files:
create_attachment(file_name, path_id, user_profile, user_profile.realm, size)
create_attachment(
file_name, path_id, user_profile, user_profile.realm, size, "text/plain"
)
# return path ids
return [x[1] for x in dummy_files]

View File

@ -190,7 +190,9 @@ class ArchiveMessagesTestingBase(RetentionTestingBase):
]
for file_name, path_id, size in dummy_files:
create_attachment(file_name, path_id, user_profile, user_profile.realm, size)
create_attachment(
file_name, path_id, user_profile, user_profile.realm, size, "text/plain"
)
self.subscribe(user_profile, "Denmark")
body = (
@ -603,7 +605,9 @@ class MoveMessageToArchiveBase(RetentionTestingBase):
]
user_profile = self.example_user("hamlet")
for file_name, path_id, size in dummy_files:
create_attachment(file_name, path_id, user_profile, user_profile.realm, size)
create_attachment(
file_name, path_id, user_profile, user_profile.realm, size, "text/plain"
)
def _assert_archive_empty(self) -> None:
self.assertFalse(ArchivedUserMessage.objects.exists())