snapshot of https://github.com/zulip/zulip.git @ 48c69911c7dd4e03b20552eb3bd77ad8151c1357 (2026-09-15)
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
This commit is contained in:
111
zerver/tests/test_saved_snippets.py
Normal file
111
zerver/tests/test_saved_snippets.py
Normal file
@@ -0,0 +1,111 @@
|
||||
from zerver.actions.saved_snippets import do_create_saved_snippet
|
||||
from zerver.lib.test_classes import ZulipTestCase
|
||||
from zerver.models import SavedSnippet, UserProfile
|
||||
|
||||
|
||||
class SavedSnippetTests(ZulipTestCase):
|
||||
def create_example_saved_snippet(self, user: UserProfile) -> int:
|
||||
saved_snippet = do_create_saved_snippet(
|
||||
"Welcome message", "**Welcome** to the organization.", user
|
||||
)
|
||||
return saved_snippet.id
|
||||
|
||||
def test_create_saved_snippet(self) -> None:
|
||||
"""Tests creation of saved snippets."""
|
||||
|
||||
user = self.example_user("hamlet")
|
||||
self.login_user(user)
|
||||
|
||||
result = self.client_get(
|
||||
"/json/saved_snippets",
|
||||
)
|
||||
response_dict = self.assert_json_success(result)
|
||||
self.assert_length(response_dict["saved_snippets"], 0)
|
||||
|
||||
result = self.client_post(
|
||||
"/json/saved_snippets",
|
||||
{"title": "Welcome message", "content": "**Welcome** to the organization."},
|
||||
)
|
||||
response_dict = self.assert_json_success(result)
|
||||
saved_snippet_id = response_dict["saved_snippet_id"]
|
||||
|
||||
result = self.client_get(
|
||||
"/json/saved_snippets",
|
||||
)
|
||||
response_dict = self.assert_json_success(result)
|
||||
self.assert_length(response_dict["saved_snippets"], 1)
|
||||
self.assertEqual(saved_snippet_id, response_dict["saved_snippets"][0]["id"])
|
||||
|
||||
result = self.client_post(
|
||||
"/json/saved_snippets",
|
||||
{
|
||||
"title": "A" * (SavedSnippet.MAX_TITLE_LENGTH + 60),
|
||||
"content": "**Welcome** to the organization.",
|
||||
},
|
||||
)
|
||||
self.assert_json_error(
|
||||
result,
|
||||
status_code=400,
|
||||
msg=f"title is too long (limit: {SavedSnippet.MAX_TITLE_LENGTH} characters)",
|
||||
)
|
||||
|
||||
def test_edit_saved_snippet(self) -> None:
|
||||
"""Tests updation of saved snippets."""
|
||||
|
||||
user = self.example_user("hamlet")
|
||||
self.login_user(user)
|
||||
saved_snippet_id = self.create_example_saved_snippet(user)
|
||||
|
||||
result = self.client_patch(
|
||||
f"/json/saved_snippets/{saved_snippet_id}",
|
||||
{"title": "New title"},
|
||||
)
|
||||
self.assert_json_success(result)
|
||||
|
||||
result = self.client_patch(
|
||||
f"/json/saved_snippets/{saved_snippet_id}", {"content": "New content"}
|
||||
)
|
||||
self.assert_json_success(result)
|
||||
|
||||
# No-op requests succeed.
|
||||
result = self.client_patch(
|
||||
f"/json/saved_snippets/{saved_snippet_id}",
|
||||
)
|
||||
self.assert_json_success(result)
|
||||
|
||||
# Tests if error is thrown when the provided ID does not exist.
|
||||
result = self.client_patch(
|
||||
"/json/saved_snippets/10",
|
||||
{"content": "New content"},
|
||||
)
|
||||
self.assert_json_error(result, "Saved snippet does not exist.", status_code=404)
|
||||
|
||||
def test_delete_saved_snippet(self) -> None:
|
||||
"""Tests deletion of saved snippets."""
|
||||
|
||||
user = self.example_user("hamlet")
|
||||
self.login_user(user)
|
||||
saved_snippet_id = self.create_example_saved_snippet(user)
|
||||
|
||||
result = self.client_get(
|
||||
"/json/saved_snippets",
|
||||
)
|
||||
response_dict = self.assert_json_success(result)
|
||||
self.assert_length(response_dict["saved_snippets"], 1)
|
||||
|
||||
result = self.client_delete(
|
||||
f"/json/saved_snippets/{saved_snippet_id}",
|
||||
)
|
||||
self.assert_json_success(result)
|
||||
|
||||
result = self.client_get(
|
||||
"/json/saved_snippets",
|
||||
)
|
||||
response_dict = self.assert_json_success(result)
|
||||
self.assert_length(response_dict["saved_snippets"], 0)
|
||||
|
||||
# Tests if error is thrown when the provided ID does not exist.
|
||||
result = self.client_delete(
|
||||
"/json/saved_snippets/10",
|
||||
)
|
||||
self.assert_json_error(result, "Saved snippet does not exist.", status_code=404)
|
||||
Reference in New Issue
Block a user