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.

event_schema: Extract check_alert_words.

Steve Howell631adc567710
diff --git a/zerver/lib/event_schema.py b/zerver/lib/event_schema.py
index e67015783c2..4c82cfddcfb 100644
--- a/zerver/lib/event_schema.py
+++ b/zerver/lib/event_schema.py
@@ -109,6 +109,14 @@ check_optional_value = check_union(
]
)
+check_alert_words = check_events_dict(
+ required_keys=[
+ # force vertical formatting
+ ("type", equals("alert_words")),
+ ("alert_words", check_list(check_string)),
+ ]
+)
+
_check_custom_profile_field = check_dict_only(
required_keys=[
("id", check_int),
diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py
index ca5778f6cc7..94be446072c 100644
--- a/zerver/tests/test_events.py
+++ b/zerver/tests/test_events.py
@@ -91,6 +91,7 @@ from zerver.lib.actions import (
)
from zerver.lib.event_schema import (
basic_stream_fields,
+ check_alert_words,
check_custom_profile_fields,
check_events_dict,
check_invites_changed,
@@ -819,18 +820,13 @@ class NormalActionsTest(BaseAction):
self.assertEqual(new_user_profile.email, f"user{new_user_profile.id}@zulip.testserver")
def test_alert_words_events(self) -> None:
- alert_words_checker = check_events_dict([
- ('type', equals('alert_words')),
- ('alert_words', check_list(check_string)),
- ])
-
events = self.verify_action(
lambda: do_add_alert_words(self.user_profile, ["alert_word"]))
- alert_words_checker('events[0]', events[0])
+ check_alert_words('events[0]', events[0])
events = self.verify_action(
lambda: do_remove_alert_words(self.user_profile, ["alert_word"]))
- alert_words_checker('events[0]', events[0])
+ check_alert_words('events[0]', events[0])
def test_away_events(self) -> None:
checker = check_events_dict([