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
def test_standup_send_non_member(reset): ''' Invalid request made by a non-member ''' my_token = register('*****@*****.**', '1231FFF!', 'Yousif', 'Khalid')[1] user_token = register('*****@*****.**', '2222!!!!', 'Jack', 'Robbers')[1] # creating a channel channel_id = channels_create(my_token, 'Yousifs Channel', is_public=True) # 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 with pytest.raises(HTTPError): standup_send(user_token, channel_id, 'Jacks message!')
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")
def test_message_remove_slackr_owner(reset): # slackr owner a_token = register('*****@*****.**', 'pass123456', 'Alan', 'Brown')[1] k_token = register('*****@*****.**', 'kenis123', 'Ken', 'Li')[1] # ken creates a channel channel_id = channels_create(k_token, 'test_public', True) msg0_id = message_send(k_token, channel_id, 'test message in ken channel') message_send(k_token, channel_id, 'test message2 in ken channel') message_remove(a_token, msg0_id) msg_list = channel_messages(k_token, channel_id, 0)[0] assert len(msg_list) == 2 # hangman bot sends a message at the start assert msg_list[0]['message'] == 'test message2 in ken channel' # unremoved message (2nd one sent) retains its ID # hangman bot sends the first msg with id 1 assert msg_list[0]['message_id'] == 3 logout(a_token) logout(k_token)
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
def test_standup_active_ok(reset): ''' Checking if a standup is active inside a channel ''' my_token = register('*****@*****.**', '1231FFF!', 'Yousif', 'Khalid')[1] channel_id = channels_create(my_token, 'Yousifs Channel', is_public=True) finish_time = time.time() + 3 # creating a standup standup_start(my_token, channel_id, length=3) is_active, standup_finish = standup_active(my_token, channel_id) time.sleep(1) # should be active assert is_active assert standup_finish - finish_time < 1 # have to account for delay time.sleep(2) # checking once again => shouldn't be active is_active, standup_finish = standup_active(my_token, channel_id) assert not is_active assert standup_finish is None
def test_standup_send_non_blocking(reset): ''' Testing tinkering with standups does not block other things ''' my_token = register('*****@*****.**', '1231FFF!', 'Yousif', 'Khalid')[1] # creating a channel channel_id = channels_create(my_token, 'Yousifs Channel', is_public=True) # starting a standup by me standup_start(my_token, channel_id, length=3) # message sent by me standup_send(my_token, channel_id, 'should be last message sent pt1') standup_send(my_token, channel_id, 'should be last message sent pt2') message_send(my_token, channel_id, 'should be first message sent') time.sleep(3.1) messages = channel_messages(my_token, channel_id, start=0)[0] # hangman bot sends a message at the creation of the channel assert len(messages) == 3 assert messages[0]['message'] == \ 'should be last message sent pt1\nshould be last message sent pt2'
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