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

Steve Howell92136d738a7a
diff --git a/zerver/lib/event_schema.py b/zerver/lib/event_schema.py
index ac9a98e2de2..557ad43e772 100644
--- a/zerver/lib/event_schema.py
+++ b/zerver/lib/event_schema.py
@@ -139,6 +139,35 @@ check_message = check_events_dict(
]
)
+# We will eventually just send user_ids.
+_check_reaction_user = check_dict_only(
+ required_keys=[
+ # force vertical
+ ("email", check_string),
+ ("full_name", check_string),
+ ("user_id", check_int),
+ ]
+)
+
+_check_reaction = check_events_dict(
+ required_keys=[
+ ("type", equals("reaction")),
+ ("op", check_add_or_remove),
+ ("message_id", check_int),
+ ("emoji_name", check_string),
+ ("emoji_code", check_string),
+ ("reaction_type", check_string),
+ ("user_id", check_int),
+ ("user", _check_reaction_user),
+ ]
+)
+
+
+def check_reaction(var_name: str, event: Dict[str, Any], op: str) -> None:
+ _check_reaction(var_name, event)
+ assert event["op"] == op
+
+
_check_bot_services_outgoing = check_dict_only(
required_keys=[
# force vertical
diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py
index aef623890a5..f25e039f9da 100644
--- a/zerver/tests/test_events.py
+++ b/zerver/tests/test_events.py
@@ -93,6 +93,7 @@ from zerver.lib.event_schema import (
basic_stream_fields,
check_events_dict,
check_message,
+ check_reaction,
check_realm_bot_add,
check_realm_bot_delete,
check_realm_bot_remove,
@@ -491,21 +492,6 @@ class NormalActionsTest(BaseAction):
)
def test_add_reaction(self) -> None:
- schema_checker = check_events_dict([
- ('type', equals('reaction')),
- ('op', equals('add')),
- ('message_id', check_int),
- ('emoji_name', check_string),
- ('emoji_code', check_string),
- ('reaction_type', check_string),
- ('user_id', check_int),
- ('user', check_dict_only([
- ('email', check_string),
- ('full_name', check_string),
- ('user_id', check_int),
- ])),
- ])
-
message_id = self.send_stream_message(self.example_user("hamlet"), "Verona", "hello")
message = Message.objects.get(id=message_id)
events = self.verify_action(
@@ -513,7 +499,7 @@ class NormalActionsTest(BaseAction):
self.user_profile, message, "tada", "1f389", "unicode_emoji"),
state_change_expected=False,
)
- schema_checker('events[0]', events[0])
+ check_reaction('events[0]', events[0], 'add')
def test_add_submessage(self) -> None:
schema_checker = check_events_dict([
@@ -544,21 +530,6 @@ class NormalActionsTest(BaseAction):
schema_checker('events[0]', events[0])
def test_remove_reaction(self) -> None:
- schema_checker = check_events_dict([
- ('type', equals('reaction')),
- ('op', equals('remove')),
- ('message_id', check_int),
- ('emoji_name', check_string),
- ('emoji_code', check_string),
- ('reaction_type', check_string),
- ('user_id', check_int),
- ('user', check_dict_only([
- ('email', check_string),
- ('full_name', check_string),
- ('user_id', check_int),
- ])),
- ])
-
message_id = self.send_stream_message(self.example_user("hamlet"), "Verona", "hello")
message = Message.objects.get(id=message_id)
do_add_reaction(self.user_profile, message, "tada", "1f389", "unicode_emoji")
@@ -567,7 +538,7 @@ class NormalActionsTest(BaseAction):
self.user_profile, message, "1f389", "unicode_emoji"),
state_change_expected=False,
)
- schema_checker('events[0]', events[0])
+ check_reaction('events[0]', events[0], 'remove')
def test_invite_user_event(self) -> None:
schema_checker = check_events_dict([