From b3a6c0a2539d40088849f30090d022492125b5fd Mon Sep 17 00:00:00 2001 From: RobbieClarken Date: Mon, 14 May 2018 15:33:51 -0400 Subject: [PATCH] zerver/tests: Test currently_used_upload_space function. --- zerver/tests/test_upload.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/zerver/tests/test_upload.py b/zerver/tests/test_upload.py index 557869c3eb..33a07a5023 100644 --- a/zerver/tests/test_upload.py +++ b/zerver/tests/test_upload.py @@ -21,7 +21,8 @@ from zerver.lib.test_runner import slow from zerver.lib.upload import sanitize_name, S3UploadBackend, \ upload_message_file, delete_message_image, LocalUploadBackend, \ ZulipUploadBackend, MEDIUM_AVATAR_SIZE, resize_avatar, \ - resize_emoji, BadImageError, get_realm_for_filename + resize_emoji, BadImageError, get_realm_for_filename, \ + currently_used_upload_space import zerver.lib.upload from zerver.models import Attachment, get_user, \ get_old_unclaimed_attachments, Message, UserProfile, Stream, Realm, \ @@ -1190,3 +1191,20 @@ class SanitizeNameTests(TestCase): self.assertEqual(sanitize_name(u'snowman☃.txt'), u'snowman.txt') self.assertEqual(sanitize_name(u'테스트.txt'), u'테스트.txt') self.assertEqual(sanitize_name(u'~/."\`\?*"u0`000ssh/test.t**{}ar.gz'), u'.u0000sshtest.tar.gz') + + +class UploadSpaceTests(UploadSerializeMixin, ZulipTestCase): + def setUp(self) -> None: + self.realm = get_realm("zulip") + self.user_profile = self.example_user('hamlet') + + def test_currently_used_upload_space(self) -> None: + self.assertEqual(0, currently_used_upload_space(self.realm)) + + data = b'zulip!' + upload_message_file(u'dummy.txt', len(data), u'text/plain', data, self.user_profile) + self.assertEqual(len(data), currently_used_upload_space(self.realm)) + + data2 = b'more-data!' + upload_message_file(u'dummy2.txt', len(data2), u'text/plain', data2, self.user_profile) + self.assertEqual(len(data) + len(data2), currently_used_upload_space(self.realm))