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: Fix tests to use json encoded 'to'.

Kenneth Rodriguese969084f434f
diff --git a/zerver/tests/test_decorators.py b/zerver/tests/test_decorators.py
index eda6de02cd1..d90a957b4f5 100644
--- a/zerver/tests/test_decorators.py
+++ b/zerver/tests/test_decorators.py
@@ -608,7 +608,7 @@ class DeactivatedRealmTest(ZulipTestCase):
{
"type": "private",
"content": "Test message",
- "to": self.example_email("othello"),
+ "to": orjson.dumps([self.example_email("othello")]).decode(),
},
)
self.assert_json_error_contains(result, "Not logged in", status_code=401)
@@ -625,7 +625,7 @@ class DeactivatedRealmTest(ZulipTestCase):
{
"type": "private",
"content": "Test message",
- "to": self.example_email("othello"),
+ "to": orjson.dumps([self.example_email("othello")]).decode(),
},
)
self.assert_json_error_contains(
@@ -638,7 +638,7 @@ class DeactivatedRealmTest(ZulipTestCase):
{
"type": "private",
"content": "Test message",
- "to": self.example_email("othello"),
+ "to": orjson.dumps([self.example_email("othello")]).decode(),
},
)
self.assert_json_error_contains(
@@ -764,7 +764,7 @@ class InactiveUserTest(ZulipTestCase):
{
"type": "private",
"content": "Test message",
- "to": self.example_email("othello"),
+ "to": orjson.dumps([self.example_email("othello")]).decode(),
},
)
self.assert_json_error_contains(result, "Not logged in", status_code=401)
@@ -779,7 +779,7 @@ class InactiveUserTest(ZulipTestCase):
{
"type": "private",
"content": "Test message",
- "to": self.example_email("othello"),
+ "to": orjson.dumps([self.example_email("othello")]).decode(),
},
)
self.assert_json_error_contains(result, "Account is deactivated", status_code=401)
@@ -790,7 +790,7 @@ class InactiveUserTest(ZulipTestCase):
{
"type": "private",
"content": "Test message",
- "to": self.example_email("othello"),
+ "to": orjson.dumps([self.example_email("othello")]).decode(),
},
)
self.assert_json_error_contains(result, "Account is deactivated", status_code=401)
diff --git a/zerver/tests/test_message_send.py b/zerver/tests/test_message_send.py
index 1eba3a4d701..e0c7be7e4e7 100644
--- a/zerver/tests/test_message_send.py
+++ b/zerver/tests/test_message_send.py
@@ -566,7 +566,7 @@ class MessagePOSTTest(ZulipTestCase):
"/json/messages",
{
"type": "channel",
- "to": "nonexistent_stream",
+ "to": orjson.dumps("nonexistent_stream").decode(),
"content": "Test message",
"topic": "Test topic",
},
@@ -583,7 +583,7 @@ class MessagePOSTTest(ZulipTestCase):
"/json/messages",
{
"type": "channel",
- "to": """&<"'><non-existent>""",
+ "to": orjson.dumps("""&<"'><non-existent>""").decode(),
"content": "Test message",
"topic": "Test topic",
},
@@ -766,7 +766,7 @@ class MessagePOSTTest(ZulipTestCase):
{
"type": "direct",
"content": "Test message",
- "to": "nonexistent",
+ "to": orjson.dumps(["nonexistent"]).decode(),
},
)
self.assert_json_error(result, "Invalid email 'nonexistent'")
@@ -880,7 +880,7 @@ class MessagePOSTTest(ZulipTestCase):
{
"type": "invalid type",
"content": "Test message",
- "to": othello.email,
+ "to": orjson.dumps([othello.email]).decode(),
},
)
self.assert_json_error(result, "Invalid type")
@@ -893,7 +893,7 @@ class MessagePOSTTest(ZulipTestCase):
othello = self.example_user("othello")
result = self.client_post(
"/json/messages",
- {"type": "direct", "content": " ", "to": othello.email},
+ {"type": "direct", "content": " ", "to": orjson.dumps([othello.email]).decode()},
)
self.assert_json_error(result, "Message must not be empty")
@@ -904,7 +904,7 @@ class MessagePOSTTest(ZulipTestCase):
self.login("hamlet")
result = self.client_post(
"/json/messages",
- {"type": "channel", "to": "Verona", "content": "Test message"},
+ {"type": "channel", "to": orjson.dumps("Verona").decode(), "content": "Test message"},
)
self.assert_json_error(result, "Missing topic")
@@ -918,7 +918,7 @@ class MessagePOSTTest(ZulipTestCase):
"/json/messages",
{
"type": "channel",
- "to": "Verona",
+ "to": orjson.dumps("Verona").decode(),
"topic": "Test\n\rTopic",
"content": "Test message",
},
@@ -930,7 +930,7 @@ class MessagePOSTTest(ZulipTestCase):
"/json/messages",
{
"type": "channel",
- "to": "Verona",
+ "to": orjson.dumps("Verona").decode(),
"topic": "Test\ufffeTopic",
"content": "Test message",
},
@@ -943,7 +943,7 @@ class MessagePOSTTest(ZulipTestCase):
"/json/messages",
{
"type": "channel",
- "to": "Verona",
+ "to": orjson.dumps("Verona").decode(),
"topic": f"{Message.DM_TOPIC}",
"content": "Test message",
},
@@ -959,7 +959,7 @@ class MessagePOSTTest(ZulipTestCase):
"/json/messages",
{
"type": "invalid",
- "to": "Verona",
+ "to": orjson.dumps("Verona").decode(),
"content": "Test message",
"topic": "Test topic",
},
@@ -973,7 +973,7 @@ class MessagePOSTTest(ZulipTestCase):
self.login("hamlet")
result = self.client_post(
"/json/messages",
- {"type": "direct", "content": "Test content", "to": ""},
+ {"type": "direct", "content": "Test content", "to": orjson.dumps("").decode()},
)
self.assert_json_error(result, "Message must have recipients")
@@ -1028,7 +1028,7 @@ class MessagePOSTTest(ZulipTestCase):
"sender": self.mit_email("sipbtest"),
"content": "Test message",
"client": "irc_mirror",
- "to": self.mit_email("starnine"),
+ "to": orjson.dumps([self.mit_email("starnine")]).decode(),
},
subdomain="zephyr",
)
@@ -1046,7 +1046,7 @@ class MessagePOSTTest(ZulipTestCase):
"sender": self.mit_email("sipbtest"),
"content": "Test message",
"client": "irc_mirror",
- "to": self.mit_email("espuser"),
+ "to": orjson.dumps([self.mit_email("espuser")]).decode(),
},
subdomain="zephyr",
)
@@ -1059,7 +1059,7 @@ class MessagePOSTTest(ZulipTestCase):
self.login("hamlet")
post_data = {
"type": "channel",
- "to": "Verona",
+ "to": orjson.dumps("Verona").decode(),
"content": " I like null bytes \x00 in my content",
"topic": "Test topic",
}
@@ -1144,7 +1144,7 @@ class MessagePOSTTest(ZulipTestCase):
"/json/messages",
{
"type": "channel",
- "to": "Verona",
+ "to": orjson.dumps("Verona").decode(),
"content": "Test message",
"topic": "Test topic",
"forged": "true",
@@ -1160,7 +1160,7 @@ class MessagePOSTTest(ZulipTestCase):
"type": "direct",
"content": "Test message",
"client": "irc_mirror",
- "to": self.mit_email("starnine"),
+ "to": orjson.dumps([self.mit_email("starnine")]).decode(),
},
subdomain="zephyr",
)
@@ -1175,7 +1175,7 @@ class MessagePOSTTest(ZulipTestCase):
"sender": self.mit_email("sipbtest"),
"content": "Test message",
"client": "irc_mirror",
- "to": self.mit_email("starnine"),
+ "to": orjson.dumps([self.mit_email("starnine")]).decode(),
},
subdomain="zephyr",
)
@@ -1194,7 +1194,7 @@ class MessagePOSTTest(ZulipTestCase):
"sender": self.mit_email("sipbtest"),
"content": "Test message",
"client": "irc_mirror",
- "to": self.mit_email("starnine"),
+ "to": orjson.dumps([self.mit_email("starnine")]).decode(),
},
subdomain="zephyr",
)
@@ -2385,7 +2385,7 @@ class StreamMessagesTest(ZulipTestCase):
"/api/v1/messages",
{
"type": "channel",
- "to": "Verona",
+ "to": orjson.dumps("Verona").decode(),
"sender": self.mit_email("sipbtest"),
"client": "irc_mirror",
"topic": "announcement",