def test_non_existant_topic(self) -> None: test_stream = self.make_stream("Test Public Archives") do_change_stream_web_public(test_stream, True) result = self.client_get( "/archive/streams/" + str(test_stream.id) + "/topics/nonexistenttopic", ) self.assert_in_success_response(["This topic does not exist."], result)
def test_get_web_public_streams(self) -> None: realm = get_realm("zulip") public_streams = get_web_public_streams(realm) self.assert_length(public_streams, 1) public_stream = public_streams[0] self.assertEqual(public_stream["name"], "Rome") info = get_web_public_subs(realm) self.assert_length(info.subscriptions, 1) self.assertEqual(info.subscriptions[0]["name"], "Rome") self.assert_length(info.unsubscribed, 0) self.assert_length(info.never_subscribed, 0) # Now add a second public stream test_stream = self.make_stream("Test Public Archives") do_change_stream_web_public(test_stream, True) public_streams = get_web_public_streams(realm) self.assert_length(public_streams, 2) info = get_web_public_subs(realm) self.assert_length(info.subscriptions, 2) self.assert_length(info.unsubscribed, 0) self.assert_length(info.never_subscribed, 0) self.assertNotEqual(info.subscriptions[0]["color"], info.subscriptions[1]["color"]) do_deactivate_stream(test_stream, acting_user=None) public_streams = get_web_public_streams(realm) self.assert_length(public_streams, 1) info = get_web_public_subs(realm) self.assert_length(info.subscriptions, 1) self.assert_length(info.unsubscribed, 0) self.assert_length(info.never_subscribed, 0)
def test_get_web_public_streams(self) -> None: realm = get_realm("zulip") public_streams = get_web_public_streams(realm) self.assert_length(public_streams, 1) public_stream = public_streams[0] self.assertEqual(public_stream['name'], "Rome") public_subs, public_unsubs, public_neversubs = get_web_public_subs( realm) self.assert_length(public_subs, 1) public_sub = public_subs[0] self.assertEqual(public_sub['name'], "Rome") self.assert_length(public_unsubs, 0) self.assert_length(public_neversubs, 0) # Now add a second public stream test_stream = self.make_stream('Test Public Archives') do_change_stream_web_public(test_stream, True) public_streams = get_web_public_streams(realm) self.assert_length(public_streams, 2) public_subs, public_unsubs, public_neversubs = get_web_public_subs( realm) self.assert_length(public_subs, 2) self.assert_length(public_unsubs, 0) self.assert_length(public_neversubs, 0) self.assertNotEqual(public_subs[0]['color'], public_subs[1]['color']) do_deactivate_stream(test_stream) public_streams = get_web_public_streams(realm) self.assert_length(public_streams, 1) public_subs, public_unsubs, public_neversubs = get_web_public_subs( realm) self.assert_length(public_subs, 1) self.assert_length(public_unsubs, 0) self.assert_length(public_neversubs, 0)
def test_web_public_stream(self) -> None: test_stream = self.make_stream('Test Public Archives') do_change_stream_web_public(test_stream, True) self.send_stream_message(self.example_email("iago"), "Test Public Archives", 'Test Message 3', topic_name='first_topic') self.send_stream_message(self.example_email("iago"), "Test Public Archives", 'Test Message', topic_name='TopicGlobal') self.send_stream_message(self.example_email("iago"), "Test Public Archives", 'Test Message 2', topic_name='topicglobal') self.send_stream_message(self.example_email("iago"), "Test Public Archives", 'Test Message 3', topic_name='second_topic') self.send_stream_message(self.example_email("iago"), "Test Public Archives", 'Test Message 4', topic_name='TopicGlobal') result = self.client_get("/archive/streams/" + str(test_stream.id) + "/topics") self.assert_json_success(result) history = result.json()['topics'] self.assert_length(history, 3) # Should be sorted with latest topic first self.assertEqual(history[0]['name'], 'TopicGlobal') self.assertEqual(history[1]['name'], 'second_topic') self.assertEqual(history[2]['name'], 'first_topic')
def test_get_web_public_streams(self) -> None: realm = get_realm("zulip") public_streams = get_web_public_streams(realm) self.assert_length(public_streams, 1) public_stream = public_streams[0] self.assertEqual(public_stream['name'], "Rome") public_subs, public_unsubs, public_neversubs = get_web_public_subs(realm) self.assert_length(public_subs, 1) public_sub = public_subs[0] self.assertEqual(public_sub['name'], "Rome") self.assert_length(public_unsubs, 0) self.assert_length(public_neversubs, 0) # Now add a second public stream test_stream = self.make_stream('Test Public Archives') do_change_stream_web_public(test_stream, True) public_streams = get_web_public_streams(realm) self.assert_length(public_streams, 2) public_subs, public_unsubs, public_neversubs = get_web_public_subs(realm) self.assert_length(public_subs, 2) self.assert_length(public_unsubs, 0) self.assert_length(public_neversubs, 0) self.assertNotEqual(public_subs[0]['color'], public_subs[1]['color']) do_deactivate_stream(test_stream) public_streams = get_web_public_streams(realm) self.assert_length(public_streams, 1) public_subs, public_unsubs, public_neversubs = get_web_public_subs(realm) self.assert_length(public_subs, 1) self.assert_length(public_unsubs, 0) self.assert_length(public_neversubs, 0)
def test_non_existant_topic(self) -> None: test_stream = self.make_stream('Test Public Archives') do_change_stream_web_public(test_stream, True) result = self.client_get( "/archive/streams/" + str(test_stream.id) + "/topics/nonexistenttopic" ) self.assert_in_success_response(["This topic does not exist."], result)
def test_web_public_stream_topic(self) -> None: test_stream = self.make_stream('Test Public Archives') do_change_stream_web_public(test_stream, True) def send_msg_and_get_result(msg: str) -> HttpResponse: self.send_stream_message(self.example_email("iago"), "Test Public Archives", msg, 'TopicGlobal') return self.client_get("/archive/streams/" + str(test_stream.id) + "/topics/TopicGlobal") result = send_msg_and_get_result('Test Message 1') self.assert_in_success_response(["Test Message 1"], result) result = send_msg_and_get_result('/me goes testing.') self.assert_in_success_response(["goes testing."], result)
def test_web_public_stream(self) -> None: test_stream = self.make_stream('Test Public Archives') do_change_stream_web_public(test_stream, True) self.send_stream_message( self.example_email("iago"), "Test Public Archives", 'Test Message 3', topic_name='first_topic' ) self.send_stream_message( self.example_email("iago"), "Test Public Archives", 'Test Message', topic_name='TopicGlobal' ) self.send_stream_message( self.example_email("iago"), "Test Public Archives", 'Test Message 2', topic_name='topicglobal' ) self.send_stream_message( self.example_email("iago"), "Test Public Archives", 'Test Message 3', topic_name='second_topic' ) self.send_stream_message( self.example_email("iago"), "Test Public Archives", 'Test Message 4', topic_name='TopicGlobal' ) result = self.client_get( "/archive/streams/" + str(test_stream.id) + "/topics" ) self.assert_json_success(result) history = result.json()['topics'] self.assert_length(history, 3) # Should be sorted with latest topic first self.assertEqual(history[0]['name'], 'TopicGlobal') self.assertEqual(history[1]['name'], 'second_topic') self.assertEqual(history[2]['name'], 'first_topic')
def test_web_public_stream(self) -> None: test_stream = self.make_stream("Test Public Archives") do_change_stream_web_public(test_stream, True) self.send_stream_message( self.example_user("iago"), "Test Public Archives", "Test Message 3", topic_name="first_topic", ) self.send_stream_message( self.example_user("iago"), "Test Public Archives", "Test Message", topic_name="TopicGlobal", ) self.send_stream_message( self.example_user("iago"), "Test Public Archives", "Test Message 2", topic_name="topicglobal", ) self.send_stream_message( self.example_user("iago"), "Test Public Archives", "Test Message 3", topic_name="second_topic", ) self.send_stream_message( self.example_user("iago"), "Test Public Archives", "Test Message 4", topic_name="TopicGlobal", ) result = self.client_get( "/archive/streams/" + str(test_stream.id) + "/topics", ) self.assert_json_success(result) history = result.json()["topics"] self.assert_length(history, 3) # Should be sorted with latest topic first self.assertEqual(history[0]["name"], "TopicGlobal") self.assertEqual(history[1]["name"], "second_topic") self.assertEqual(history[2]["name"], "first_topic")
def test_web_public_stream_topic(self) -> None: test_stream = self.make_stream('Test Public Archives') do_change_stream_web_public(test_stream, True) def send_msg_and_get_result(msg: str) -> HttpResponse: self.send_stream_message( self.example_email("iago"), "Test Public Archives", msg, 'TopicGlobal' ) return self.client_get( "/archive/streams/" + str(test_stream.id) + "/topics/TopicGlobal" ) result = send_msg_and_get_result('Test Message 1') self.assert_in_success_response(["Test Message 1"], result) result = send_msg_and_get_result('/me goes testing.') self.assert_in_success_response(["goes testing."], result)
def test_reaction_event_scope(self) -> None: iago = self.example_user("iago") hamlet = self.example_user("hamlet") polonius = self.example_user("polonius") reaction_info = { "emoji_name": "smile", } # Test `invite_only` streams with `!history_public_to_subscribers` and `!is_web_public` stream = self.make_stream( "test_reactions_stream", invite_only=True, history_public_to_subscribers=False ) self.subscribe(iago, stream.name) message_before_id = self.send_stream_message( iago, "test_reactions_stream", "before subscription history private" ) self.subscribe(hamlet, stream.name) self.subscribe(polonius, stream.name) # Hamlet and Polonius joined after the message was sent, and # so only Iago should receive the event. events: List[Mapping[str, Any]] = [] with tornado_redirected_to_list(events): result = self.api_post( iago, f"/api/v1/messages/{message_before_id}/reactions", reaction_info ) self.assert_json_success(result) self.assert_length(events, 1) event = events[0]["event"] self.assertEqual(event["type"], "reaction") event_user_ids = set(events[0]["users"]) self.assertEqual(event_user_ids, {iago.id}) remove = self.api_delete( iago, f"/api/v1/messages/{message_before_id}/reactions", reaction_info ) self.assert_json_success(remove) # Reaction to a Message sent after subscription, should # trigger events for all subscribers (Iago, Hamlet and Polonius). message_after_id = self.send_stream_message( iago, "test_reactions_stream", "after subscription history private" ) events = [] with tornado_redirected_to_list(events): result = self.api_post( iago, f"/api/v1/messages/{message_after_id}/reactions", reaction_info ) self.assert_json_success(result) self.assert_length(events, 1) event = events[0]["event"] self.assertEqual(event["type"], "reaction") event_user_ids = set(events[0]["users"]) self.assertEqual(event_user_ids, {iago.id, hamlet.id, polonius.id}) remove = self.api_delete( iago, f"/api/v1/messages/{message_after_id}/reactions", reaction_info ) self.assert_json_success(remove) # Make stream history public to subscribers do_change_stream_invite_only(stream, False, history_public_to_subscribers=True) # Since stream history is public to subscribers, reacting to # message_before_id should notify all non-guest subscribers: # Iago and Hamlet. events = [] with tornado_redirected_to_list(events): result = self.api_post( iago, f"/api/v1/messages/{message_before_id}/reactions", reaction_info ) self.assert_json_success(result) self.assert_length(events, 1) event = events[0]["event"] self.assertEqual(event["type"], "reaction") event_user_ids = set(events[0]["users"]) self.assertEqual(event_user_ids, {iago.id, hamlet.id}) remove = self.api_delete( iago, f"/api/v1/messages/{message_before_id}/reactions", reaction_info ) self.assert_json_success(remove) # Make stream web_public as well. do_change_stream_web_public(stream, True) # For is_web_public streams, events even on old messages # should go to all subscribers, including guests like polonius. events = [] with tornado_redirected_to_list(events): result = self.api_post( iago, f"/api/v1/messages/{message_before_id}/reactions", reaction_info ) self.assert_json_success(result) self.assert_length(events, 1) event = events[0]["event"] self.assertEqual(event["type"], "reaction") event_user_ids = set(events[0]["users"]) self.assertEqual(event_user_ids, {iago.id, hamlet.id, polonius.id}) remove = self.api_delete( iago, f"/api/v1/messages/{message_before_id}/reactions", reaction_info ) self.assert_json_success(remove) # Private message, event should go to both participants. private_message_id = self.send_personal_message( iago, hamlet, "hello to single reciever", ) events = [] with tornado_redirected_to_list(events): result = self.api_post( hamlet, f"/api/v1/messages/{private_message_id}/reactions", reaction_info ) self.assert_json_success(result) self.assert_length(events, 1) event = events[0]["event"] self.assertEqual(event["type"], "reaction") event_user_ids = set(events[0]["users"]) self.assertEqual(event_user_ids, {iago.id, hamlet.id}) # Group private message; event should go to all participants. huddle_message_id = self.send_huddle_message( hamlet, [polonius, iago], "hello message to muliple reciever", ) events = [] with tornado_redirected_to_list(events): result = self.api_post( polonius, f"/api/v1/messages/{huddle_message_id}/reactions", reaction_info ) self.assert_json_success(result) self.assert_length(events, 1) event = events[0]["event"] self.assertEqual(event["type"], "reaction") event_user_ids = set(events[0]["users"]) self.assertEqual(event_user_ids, {iago.id, hamlet.id, polonius.id})