mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 06:53:25 +00:00
event_schema: Extract check_subscription_remove.
This commit is contained in:
@@ -230,3 +230,20 @@ def check_subscription_add(
|
|||||||
assert "subscribers" in sub.keys()
|
assert "subscribers" in sub.keys()
|
||||||
else:
|
else:
|
||||||
assert "subscribers" not in sub.keys()
|
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)),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ from zerver.lib.event_schema import (
|
|||||||
check_stream_create,
|
check_stream_create,
|
||||||
check_stream_update,
|
check_stream_update,
|
||||||
check_subscription_add,
|
check_subscription_add,
|
||||||
|
check_subscription_remove,
|
||||||
)
|
)
|
||||||
from zerver.lib.events import apply_events, fetch_initial_state_data, post_process_state
|
from zerver.lib.events import apply_events, fetch_initial_state_data, post_process_state
|
||||||
from zerver.lib.markdown import MentionData
|
from zerver.lib.markdown import MentionData
|
||||||
@@ -2566,16 +2567,6 @@ class SubscribeActionTest(BaseAction):
|
|||||||
self.do_test_subscribe_events(include_subscribers=False)
|
self.do_test_subscribe_events(include_subscribers=False)
|
||||||
|
|
||||||
def do_test_subscribe_events(self, include_subscribers: bool) -> None:
|
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([
|
peer_add_schema_checker = check_events_dict([
|
||||||
('type', equals('subscription')),
|
('type', equals('subscription')),
|
||||||
('op', equals('peer_add')),
|
('op', equals('peer_add')),
|
||||||
@@ -2627,7 +2618,12 @@ class SubscribeActionTest(BaseAction):
|
|||||||
action,
|
action,
|
||||||
include_subscribers=include_subscribers,
|
include_subscribers=include_subscribers,
|
||||||
num_events=3)
|
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 stream
|
# Now resubscribe a user, to make sure that works on a vacated stream
|
||||||
action = lambda: self.subscribe(self.example_user("hamlet"), "test_stream")
|
action = lambda: self.subscribe(self.example_user("hamlet"), "test_stream")
|
||||||
|
|||||||
Reference in New Issue
Block a user