Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

tests: Update ZulipTestCase.tearDown to remove local uploads.

Lauryn Menard7b225245c0b8
diff --git a/zerver/lib/test_classes.py b/zerver/lib/test_classes.py
index 12b691b2c57..6fb6068becf 100644
--- a/zerver/lib/test_classes.py
+++ b/zerver/lib/test_classes.py
@@ -159,6 +159,11 @@ class ZulipTestCase(TestCase):
flush_per_request_caches()
translation.activate(settings.LANGUAGE_CODE)
+ # Clean up local uploads directory after tests:
+ assert settings.LOCAL_UPLOADS_DIR is not None
+ if os.path.exists(settings.LOCAL_UPLOADS_DIR):
+ shutil.rmtree(settings.LOCAL_UPLOADS_DIR)
+
# Clean up after using fakeldap in LDAP tests:
if hasattr(self, "mock_ldap") and hasattr(self, "mock_initialize"):
if self.mock_ldap is not None:
diff --git a/zerver/tests/test_upload.py b/zerver/tests/test_upload.py
index 22216739ecf..4629774fedb 100644
--- a/zerver/tests/test_upload.py
+++ b/zerver/tests/test_upload.py
@@ -2,7 +2,6 @@ import datetime
import io
import os
import re
-import shutil
import time
import urllib
from io import StringIO
@@ -67,12 +66,6 @@ from zerver.models import (
)
-def destroy_uploads() -> None:
- assert settings.LOCAL_UPLOADS_DIR is not None
- if os.path.exists(settings.LOCAL_UPLOADS_DIR):
- shutil.rmtree(settings.LOCAL_UPLOADS_DIR)
-
-
class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
def test_rest_endpoint(self) -> None:
"""
@@ -347,7 +340,8 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
result = self.client_post("/json/user_uploads", {"file": fp})
response_dict = self.assert_json_success(result)
- destroy_uploads()
+ assert settings.LOCAL_UPLOADS_DIR is not None
+ self.rm_tree(settings.LOCAL_UPLOADS_DIR)
response = self.client_get(response_dict["uri"])
self.assertEqual(response.status_code, 404)
@@ -960,10 +954,6 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
check_xsend_links("áéБД.pdf", "%C3%A1%C3%A9%D0%91%D0%94.pdf")
check_xsend_links("zulip", "zulip", 'filename="zulip"')
- def tearDown(self) -> None:
- destroy_uploads()
- super().tearDown()
-
class AvatarTest(UploadSerializeMixin, ZulipTestCase):
def test_get_avatar_field(self) -> None:
@@ -1406,10 +1396,6 @@ class AvatarTest(UploadSerializeMixin, ZulipTestCase):
result = self.client_post("/json/users/me/avatar", {"file": fp})
self.assert_json_error(result, "Uploaded file is larger than the allowed limit of 0 MiB")
- def tearDown(self) -> None:
- destroy_uploads()
- super().tearDown()
-
class EmojiTest(UploadSerializeMixin, ZulipTestCase):
# While testing GIF resizing, we can't test if the final GIF has the same
@@ -1475,10 +1461,6 @@ class EmojiTest(UploadSerializeMixin, ZulipTestCase):
self.assertFalse(is_animated)
assert no_still_data is None
- def tearDown(self) -> None:
- destroy_uploads()
- super().tearDown()
-
class RealmIconTest(UploadSerializeMixin, ZulipTestCase):
def test_multiple_upload_failure(self) -> None:
@@ -1617,10 +1599,6 @@ class RealmIconTest(UploadSerializeMixin, ZulipTestCase):
result = self.client_post("/json/realm/icon", {"file": fp})
self.assert_json_error(result, "Uploaded file is larger than the allowed limit of 0 MiB")
- def tearDown(self) -> None:
- destroy_uploads()
- super().tearDown()
-
class RealmLogoTest(UploadSerializeMixin, ZulipTestCase):
night = False
@@ -1820,10 +1798,6 @@ class RealmLogoTest(UploadSerializeMixin, ZulipTestCase):
)
self.assert_json_error(result, "Uploaded file is larger than the allowed limit of 0 MiB")
- def tearDown(self) -> None:
- destroy_uploads()
- super().tearDown()
-
class RealmNightLogoTest(RealmLogoTest):
# Run the same tests as for RealmLogoTest, just with dark theme enabled
diff --git a/zerver/tests/test_upload_local.py b/zerver/tests/test_upload_local.py
index 83794454967..2272cb8dd99 100644
--- a/zerver/tests/test_upload_local.py
+++ b/zerver/tests/test_upload_local.py
@@ -1,6 +1,5 @@
import os
import re
-import shutil
import urllib
from io import StringIO
from urllib.parse import urlparse
@@ -39,12 +38,6 @@ from zerver.models import (
)
-def destroy_uploads() -> None:
- assert settings.LOCAL_UPLOADS_DIR is not None
- if os.path.exists(settings.LOCAL_UPLOADS_DIR):
- shutil.rmtree(settings.LOCAL_UPLOADS_DIR)
-
-
class LocalStorageTest(UploadSerializeMixin, ZulipTestCase):
def test_upload_message_attachment(self) -> None:
user_profile = self.example_user("hamlet")
@@ -269,7 +262,3 @@ class LocalStorageTest(UploadSerializeMixin, ZulipTestCase):
)
path_id = urllib.parse.urlparse(uri).path
self.assertEqual(delete_export_tarball(path_id), path_id)
-
- def tearDown(self) -> None:
- destroy_uploads()
- super().tearDown()