Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
event tests: Cover do_update_user_status better.
Steve Howellc693ae8982c1
diff --git a/tools/check-schemas b/tools/check-schemasindex 4bc53d2e718..a986b67c260 100755--- a/tools/check-schemas+++ b/tools/check-schemas@@ -64,13 +64,6 @@ from zerver.lib.data_types import ()from zerver.openapi.openapi import openapi_spec-SKIP_LIST = [- # The event_schema checker for user_status is overly strict.- "user_status__revoke_away",- "user_status__set_away",- "user_status__set_status_text",-]-# This list of exemptions represents details we should fix in Zulip's# API structure and/or validators.EXEMPT_OPENAPI_NAMES = [@@ -232,9 +225,6 @@ def run() -> None:fixtures = read_fixtures()verify_fixtures_are_sorted(list(fixtures.keys()))for name, event in fixtures.items():- if name in SKIP_LIST:- print(f"skip {name}")- continuecheck_event(name, event)validate_openapi_against_event_schema()diff --git a/zerver/lib/event_schema.py b/zerver/lib/event_schema.pyindex 8ff7d5fff3a..f17810557e6 100644--- a/zerver/lib/event_schema.py+++ b/zerver/lib/event_schema.py@@ -27,7 +27,7 @@# See check_delete_message and check_presence for examples of this# paradigm.-from typing import Dict, List, Sequence, Tuple, Union+from typing import Dict, List, Sequence, Set, Tuple, Unionfrom zerver.lib.data_types import (DictType,@@ -1527,10 +1527,21 @@ def check_user_group_update(user_status_event = event_dict_type(required_keys=[+ # force vertical("type", Equals("user_status")),("user_id", int),+ ],+ optional_keys=[+ # force vertical("away", bool),("status_text", str),])-check_user_status = make_checker(user_status_event)+_check_user_status = make_checker(user_status_event)++def check_user_status(+ var_name: str, event: Dict[str, object], fields: Set[str]+) -> None:+ _check_user_status(var_name, event)++ assert set(event.keys()) == {"id", "type", "user_id"} | fieldsdiff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.pyindex 5196fc2fcdb..20bc0f3af99 100644--- a/zerver/tests/test_events.py+++ b/zerver/tests/test_events.py@@ -816,7 +816,7 @@ class NormalActionsTest(BaseAction):status_text='out to lunch',client_id=client.id))- check_user_status('events[0]', events[0])+ check_user_status("events[0]", events[0], {"away", "status_text"})events = self.verify_action(lambda: do_update_user_status(@@ -825,7 +825,25 @@ class NormalActionsTest(BaseAction):status_text='',client_id=client.id))- check_user_status('events[0]', events[0])+ check_user_status("events[0]", events[0], {"away", "status_text"})++ events = self.verify_action(+ lambda: do_update_user_status(+ user_profile=self.user_profile,+ away=True,+ status_text=None,+ client_id=client.id))++ check_user_status("events[0]", events[0], {"away"})++ events = self.verify_action(+ lambda: do_update_user_status(+ user_profile=self.user_profile,+ away=None,+ status_text="at the beach",+ client_id=client.id))++ check_user_status("events[0]", events[0], {"status_text"})def test_user_group_events(self) -> None:othello = self.example_user('othello')