Exemplo n.º 1
0
def test_partial_word():
    setupDict = setup()
    message_id = message_send(setupDict['token'], setupDict['channel_id'],
                              'word')
    message_id2 = message_send(setupDict['token'], setupDict['channel_id'],
                               'w0rd')
    searchResult = search(setupDict['token'], 'rd')
    messages = searchResult['messages']
    assert len(messages) == 2
    assert messages[0]['message_id'] == message_id['message_id']
    assert messages[0]['message'] == 'word'
    assert messages[1]['message_id'] == message_id2['message_id']
    assert messages[1]['message'] == 'w0rd'
Exemplo n.º 2
0
def test_different_channels():
    setupDict = setup()
    channel_id = channels_create(setupDict['token'], 'Channel2', True)
    message_id = message_send(setupDict['token'], setupDict['channel_id'],
                              'word')
    message_id2 = message_send(setupDict['token'], channel_id['channel_id'],
                               'w0rd')
    searchResult = search(setupDict['token'], 'rd')
    messages = searchResult['messages']
    assert len(messages) == 2
    assert messages[0]['message_id'] == message_id['message_id']
    assert messages[0]['message'] == 'word'
    assert messages[1]['message_id'] == message_id2['message_id']
    assert messages[1]['message'] == 'w0rd'
def test_search_empty_channel():
    '''
    Test search with a search on an empty channel
    '''
    # Initialising
    global_var.initialise_all()

    # Creating user
    user = auth_register('*****@*****.**', 'password', 'search', 'test')
    token = get_user_token_by_u_id(user["u_id"])

    # Creating channel
    channels_create(token, "chat", True)

    assert search.search(token, 'hey') == {'messages': []}
def test_search_all():
    '''
    Testing search with a search for all messages request
    '''
    # Initialising
    global_var.initialise_all()

    # Creating user
    user = auth_register('*****@*****.**', 'password', 'search', 'test')
    token = get_user_token_by_u_id(user["u_id"])

    # Creating channel
    channel = channels_create(token, "chat", True)
    channel_id = channel["channel_id"]

    # Adding messages to channel
    message_send(token, channel_id, "121")
    message_send(token, channel_id, "321")
    message_send(token, channel_id, "342")
    message_send(token, channel_id, "499")

    # Searching for all messages
    messages = search.search(token, '')

    # Checking if all messages are retrieved
    assert messages["messages"][0]["message"] == "499"
    assert messages["messages"][0]["u_id"] == user["u_id"]
    assert messages["messages"][1]["message"] == "342"
    assert not messages["messages"][1]["is_pinned"]
    assert messages["messages"][2]["message"] == "321"
    assert messages["messages"][3]["message"] == "121"
    assert messages["messages"][3]["reacts"] == [
        {
            "react_id": LIKE_REACT,
            "u_ids": [],
            "is_this_user_reacted": False
        },
        {
            "react_id": HEART_REACT,
            "u_ids": [],
            "is_this_user_reacted": False
        }
    ]

    # Ensuring that no messages after all messages retrieved
    with pytest.raises(IndexError, match="list index out of range"):
        message = messages["messages"][4]
def test_search_single_channel():
    '''
    Testing successful case for search with a channel having two messages
    and returning two messages
    '''

    # Initialising
    global_var.initialise_all()

    # Creating user
    user = auth_register('*****@*****.**', 'password', 'search', 'test')
    token = get_user_token_by_u_id(user["u_id"])

    user2 = auth_register('*****@*****.**', 'password', 'search', 'test')
    token2 = get_user_token_by_u_id(user2["u_id"])

    # Creating channel
    channel = channels_create(token, "chat", True)
    channel_id = channel["channel_id"]

    # Create channel from the second user which the searching user is not a
    # member of
    channels_create(token2, "chat", True)

    # Adding messages to channel
    message_send(token, channel_id, "121")
    message_send(token, channel_id, "321")
    message_send(token, channel_id, "342")
    message_send(token, channel_id, "499")

    # Search
    messages = search.search(token, '21')

    # Checking if messages are obtained
    assert messages["messages"][0]["message"] == "321"
    assert messages["messages"][0]["u_id"] == user["u_id"]
    assert messages["messages"][1]["message"] == "121"

    # Ensuring that no other messages are obtained
    with pytest.raises(IndexError, match="list index out of range"):
        message = messages["messages"][2]
def test_search_no_match():
    '''
    Testing search with a search for no such message
    '''

    # Initialising
    global_var.initialise_all()

    # Creating user
    user = auth_register('*****@*****.**', 'password', 'search', 'test')
    token = get_user_token_by_u_id(user["u_id"])

    # Creating channel
    channel = channels_create(token, "chat", True)
    channel_id = channel["channel_id"]

    # Adding messages to channel
    message_send(token, channel_id, "121")
    message_send(token, channel_id, "321")
    message_send(token, channel_id, "342")
    message_send(token, channel_id, "499")

    assert search.search(token, 'hey') == {'messages': []}