Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
event_schema: Extract check_subscription_remove.
Steve Howell502f1b9fe204
diff --git a/zerver/lib/event_schema.py b/zerver/lib/event_schema.pyindex 22e5d7cccce..b1f7cad166c 100644--- a/zerver/lib/event_schema.py+++ b/zerver/lib/event_schema.py@@ -230,3 +230,20 @@ def check_subscription_add(assert "subscribers" in sub.keys()else:assert "subscribers" not in sub.keys()+++_check_remove_sub = check_dict_only(+ required_keys=[+ # We should eventually just return stream_id here.+ ("name", check_string),+ ("stream_id", check_int),+ ]+)++check_subscription_remove = check_events_dict(+ required_keys=[+ ("type", equals("subscription")),+ ("op", equals("remove")),+ ("subscriptions", check_list(_check_remove_sub)),+ ]+)diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.pyindex 08a3df74283..ddb43435f97 100644--- a/zerver/tests/test_events.py+++ b/zerver/tests/test_events.py@@ -96,6 +96,7 @@ from zerver.lib.event_schema import (check_stream_create,check_stream_update,check_subscription_add,+ check_subscription_remove,)from zerver.lib.events import apply_events, fetch_initial_state_data, post_process_statefrom zerver.lib.markdown import MentionData@@ -2566,16 +2567,6 @@ class SubscribeActionTest(BaseAction):self.do_test_subscribe_events(include_subscribers=False)def do_test_subscribe_events(self, include_subscribers: bool) -> None:- remove_schema_checker = check_events_dict([- ('type', equals('subscription')),- ('op', equals('remove')),- ('subscriptions', check_list(- check_dict_only([- ('name', equals('test_stream')),- ('stream_id', check_int),- ]),- )),- ])peer_add_schema_checker = check_events_dict([('type', equals('subscription')),('op', equals('peer_add')),@@ -2627,7 +2618,12 @@ class SubscribeActionTest(BaseAction):action,include_subscribers=include_subscribers,num_events=3)- remove_schema_checker('events[0]', events[0])+ check_subscription_remove('events[0]', events[0])+ self.assertEqual(len(events[0]['subscriptions']), 1)+ self.assertEqual(+ events[0]['subscriptions'][0]['name'],+ 'test_stream',+ )# Now resubscribe a user, to make sure that works on a vacated streamaction = lambda: self.subscribe(self.example_user("hamlet"), "test_stream")