Exemplo n.º 1
0
def test_search_1(reset):
    '''
    can search a variety of strings sent by different users
    in a multitude of channels of which the auth user is part
    '''
    j_token = register("*****@*****.**",
                       "paris in the rain", "Josh", "Wang")[1]
    k_token = register("*****@*****.**", "pianoforte", "Ken", "Li")[1]
    i_token = register("*****@*****.**",
                       "ilovetrimesters", "Ian", "Jacobs")[1]

    ch_id1 = channels_create(j_token, "channel1", True)
    ch_id2 = channels_create(k_token, "channel2", True)
    ch_id3 = channels_create(i_token, "channel3", True)

    channel_join(j_token, ch_id2)
    channel_join(k_token, ch_id3)

    message_send(j_token, ch_id1, "Cat get down!")
    message_send(k_token, ch_id2, "this is the category")
    message_send(i_token, ch_id3, "cataracts are bad for your eyes")
    message_send(j_token, ch_id2, "scathe hat bat shat in the lsadfkl")
    message_send(j_token, ch_id2, "token")
    message_send(k_token, ch_id3, "a;sdkjf;lasdjf;lj 3wioru cate")

    assert len(search(j_token, "cat")["messages"]) == 2
    assert len(search(k_token, "cat")["messages"]) == 4
    assert len(search(i_token, "cat")["messages"]) == 2
Exemplo n.º 2
0
def test_message_pin_not_owner_tries():
    c_token = register('*****@*****.**', 'ssap12652', 'Chen', 'Bee')[1]
    channel_join(c_token, 1)
    msg1_id = message_send(c_token, 1, 'My own message')

    with pytest.raises(HTTPError):
        message_pin(c_token, msg1_id)
    logout(c_token)
Exemplo n.º 3
0
def test_message_unreact_not_in_channel():
    c_token = register('*****@*****.**', 'ssap12652', 'Chen', 'Bee')[1]
    channel_join(c_token, 1)
    msg1_id = message_send(c_token, 1, 'I am new here.')
    message_react(c_token, msg1_id, 1)
    channel_leave(c_token, 1)
    with pytest.raises(HTTPError):
        message_unreact(c_token, 1, 1)
    logout(c_token)
Exemplo n.º 4
0
def test_message_pin_owner_pins_user():
    a_token = login('*****@*****.**', 'pass123456')[1]
    k_token = register('*****@*****.**', 'kenis123', 'Ken', 'Li')[1]
    channel_join(k_token, 1)
    msg1_id = message_send(k_token, 1, 'User message')
    # user a pins user k's message
    message_pin(a_token, msg1_id)

    msg_list = channel_messages(a_token, 1, 0)[0]
    assert msg_list[0]['is_pinned'] and msg_list[1]['is_pinned']
    logout(a_token)
    logout(k_token)
Exemplo n.º 5
0
def test_message_unpin_not_channel_owner(reset):
    a_token = register('*****@*****.**', 'pass123456', 'Admin', 'Heeblo')[1]
    channel_id = channels_create(a_token, 'test_public', True)
    msg0_id = message_send(a_token, channel_id, 'Pin this message')
    # pins the message
    message_pin(a_token, msg0_id)

    # make another user who is part of channel but not owner nor slackr owner
    u_token = register('*****@*****.**', 'usersweakpw', 'Bob', 'Builder')[1]
    channel_join(u_token, channel_id)

    with pytest.raises(HTTPError):
        message_unpin(u_token, msg0_id)
    logout(a_token)
Exemplo n.º 6
0
def test_join_channel_logged_out(reset):
    _, reg_token = register('*****@*****.**', 'wubbalubba', 'Max', 'Smith')
    logout(reg_token)
    owner_token = login('*****@*****.**', 'wubbalubba')[1]
    channel_id = channels_create(owner_token, 'Maxs Channel', is_public=True)
    success = logout(owner_token)
    assert success == True

    _, reg_token = register('*****@*****.**', 'wubbalubba', 'Mike', 'Smith')
    logout(reg_token)
    user_token = login('*****@*****.**', 'wubbalubba')[1]
    logout(user_token)

    with pytest.raises(HTTPError):
        channel_join(user_token, channel_id)
Exemplo n.º 7
0
def test_user_remove_removed_from_channels(reset):
    '''
    removing a user should remove him from all channels he has joined
    '''
    _, admin_token = register(
        '*****@*****.**', 'HelloWorld', 'Yousif', 'Wang')
    u_id, u_token = register('*****@*****.**', 'HelloWorld123', 'Josh', 'Wang')
    # admin creates a channel
    channel_id = channels_create(admin_token, 'Da channel', is_public=True)
    # joining..
    channel_join(u_token, channel_id)
    # new user is removed
    user_remove(admin_token, u_id)
    # should only contain the admin now
    _, _, all_membs = channel_details(admin_token, channel_id)
    # 2 members since we have a hangman bot in each channel
    assert len(all_membs) == 2
Exemplo n.º 8
0
def test_message_edit_reject_permission(reset):
    j_token = register("*****@*****.**", "1234566", "Josh", "Wang")[1]
    k_token = register("*****@*****.**", "jludagsfhjkliopasdf", "Ken", "Li")[1]
    i_token = register("*****@*****.**", "aslkdfjwe", "Ian", "Jacobs")[1]
    l_token = register("*****@*****.**", "ajsoqefdas", "Lloyd", "Freeman")[1]

    ch_id = channels_create(k_token, "new_channel", True)
    channel_join(i_token, ch_id)
    channel_join(l_token, ch_id)

    msg_id = message_send(l_token, ch_id, "This is a message")

    message_edit(j_token, msg_id, "Josh is a slack owner and can edit")
    message_edit(k_token, msg_id, "Ken is a channel owner and can edit")
    message_edit(l_token, msg_id, "Lloyd wrote the message and cand edit")

    with pytest.raises(HTTPError):
        message_edit(i_token, msg_id,
                     "Ian was not involved and cannot edit for once")
Exemplo n.º 9
0
def test_user_remove_removed_message(reset):
    '''
    A removed user has all the messages he has sent removed
    '''
    _, admin_token = register(
        '*****@*****.**', 'HelloWorld', 'Yousif', 'Wang')
    u_id, u_token = register('*****@*****.**', 'HelloWorld123', 'Josh', 'Wang')
    # admin creates a channel
    channel_id = channels_create(admin_token, 'Da channel', is_public=True)
    # joining..
    channel_join(u_token, channel_id)
    # send a message
    message_send(u_token, channel_id, 'HelloWorld')
    # new user is removed
    user_remove(admin_token, u_id)
    # their message should be removed from the channel
    messages, _, _ = channel_messages(admin_token, channel_id, start=0)
    # the reason we assert 1 is because the hangman sends a message at the
    # start of channel
    assert len(messages) == 1
Exemplo n.º 10
0
def test_standup_send_two_messages(reset):
    '''
    A valid request to send two messages to a standup
    '''
    my_id, my_token = register(
        '*****@*****.**', '1231FFF!', 'Yousif', 'Khalid')
    user_token = register('*****@*****.**',
                          '2222!!!!', 'Jack', 'Robbers')[1]
    # creating a channel
    channel_id = channels_create(my_token, 'Yousifs Channel', is_public=True)
    # other user joins
    channel_join(user_token, channel_id)
    # starting a standup by me
    standup_start(my_token, channel_id, length=3)
    # message sent by me
    standup_send(my_token, channel_id, 'Actually my first message?')
    # message sent by another guy
    standup_send(user_token, channel_id, 'Jacks message!')
    time.sleep(3.1)
    messages = channel_messages(my_token, channel_id, start=0)[0]
    assert messages[0]['message'] == 'Actually my first message?\nJacks message!'
    assert messages[0]['u_id'] == my_id