def test_search_not_in_channel(user_1, user_2, public_channel_1):
    """Test searching messages when the user is not part of the channel.
    """
    query_str = "ZzZ"
    message.message_send(user_1['token'], public_channel_1['channel_id'], query_str)
    msg_list = search(user_2['token'], query_str)
    assert len(msg_list['messages']) == 0
    clear()
def test_search_leave_channel(user_1, public_channel_1):
    """Test searching messages when user has left channel the channel
    """
    query_str = "ZzZ"
    message.message_send(user_1['token'], public_channel_1['channel_id'], query_str)
    channel.channel_leave(user_1['token'], public_channel_1['channel_id'])
    msg_list = search(user_1['token'], query_str)
    assert len(msg_list['messages']) == 0
    clear()
def test_search_no_match(user_1, public_channel_1):
    """Test searching messages with 0 results
    """
    message_str_1 = "Welcome to group 1!"
    query_str = "ZzZ"
    message.message_send(user_1['token'], public_channel_1['channel_id'], message_str_1)
    msg_list = search(user_1['token'], query_str)
    assert len(msg_list['messages']) == 0
    clear()
Пример #4
0
def route_message_send():
    """Send a message from authorised_user to the channel specified by channel_id

    Args:
        token (string)
        channel_id (int)
        message (string)

    Returns:
        (dict): { message_id }
    """
    payload = request.get_json()
    channel_id = int(payload['channel_id'])
    try:
        return dumps(
            message.message_send(payload['token'], channel_id,
                                 payload['message']))
    except (InputError, AccessError) as e:
        return e
def create_messages(user, channel_id, i, j):
    """Sends n messages to the channel with channel_id in channel_data

    Args:
        user (dict): { u_id, token }
        channel_data (dict): { channel_id }
        i (int): start of a message string
        j (int): end of a message string

    Returns:
        (dict): { messages }
    """
    result = []
    for index in range(i, j):
        time = int(datetime.now(tz=timezone.utc).timestamp())
        message_info = message_send(user['token'], channel_id, f"{index}")
        result.insert(
            0, {
                'message_id': message_info['message_id'],
                'u_id': user['u_id'],
                'message': f"{index}",
                'time_created': time,
            })
    return result
def thumbs_down_default_message(user_1, public_channel_1):
    payload = message.message_send(user_1['token'], public_channel_1['channel_id'], "Hey channel!")
    message.message_react(user_1['token'], payload['message_id'], THUMBS_DOWN)
    return payload
def default_message(user_1, public_channel_1):
    return message.message_send(user_1['token'], public_channel_1['channel_id'], "Hey channel!")
def test_search_standard(user_1, user_2, user_3, user_4, public_channel_1, public_channel_2, public_channel_3, public_channel_4):
    """Test searching messages in multiple channels
    """
    message_str_1 = "Welcome to group 1!"
    message_str_2 = "Welcome to group 2!"
    message_str_3 = "Welcome to group 3!"
    message_str_4 = "Welcome to group 4!"
    message_str_5 = "Hiya guys!"
    message_str_6 = "sup"
    message_str_7 = "Let's get down to business!"
    query_str = "Welcome"
    channel.channel_join(user_1['token'], public_channel_2['channel_id'])
    channel.channel_join(user_1['token'], public_channel_3['channel_id'])
    channel.channel_join(user_1['token'], public_channel_4['channel_id'])
    message.message_send(user_1['token'], public_channel_1['channel_id'], message_str_1)
    message.message_send(user_2['token'], public_channel_2['channel_id'], message_str_2)
    message.message_send(user_3['token'], public_channel_3['channel_id'], message_str_3)
    message.message_send(user_4['token'], public_channel_4['channel_id'], message_str_4)
    message.message_send(user_1['token'], public_channel_1['channel_id'], message_str_5)
    message.message_send(user_1['token'], public_channel_2['channel_id'], message_str_6)
    message.message_send(user_1['token'], public_channel_2['channel_id'], message_str_7)
    msg_list = search(user_1['token'], query_str)
    msg_count = 0
    msg_cmp_2 = []
    for msg in msg_list['messages']:
        msg_cmp_2.append(msg['message'])
        msg_count += 1
    assert msg_count == 4
    msg_cmp_1 = [message_str_1, message_str_2, message_str_3, message_str_4]
    msg_cmp_1.sort()
    msg_cmp_2.sort()
    assert msg_cmp_1 == msg_cmp_2
    clear()