Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
playgrounds: Avoid json encoding each field in POST /realm/playgrounds.
Sumanth V Raof9b79999ed13
diff --git a/zerver/openapi/curl_param_value_generators.py b/zerver/openapi/curl_param_value_generators.pyindex 4cd6ce318c1..4e0e55a9133 100644--- a/zerver/openapi/curl_param_value_generators.py+++ b/zerver/openapi/curl_param_value_generators.py@@ -5,7 +5,6 @@# based on Zulip's OpenAPI definitions, as well as test setup and# fetching of appropriate parameter values to use when running the# cURL examples as part of the tools/test-api test suite.-import jsonfrom functools import wrapsfrom typing import Any, Callable, Dict, List, Optional, Set, Tuple@@ -283,8 +282,8 @@ def upload_custom_emoji() -> Dict[str, object]:def add_realm_playground() -> Dict[str, object]:return {"name": "Python2 playground",- "pygments_language": json.dumps("Python2"),- "url_prefix": json.dumps("https://python2.example.com"),+ "pygments_language": "Python2",+ "url_prefix": "https://python2.example.com",}diff --git a/zerver/openapi/python_examples.py b/zerver/openapi/python_examples.pyindex 17691ca27c1..9b2757d8b20 100644--- a/zerver/openapi/python_examples.py+++ b/zerver/openapi/python_examples.py@@ -390,8 +390,8 @@ def add_realm_playground(client: Client) -> None:# Add a realm playground for Pythonrequest = {"name": "Python playground",- "pygments_language": json.dumps("Python"),- "url_prefix": json.dumps("https://python.example.com"),+ "pygments_language": "Python",+ "url_prefix": "https://python.example.com",}result = client.call_endpoint(url="/realm/playgrounds", method="POST", request=request)# {code_example|end}diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yamlindex 2d89dbfd54c..9e2f199c141 100644--- a/zerver/openapi/zulip.yaml+++ b/zerver/openapi/zulip.yaml@@ -6692,7 +6692,8 @@ paths:`POST {{ api_url }}/v1/realm/playgrounds`- **Changes**: New in Zulip 4.0 (feature level 49).+ **Changes**: New in Zulip 4.0 (feature level 49). A parameter encoding bug was+ fixed in Zulip 4.0 (feature level 57).parameters:- name: namein: query@@ -6702,7 +6703,7 @@ paths:playground options exist for that programming language.schema:type: string- example: "Python playground"+ example: Python playgroundrequired: true- name: pygments_languagein: query@@ -6711,7 +6712,7 @@ paths:programming language.schema:type: string- example: "Python"+ example: Pythonrequired: true- name: url_prefixin: querydiff --git a/zerver/tests/test_realm_playgrounds.py b/zerver/tests/test_realm_playgrounds.pyindex ac2b4244a28..ef5bcd09cb2 100644--- a/zerver/tests/test_realm_playgrounds.py+++ b/zerver/tests/test_realm_playgrounds.py@@ -1,18 +1,9 @@-from typing import Dict--import orjson-from zerver.lib.actions import do_add_realm_playgroundfrom zerver.lib.test_classes import ZulipTestCasefrom zerver.models import RealmPlayground, get_realmclass RealmPlaygroundTests(ZulipTestCase):- def json_serialize(self, payload: Dict[str, str]) -> Dict[str, str]:- payload["url_prefix"] = orjson.dumps(payload["url_prefix"]).decode()- payload["pygments_language"] = orjson.dumps(payload["pygments_language"]).decode()- return payload-def test_create_one_playground_entry(self) -> None:iago = self.example_user("iago")@@ -22,7 +13,7 @@ class RealmPlaygroundTests(ZulipTestCase):"url_prefix": "https://python.example.com",}# Now send a POST request to the API endpoint.- resp = self.api_post(iago, "/json/realm/playgrounds", self.json_serialize(payload))+ resp = self.api_post(iago, "/json/realm/playgrounds", payload)self.assert_json_success(resp)# Check if the actual object exists@@ -47,7 +38,7 @@ class RealmPlaygroundTests(ZulipTestCase):},]for payload in data:- resp = self.api_post(iago, "/json/realm/playgrounds", self.json_serialize(payload))+ resp = self.api_post(iago, "/json/realm/playgrounds", payload)self.assert_json_success(resp)realm = get_realm("zulip")@@ -66,12 +57,12 @@ class RealmPlaygroundTests(ZulipTestCase):"pygments_language": "Python","url_prefix": "https://invalid-url",}- resp = self.api_post(iago, "/json/realm/playgrounds", self.json_serialize(payload))+ resp = self.api_post(iago, "/json/realm/playgrounds", payload)self.assert_json_error(resp, "url_prefix is not a URL")payload["url_prefix"] = "https://python.example.com"payload["pygments_language"] = "a$b$c"- resp = self.api_post(iago, "/json/realm/playgrounds", self.json_serialize(payload))+ resp = self.api_post(iago, "/json/realm/playgrounds", payload)self.assert_json_error(resp, "Invalid characters in pygments language")def test_create_already_existing_playground(self) -> None:@@ -82,11 +73,10 @@ class RealmPlaygroundTests(ZulipTestCase):"pygments_language": "Python","url_prefix": "https://python.example.com",}- serialized_payload = self.json_serialize(payload)- resp = self.api_post(iago, "/json/realm/playgrounds", serialized_payload)+ resp = self.api_post(iago, "/json/realm/playgrounds", payload)self.assert_json_success(resp)- resp = self.api_post(iago, "/json/realm/playgrounds", serialized_payload)+ resp = self.api_post(iago, "/json/realm/playgrounds", payload)self.assert_json_error(resp, "Realm playground with this Realm and Name already exists.")def test_not_realm_admin(self) -> None:diff --git a/zerver/views/realm_playgrounds.py b/zerver/views/realm_playgrounds.pyindex b9678f2daa5..17353878508 100644--- a/zerver/views/realm_playgrounds.py+++ b/zerver/views/realm_playgrounds.py@@ -39,8 +39,8 @@ def add_realm_playground(request: HttpRequest,user_profile: UserProfile,name: str = REQ(),- url_prefix: str = REQ(json_validator=check_url),- pygments_language: str = REQ(json_validator=check_pygments_language),+ url_prefix: str = REQ(str_validator=check_url),+ pygments_language: str = REQ(str_validator=check_pygments_language),) -> HttpResponse:try:playground_id = do_add_realm_playground(