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.

tests: Check for warnings from OpenAPI deprecated parameters.

Anders Kaseorg25edaa87ecdf
diff --git a/zerver/lib/test_classes.py b/zerver/lib/test_classes.py
index 96756566e86..c3e71b18afa 100644
--- a/zerver/lib/test_classes.py
+++ b/zerver/lib/test_classes.py
@@ -1312,14 +1312,18 @@ Output:
anchor: int | str = 1,
num_before: int = 100,
num_after: int = 100,
- use_first_unread_anchor: bool = False,
+ use_first_unread_anchor: bool | None = None,
include_anchor: bool = True,
) -> dict[str, list[dict[str, Any]]]:
post_params = {
"anchor": anchor,
"num_before": num_before,
"num_after": num_after,
- "use_first_unread_anchor": orjson.dumps(use_first_unread_anchor).decode(),
+ **(
+ {}
+ if use_first_unread_anchor is None
+ else {"use_first_unread_anchor": orjson.dumps(use_first_unread_anchor).decode()}
+ ),
"include_anchor": orjson.dumps(include_anchor).decode(),
}
result = self.client_get("/json/messages", dict(post_params))
@@ -1331,7 +1335,7 @@ Output:
anchor: str | int = 1,
num_before: int = 100,
num_after: int = 100,
- use_first_unread_anchor: bool = False,
+ use_first_unread_anchor: bool | None = None,
) -> list[dict[str, Any]]:
data = self.get_messages_response(anchor, num_before, num_after, use_first_unread_anchor)
return data["messages"]
diff --git a/zerver/tests/test_channel_fetch.py b/zerver/tests/test_channel_fetch.py
index 4b6fb7871e3..7cd3cae0daa 100644
--- a/zerver/tests/test_channel_fetch.py
+++ b/zerver/tests/test_channel_fetch.py
@@ -286,7 +286,10 @@ class GetStreamsTest(ZulipTestCase):
result = self.api_get(admin_user, url, data)
json = self.assert_json_success(result)
- backward_compatible_result = self.api_get(admin_user, url, backward_compatible_data)
+ with self.assertWarnsRegex(
+ DeprecationWarning, r"^include_all_active parameter is deprecated$"
+ ):
+ backward_compatible_result = self.api_get(admin_user, url, backward_compatible_data)
json_for_backward_compatible_request = self.assert_json_success(backward_compatible_result)
self.assertEqual(json, json_for_backward_compatible_request)
diff --git a/zerver/tests/test_message_flags.py b/zerver/tests/test_message_flags.py
index bf704bd45a2..ed629dbd29c 100644
--- a/zerver/tests/test_message_flags.py
+++ b/zerver/tests/test_message_flags.py
@@ -86,18 +86,19 @@ class FirstUnreadAnchorTests(ZulipTestCase):
self.assertEqual(messages_response["anchor"], new_message_id)
# Test with the old way of expressing use_first_unread_anchor=True
- messages_response = self.get_messages_response(
- anchor=0, num_before=0, num_after=1, use_first_unread_anchor=True
- )
+ with self.assertWarnsRegex(
+ DeprecationWarning, r"^use_first_unread_anchor parameter is deprecated$"
+ ):
+ messages_response = self.get_messages_response(
+ anchor=0, num_before=0, num_after=1, use_first_unread_anchor=True
+ )
self.assertEqual(messages_response["messages"][0]["id"], new_message_id)
self.assertEqual(messages_response["anchor"], new_message_id)
# We want to get the message_id of an arbitrary old message. We can
# call get_messages with use_first_unread_anchor=False and simply
# save the first message we're returned.
- messages = self.get_messages(
- anchor=0, num_before=0, num_after=2, use_first_unread_anchor=False
- )
+ messages = self.get_messages(anchor=0, num_before=0, num_after=2)
old_message_id = messages[0]["id"]
# Verify the message is marked as read