From 53ffb8152fee9d36699a102c1b5ad4cf39e93a04 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Sun, 12 Dec 2021 16:17:33 +0000 Subject: [PATCH] tests: Use read_test_image_file helper. --- zerver/lib/test_helpers.py | 5 +++++ zerver/tests/test_import_export.py | 10 ++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/zerver/lib/test_helpers.py b/zerver/lib/test_helpers.py index a548701207..0e1ab0d9c7 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 33f6244f34..8823b81440 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)