diff --git a/zerver/lib/upload/__init__.py b/zerver/lib/upload/__init__.py index a7c701c0c7..1d5dcc1e4f 100644 --- a/zerver/lib/upload/__init__.py +++ b/zerver/lib/upload/__init__.py @@ -44,7 +44,7 @@ def create_attachment( file_name: str, path_id: str, content_type: str, - file_size: int, + file_data: bytes, user_profile: UserProfile, realm: Realm, ) -> None: @@ -56,7 +56,7 @@ def create_attachment( path_id=path_id, owner=user_profile, realm=realm, - size=file_size, + size=len(file_data), content_type=content_type, ) from zerver.actions.uploads import notify_attachment_update @@ -144,7 +144,7 @@ def upload_message_attachment( uploaded_file_name, path_id, content_type, - len(file_data), + file_data, user_profile, target_realm, ) diff --git a/zerver/tests/test_message_fetch.py b/zerver/tests/test_message_fetch.py index f29492cee1..f2c9967ad3 100644 --- a/zerver/tests/test_message_fetch.py +++ b/zerver/tests/test_message_fetch.py @@ -4517,17 +4517,16 @@ class MessageHasKeywordsTest(ZulipTestCase): """Test for keywords like has_link, has_image, has_attachment.""" def setup_dummy_attachments(self, user_profile: UserProfile) -> List[str]: - sample_size = 10 realm_id = user_profile.realm_id dummy_files = [ - ("zulip.txt", f"{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/zulip.txt", sample_size), - ("temp_file.py", f"{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/temp_file.py", sample_size), - ("abc.py", f"{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/abc.py", sample_size), + ("zulip.txt", f"{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/zulip.txt"), + ("temp_file.py", f"{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/temp_file.py"), + ("abc.py", f"{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/abc.py"), ] - for file_name, path_id, size in dummy_files: + for file_name, path_id in dummy_files: create_attachment( - file_name, path_id, "text/plain", size, user_profile, user_profile.realm + file_name, path_id, "text/plain", b"1234567890", user_profile, user_profile.realm ) # return path ids diff --git a/zerver/tests/test_retention.py b/zerver/tests/test_retention.py index b2b535b7f9..edbf8ae3c3 100644 --- a/zerver/tests/test_retention.py +++ b/zerver/tests/test_retention.py @@ -180,18 +180,17 @@ class ArchiveMessagesTestingBase(RetentionTestingBase): def _send_messages_with_attachments(self) -> Dict[str, int]: user_profile = self.example_user("hamlet") - sample_size = 10 host = user_profile.realm.host realm_id = get_realm("zulip").id dummy_files = [ - ("zulip.txt", f"{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/zulip.txt", sample_size), - ("temp_file.py", f"{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/temp_file.py", sample_size), - ("abc.py", f"{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/abc.py", sample_size), + ("zulip.txt", f"{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/zulip.txt"), + ("temp_file.py", f"{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/temp_file.py"), + ("abc.py", f"{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/abc.py"), ] - for file_name, path_id, size in dummy_files: + for file_name, path_id in dummy_files: create_attachment( - file_name, path_id, "text/plain", size, user_profile, user_profile.realm + file_name, path_id, "text/plain", b"1234567890", user_profile, user_profile.realm ) self.subscribe(user_profile, "Denmark") @@ -594,19 +593,18 @@ class MoveMessageToArchiveBase(RetentionTestingBase): self.recipient = self.example_user("cordelia") def _create_attachments(self) -> None: - sample_size = 10 realm_id = get_realm("zulip").id dummy_files = [ - ("zulip.txt", f"{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/zulip.txt", sample_size), - ("temp_file.py", f"{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/temp_file.py", sample_size), - ("abc.py", f"{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/abc.py", sample_size), - ("hello.txt", f"{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/hello.txt", sample_size), - ("new.py", f"{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/new.py", sample_size), + ("zulip.txt", f"{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/zulip.txt"), + ("temp_file.py", f"{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/temp_file.py"), + ("abc.py", f"{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/abc.py"), + ("hello.txt", f"{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/hello.txt"), + ("new.py", f"{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/new.py"), ] user_profile = self.example_user("hamlet") - for file_name, path_id, size in dummy_files: + for file_name, path_id in dummy_files: create_attachment( - file_name, path_id, "text/plain", size, user_profile, user_profile.realm + file_name, path_id, "text/plain", b"1234567890", user_profile, user_profile.realm ) def _assert_archive_empty(self) -> None: