test-api: Reset uploaded realm emoji for realm export tests.

Because of how the test runner varies settings.LOCAL_UPLOADS_DIR,
we reset the realm uploaded emoji for the realm export tests for
both the python and curl examples. Previously, the realm export
was failing after the success response with the export ID was
sent.
This commit is contained in:
Lauryn Menard 2026-04-20 17:18:36 +02:00 committed by Tim Abbott
parent 5b154633f8
commit 29639e76ea
2 changed files with 20 additions and 1 deletions

View File

@ -45,6 +45,7 @@ with test_server_running(
from zerver.models.users import get_user
from zerver.openapi.javascript_examples import test_js_bindings
from zerver.openapi.python_examples import (
reset_realm_uploaded_emoji,
test_invalid_api_key,
test_realm_deactivated,
test_the_api,
@ -118,7 +119,9 @@ with test_server_running(
site=site,
)
reset_realm_uploaded_emoji(iago)
test_the_api(client, nonadmin_client, owner_client, bot_client)
reset_realm_uploaded_emoji(iago)
test_generated_curl_examples_for_success(client)
test_js_bindings(client)

View File

@ -20,11 +20,15 @@ from email.headerregistry import Address
from functools import wraps
from typing import Any, TypeVar
from django.core.files.base import File
from typing_extensions import ParamSpec
from zulip import Client
from zerver.actions.realm_emoji import check_add_realm_emoji
from zerver.lib.storage import static_path
from zerver.models.realm_emoji import RealmEmoji
from zerver.models.realms import get_realm
from zerver.models.users import get_user
from zerver.models.users import UserProfile, get_user
from zerver.openapi.openapi import validate_against_openapi_schema
ZULIP_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
@ -61,6 +65,18 @@ def openapi_test_function(
return wrapper
def reset_realm_uploaded_emoji(user: UserProfile) -> None:
# Due to the way that the test runner varies settings.LOCAL_UPLOADS_DIR
# we need to reset the uploaded green_tick emoji in order to generate
# successful realm exports for the API python and curl example tests.
RealmEmoji.objects.all().delete()
IMAGE_FILE_PATH = static_path("images/test-images/checkbox.png")
with open(IMAGE_FILE_PATH, "rb") as fp:
check_add_realm_emoji(
user.realm, "green_tick", user, File(fp, name="checkbox.png"), "image/png"
)
def ensure_users(ids_list: list[int], user_names: list[str]) -> None:
# Ensure that the list of user ids (ids_list)
# matches the users we want to refer to (user_names).