test_helpers: Use a mock, rather than explicitly setting and unsetting.

This commit is contained in:
Alex Vandiver 2022-12-16 00:09:23 +00:00 committed by Alex Vandiver
parent 7ad06473b6
commit 0c3d74ea31
1 changed files with 1 additions and 6 deletions

View File

@ -38,7 +38,6 @@ from django.urls import URLResolver
from moto.s3 import mock_s3 from moto.s3 import mock_s3
from mypy_boto3_s3.service_resource import Bucket from mypy_boto3_s3.service_resource import Bucket
import zerver.lib.upload
from zerver.actions.realm_settings import do_set_realm_property from zerver.actions.realm_settings import do_set_realm_property
from zerver.lib import cache from zerver.lib import cache
from zerver.lib.avatar import avatar_url from zerver.lib.avatar import avatar_url
@ -46,7 +45,6 @@ from zerver.lib.cache import get_cache_backend
from zerver.lib.db import Params, ParamsT, Query, TimeTrackingCursor from zerver.lib.db import Params, ParamsT, Query, TimeTrackingCursor
from zerver.lib.integrations import WEBHOOK_INTEGRATIONS from zerver.lib.integrations import WEBHOOK_INTEGRATIONS
from zerver.lib.request import RequestNotes from zerver.lib.request import RequestNotes
from zerver.lib.upload.local import LocalUploadBackend
from zerver.lib.upload.s3 import S3UploadBackend from zerver.lib.upload.s3 import S3UploadBackend
from zerver.models import ( from zerver.models import (
Client, Client,
@ -552,11 +550,8 @@ def use_s3_backend(method: FuncT) -> FuncT:
@override_settings(LOCAL_AVATARS_DIR=None) @override_settings(LOCAL_AVATARS_DIR=None)
@override_settings(LOCAL_FILES_DIR=None) @override_settings(LOCAL_FILES_DIR=None)
def new_method(*args: Any, **kwargs: Any) -> Any: def new_method(*args: Any, **kwargs: Any) -> Any:
zerver.lib.upload.upload_backend = S3UploadBackend() with mock.patch("zerver.lib.upload.upload_backend", S3UploadBackend()):
try:
return method(*args, **kwargs) return method(*args, **kwargs)
finally:
zerver.lib.upload.upload_backend = LocalUploadBackend()
return new_method return new_method