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

Steve Howell7176b90882db
diff --git a/zerver/lib/event_schema.py b/zerver/lib/event_schema.py
index bfa9ce74317..99e2a9d923a 100644
--- a/zerver/lib/event_schema.py
+++ b/zerver/lib/event_schema.py
@@ -499,6 +499,23 @@ check_subscription_remove = check_events_dict(
]
)
+_check_typing_person = check_dict_only(
+ required_keys=[
+ # we should eventually just send user_id
+ ("email", check_string),
+ ("user_id", check_int),
+ ]
+)
+
+check_typing_start = check_events_dict(
+ required_keys=[
+ ("type", equals("typing")),
+ ("op", equals("start")),
+ ("sender", _check_typing_person),
+ ("recipients", check_list(_check_typing_person)),
+ ]
+)
+
_check_update_display_settings = check_events_dict(
required_keys=[
("type", equals("update_display_settings")),
diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py
index 1fd083d5beb..d7c27e8dbf5 100644
--- a/zerver/tests/test_events.py
+++ b/zerver/tests/test_events.py
@@ -107,6 +107,7 @@ from zerver.lib.event_schema import (
check_subscription_peer_add,
check_subscription_peer_remove,
check_subscription_remove,
+ check_typing_start,
check_update_display_settings,
check_update_global_notifications,
check_update_message,
@@ -609,24 +610,12 @@ class NormalActionsTest(BaseAction):
check_invites_changed('events[4]', events[4])
def test_typing_events(self) -> None:
- schema_checker = check_events_dict([
- ('type', equals('typing')),
- ('op', equals('start')),
- ('sender', check_dict_only([
- ('email', check_string),
- ('user_id', check_int)])),
- ('recipients', check_list(check_dict_only([
- ('email', check_string),
- ('user_id', check_int),
- ]))),
- ])
-
events = self.verify_action(
lambda: check_send_typing_notification(
self.user_profile, [self.example_user("cordelia").id], "start"),
state_change_expected=False,
)
- schema_checker('events[0]', events[0])
+ check_typing_start('events[0]', events[0])
def test_custom_profile_fields_events(self) -> None:
schema_checker = check_events_dict([