Ejemplo n.º 1
0
def test_successful_msg_send():
    # a normal msg
    assert msg_send(token1, '1st msg', chan_id1) == {'message_id': 1}
    assert data['channels'][0].messages[0].message_id == 1
    # a msg with 1000 characters
    assert msg_send(token3, long_msg, chan_id1) == {'message_id': 2}
    assert data['channels'][0].messages[0].message_id == 2
    assert len(data['channels'][0].messages) == 2
Ejemplo n.º 2
0
def test_successful_remove():
    # normal remove
    msg_send(token1, '3rd msg', chan_id1)
    msg_id1 = data['channels'][0].messages[0].message_id
    msg_id3 = data['channels'][0].messages[2].message_id
    assert len(data['channels'][0].messages) == 3
    assert msg_remove(token1, msg_id1) == {}
    assert len(data['channels'][0].messages) == 2
    assert msg_remove(token1, msg_id3) == {}
    assert len(data['channels'][0].messages) == 1
Ejemplo n.º 3
0
def test_search():
    #search(token, query_str), returns messages
    #SETUP TESTS BEGIN
    #create new users:
    authRegDict = auth_register("*****@*****.**",
                                "password", "Ben", "Kah")
    token = authRegDict["token"]
    #create channel
    chanCreateDict = channels_create(token, "test channel", True)
    chanId = chanCreateDict["channel_id"]
    channel_join(token, chanId)
    #create messages
    msg_send(token, "New message sent", chanId)
    msg_send(token, "Another message", chanId)
    msg_send(token, "A completely different string", chanId)
    #SETUP TESTS END
    searchResultsList = search(token, "message")  #first search query
    searchResultsList2 = search(token, "nothing to find")  #second search query
    assert searchResultsList["messages"][1][
        "message"] == "New message sent"  #search results should contain these strings
    assert searchResultsList["messages"][0]["message"] == "Another message"
    assert len(searchResultsList["messages"]) == 2
    assert len(searchResultsList2["messages"]) == 0  #list should be empty
Ejemplo n.º 4
0
def route_msg_send():
    token = request.form.get('token')
    msg = request.form.get('message')
    chan_id = int(request.form.get('channel_id'))
    return dumps(msg_send(token, msg, chan_id))
Ejemplo n.º 5
0
def test_successful_edit():
    msg_send(token1, '4th msg', chan_id1)
    msg_id4 = data['channels'][0].messages[0].message_id
    assert msg_edit(token1, msg_id4, 'new 4th msg(edited)') == {}
    assert len(data['channels'][0].messages) == 4
Ejemplo n.º 6
0
def test_remover_notsender():
    # when remover is not the actual sender of the message
    msg_send(token3, '3rd msg', chan_id1)
    msg_id3 = data['channels'][0].messages[2].message_id
    with pytest.raises(AccessError):
        msg_remove(token1, msg_id3)
Ejemplo n.º 7
0
def test_notowner_remove():
    # when remover is not an owner
    msg_send(token3, '2nd msg', chan_id1)
    msg_id2 = data['channels'][0].messages[1].message_id
    with pytest.raises(AccessError):
        msg_remove(token3, msg_id2)
Ejemplo n.º 8
0
def test_sender_notjoined():
    # raise AccessError when a user does not belong to the channel and tring to send
    with pytest.raises(AccessError):
        msg_send(token2, 'hello', chan_id1)
Ejemplo n.º 9
0
def test_msg_too_long():
    # raise ValueError when the message is too long
    with pytest.raises(ValueError):
        msg_send(token1, invalid_msg, chan_id1)