Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
test-api: Reset uploaded realm emoji for realm export tests.
Lauryn Menard29639e76eab4
diff --git a/tools/test-api b/tools/test-apiindex 52189292e7e..34650ef3a19 100755--- a/tools/test-api+++ b/tools/test-api@@ -45,6 +45,7 @@ with test_server_running(from zerver.models.users import get_userfrom zerver.openapi.javascript_examples import test_js_bindingsfrom 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)diff --git a/zerver/openapi/python_examples.py b/zerver/openapi/python_examples.pyindex 5916dcfa4ac..83ba4b0dc99 100644--- a/zerver/openapi/python_examples.py+++ b/zerver/openapi/python_examples.py@@ -20,11 +20,15 @@ from email.headerregistry import Addressfrom functools import wrapsfrom typing import Any, TypeVar+from django.core.files.base import Filefrom typing_extensions import ParamSpecfrom 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 RealmEmojifrom zerver.models.realms import get_realm-from zerver.models.users import get_user+from zerver.models.users import UserProfile, get_userfrom zerver.openapi.openapi import validate_against_openapi_schemaZULIP_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).