Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

message_send: Add tests to verify legacy behavior.

Kenneth Rodrigues2e4ffd98acee
diff --git a/zerver/tests/test_message_send.py b/zerver/tests/test_message_send.py
index e0c7be7e4e7..2c6985b7236 100644
--- a/zerver/tests/test_message_send.py
+++ b/zerver/tests/test_message_send.py
@@ -3691,3 +3691,36 @@ class CheckMessageTest(ZulipTestCase):
"Only the general chat topic is allowed in this channel.",
):
check_message(sender, client, addressee_named_topic, message_content, realm)
+
+
+class SendToStrTest(ZulipTestCase):
+ """
+ The OpenAPI documentation specifies that the `to` parameter for
+ the send message endpoint has to be Json encoded, however to maintain compatibility
+ with older API clients, the endpoint also accepts a `str` value for the `to` parameter.
+ These tests verify this legacy behavior.
+ """
+
+ def test_message_send_to_str_channel(self) -> None:
+ self.login("hamlet")
+ result = self.client_post(
+ "/json/messages",
+ {
+ "type": "channel",
+ "to": "Denmark",
+ "content": "Test message",
+ "topic": "Test topic",
+ },
+ intentionally_undocumented=True,
+ )
+ self.assert_json_success(result)
+
+ def test_message_send_to_str_direct(self) -> None:
+ self.login("hamlet")
+ othello = self.example_user("othello")
+ result = self.client_post(
+ "/json/messages",
+ {"type": "direct", "content": "Hello", "to": orjson.dumps([othello.email]).decode()},
+ intentionally_undocumented=True,
+ )
+ self.assert_json_success(result)