def test_multiple_channels(channel_user, send_messages): owner = channel_user ch_0_ms_0 = channel_messages(owner['token'], owner['c_id'], 0)['messages'][0] ch_0_ms_1 = channel_messages(owner['token'], owner['c_id'], 0)['messages'][1] # Create another channel which also contains messages public = True c_id_2 = channels_create(owner['token'], "Channel1", public)['channel_id'] # Messages in Channel1 to be used in search message_send(owner['token'], c_id_2, "Channel1 - Message 0") message_send(owner['token'], c_id_2, "Channel1 - Message 1") ch_1_ms_0 = channel_messages(owner['token'], c_id_2, 0)['messages'][0] ch_1_ms_1 = channel_messages(owner['token'], c_id_2, 0)['messages'][1] query_str = "Channel0" search_result = search(owner['token'], query_str) assert search_result == {'messages': [ch_0_ms_0, ch_0_ms_1]} query_str = "Channel1" search_result = search(owner['token'], query_str) assert search_result == {'messages': [ch_1_ms_0, ch_1_ms_1]}
def test_no_channels_joined(): # Register a second user who is not part of the channel auth_register("*****@*****.**", "password", "Firstname", "Lastname") user_2 = auth_login("*****@*****.**", "password") query_str = "Query String" with pytest.raises(AccessError): search(user_2['token'], query_str)
def test_valid_message_unpin_flockr_owner(channel_user_message_pin): owner = channel_user_message_pin message = search(owner['token'], "Test Message 1")['messages'] assert message[0]['is_pinned'] message_unpin(owner['flockr_owner_token'], owner['message_id']) message = search(owner['token'], "Test Message 1")['messages'] assert not message[0]['is_pinned']
def test_message_pin_owner(channel_user_message): owner = channel_user_message message = search(owner['token'], "Test Message 1")['messages'] assert not message[0]['is_pinned'] message_pin(owner['token'], owner['message_id']) message = search(owner['token'], "Test Message 1")['messages'] assert message[0]['is_pinned']
def test_already_pinned(channel_user_message): owner = channel_user_message message = search(owner['token'], "Test Message 1")['messages'] assert not message[0]['is_pinned'] message_pin(owner['token'], owner['message_id']) message = search(owner['token'], "Test Message 1")['messages'] assert message[0]['is_pinned'] # Pin the same message with pytest.raises(InputError): message_pin(owner['token'], owner['message_id'])
def test_sentence_matches(channel_user, send_messages): owner = channel_user message_0 = channel_messages(owner['token'], owner['c_id'], 0)['messages'][0] message_1 = channel_messages(owner['token'], owner['c_id'], 0)['messages'][1] query_str = "Channel0 - Message" search_result = search(owner['token'], query_str) assert search_result == {'messages': [message_0]} query_str = "Message 1!" search_result = search(owner['token'], query_str) assert search_result == {'messages': [message_1]}
def test_word_matches(channel_user, send_messages): owner = channel_user message_0 = channel_messages(owner['token'], owner['c_id'], 0)['messages'][0] message_1 = channel_messages(owner['token'], owner['c_id'], 0)['messages'][1] query_str = "channel" search_result = search(owner['token'], query_str) assert search_result == {'messages': [message_0, message_1]} query_str = "message" search_result = search(owner['token'], query_str) assert search_result == {'messages': [message_0, message_1]}
def test_whitespace_query_str(channel_user): owner = channel_user query_str_space = " " with pytest.raises(InputError): search(owner['token'], query_str_space)
def test_empty_query_str(channel_user): owner = channel_user query_str_empty = "" with pytest.raises(InputError): search(owner['token'], query_str_empty)
def test_invalid_token(): query_str = "Query String" with pytest.raises(AccessError): search(token_hash(1), query_str)
def test_no_matches(channel_user, send_messages): owner = channel_user query_str = "No matches related to search" with pytest.raises(InputError): search(owner['token'], query_str)
def other_search_flask(): token = request.args.get('token') query_str = request.args.get('query_str') return dumps(o.search(token, query_str))