event_schema: Extract check_update_message_flags.

This commit is contained in:
Steve Howell 2020-07-17 07:13:10 +00:00 committed by Tim Abbott
parent f2bc22e869
commit 5209de0261
2 changed files with 29 additions and 17 deletions

View File

@ -82,6 +82,14 @@ def check_events_dict(
)
check_add_or_remove = check_union(
[
# force vertical
equals("add"),
equals("remove"),
]
)
check_value = check_union(
[
# force vertical formatting
@ -588,3 +596,20 @@ check_update_message_embedded = check_events_dict(
("sender", check_string),
]
)
_check_update_message_flags = check_events_dict(
required_keys=[
("type", equals("update_message_flags")),
("operation", check_add_or_remove),
("flag", check_string),
("messages", check_list(check_int)),
("all", check_bool),
]
)
def check_update_message_flags(
var_name: str, event: Dict[str, Any], operation: str
) -> None:
_check_update_message_flags(var_name, event)
assert event["operation"] == operation

View File

@ -108,6 +108,7 @@ from zerver.lib.event_schema import (
check_update_global_notifications,
check_update_message,
check_update_message_embedded,
check_update_message_flags,
)
from zerver.lib.events import apply_events, fetch_initial_state_data, post_process_state
from zerver.lib.markdown import MentionData
@ -442,14 +443,6 @@ class NormalActionsTest(BaseAction):
def test_update_message_flags(self) -> None:
# Test message flag update events
schema_checker = check_events_dict([
('all', check_bool),
('type', equals('update_message_flags')),
('flag', check_string),
('messages', check_list(check_int)),
('operation', equals("add")),
])
message = self.send_personal_message(
self.example_user("cordelia"),
self.example_user("hamlet"),
@ -460,19 +453,13 @@ class NormalActionsTest(BaseAction):
lambda: do_update_message_flags(user_profile, get_client("website"), 'add', 'starred', [message]),
state_change_expected=True,
)
schema_checker('events[0]', events[0])
schema_checker = check_events_dict([
('all', check_bool),
('type', equals('update_message_flags')),
('flag', check_string),
('messages', check_list(check_int)),
('operation', equals("remove")),
])
check_update_message_flags('events[0]', events[0], 'add')
events = self.verify_action(
lambda: do_update_message_flags(user_profile, get_client("website"), 'remove', 'starred', [message]),
state_change_expected=True,
)
schema_checker('events[0]', events[0])
check_update_message_flags('events[0]', events[0], 'remove')
def test_update_read_flag_removes_unread_msg_ids(self) -> None: