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: Use read_test_image_file helper.

Steve Howell53ffb8152fee
diff --git a/zerver/lib/test_helpers.py b/zerver/lib/test_helpers.py
index a5487012078..0e1ab0d9c72 100644
--- a/zerver/lib/test_helpers.py
+++ b/zerver/lib/test_helpers.py
@@ -205,6 +205,11 @@ def get_test_image_file(filename: str) -> IO[bytes]:
return open(os.path.join(test_avatar_dir, filename), "rb")
+def read_test_image_file(filename: str) -> bytes:
+ with get_test_image_file(filename) as img_file:
+ return img_file.read()
+
+
def avatar_disk_path(
user_profile: UserProfile, medium: bool = False, original: bool = False
) -> str:
diff --git a/zerver/tests/test_import_export.py b/zerver/tests/test_import_export.py
index 33f6244f34f..8823b814406 100644
--- a/zerver/tests/test_import_export.py
+++ b/zerver/tests/test_import_export.py
@@ -42,6 +42,7 @@ from zerver.lib.test_helpers import (
get_test_image_file,
most_recent_message,
most_recent_usermessage,
+ read_test_image_file,
use_s3_backend,
)
from zerver.lib.topic_mutes import add_topic_mute
@@ -194,8 +195,7 @@ class RealmImportExportTest(ZulipTestCase):
upload.upload_backend.upload_realm_logo_image(img_file, user_profile, night=True)
do_change_logo_source(realm, Realm.LOGO_UPLOADED, True, acting_user=user_profile)
- with get_test_image_file("img.png") as img_file:
- test_image = img_file.read()
+ test_image = read_test_image_file("img.png")
user_profile.avatar_source = "U"
user_profile.save()
@@ -1208,8 +1208,7 @@ class RealmImportExportTest(ZulipTestCase):
upload_path = upload.upload_backend.realm_avatar_and_logo_path(imported_realm)
full_upload_path = os.path.join(settings.LOCAL_UPLOADS_DIR, upload_path)
- with get_test_image_file("img.png") as f:
- test_image_data = f.read()
+ test_image_data = read_test_image_file("img.png")
self.assertIsNotNone(test_image_data)
with open(os.path.join(full_upload_path, "icon.original"), "rb") as f:
@@ -1242,8 +1241,7 @@ class RealmImportExportTest(ZulipTestCase):
do_import_realm(os.path.join(settings.TEST_WORKER_DIR, "test-export"), "test-zulip")
imported_realm = Realm.objects.get(string_id="test-zulip")
- with get_test_image_file("img.png") as f:
- test_image_data = f.read()
+ test_image_data = read_test_image_file("img.png")
# Test attachments
uploaded_file = Attachment.objects.get(realm=imported_realm)