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_subscription_update.

Steve Howellb7b2546f449e
diff --git a/zerver/lib/event_schema.py b/zerver/lib/event_schema.py
index 1eb243787ae..8f608b53d0b 100644
--- a/zerver/lib/event_schema.py
+++ b/zerver/lib/event_schema.py
@@ -1108,6 +1108,28 @@ subscription_remove_event = event_dict_type(
)
check_subscription_remove = make_checker(subscription_remove_event)
+subscription_update_event = event_dict_type(
+ required_keys=[
+ ("type", Equals("subscription")),
+ ("op", Equals("update")),
+ ("property", str),
+ ("stream_id", int),
+ ("value", value_type),
+ ("name", str),
+ ("email", str),
+ ]
+)
+_check_subscription_update = make_checker(subscription_update_event)
+
+
+def check_subscription_update(
+ var_name: str, event: Dict[str, object], property: str, value: bool
+) -> None:
+ _check_subscription_update(var_name, event)
+ assert event["property"] == property
+ assert event["value"] == value
+
+
typing_person_type = DictType(
required_keys=[
# we should eventually just send user_id
diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py
index c568a13b0d7..2beee42ada4 100644
--- a/zerver/tests/test_events.py
+++ b/zerver/tests/test_events.py
@@ -124,6 +124,7 @@ from zerver.lib.event_schema import (
check_subscription_peer_add,
check_subscription_peer_remove,
check_subscription_remove,
+ check_subscription_update,
check_typing_start,
check_typing_stop,
check_update_display_settings,
@@ -1021,15 +1022,6 @@ class NormalActionsTest(BaseAction):
check_realm_update_dict('events[0]', events[0])
def test_change_pin_stream(self) -> None:
- schema_checker = check_events_dict([
- ('type', equals('subscription')),
- ('op', equals('update')),
- ('property', equals('pin_to_top')),
- ('stream_id', check_int),
- ('value', check_bool),
- ('name', check_string),
- ('email', check_string),
- ])
stream = get_stream("Denmark", self.user_profile.realm)
sub = get_subscription(stream.name, self.user_profile)
do_change_subscription_property(self.user_profile, sub, stream, "pin_to_top", False)
@@ -1041,20 +1033,15 @@ class NormalActionsTest(BaseAction):
stream,
"pin_to_top",
pinned))
- schema_checker('events[0]', events[0])
+ check_subscription_update(
+ "events[0]",
+ events[0],
+ property="pin_to_top",
+ value=pinned,
+ )
def test_change_stream_notification_settings(self) -> None:
for setting_name in ['email_notifications']:
- schema_checker = check_events_dict([
- ('type', equals('subscription')),
- ('op', equals('update')),
- ('property', equals(setting_name)),
- ('stream_id', check_int),
- ('value', check_bool),
- ('name', check_string),
- ('email', check_string),
- ])
-
stream = get_stream("Denmark", self.user_profile.realm)
sub = get_subscription(stream.name, self.user_profile)
@@ -1067,7 +1054,12 @@ class NormalActionsTest(BaseAction):
stream,
setting_name, value),
notification_settings_null=True)
- schema_checker('events[0]', events[0])
+ check_subscription_update(
+ "events[0]",
+ events[0],
+ property=setting_name,
+ value=value,
+ )
for value in (True, False):
events = self.verify_action(
@@ -1077,7 +1069,12 @@ class NormalActionsTest(BaseAction):
stream,
setting_name,
value))
- schema_checker('events[0]', events[0])
+ check_subscription_update(
+ "events[0]",
+ events[0],
+ property=setting_name,
+ value=value,
+ )
def test_change_realm_message_edit_settings(self) -> None:
# Test every transition among the four possibilities {T,F} x {0, non-0}