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
def test_users_all_data_missing(reset): ''' Invalid requesting missing some data ''' register("*****@*****.**", "paris in the rain", "Josh", "Wang") register("*****@*****.**", "pianoforte", "Ken", "Li") with pytest.raises(HTTPError): urllib.request.urlopen(urls.USERS_ALL_URL)
def test_user_remove_invalid_token(reset): ''' test sending an invalid token ''' _, token = register('*****@*****.**', 'HelloWorld', 'Yousif', 'Wang') u_id, _ = register('*****@*****.**', 'HelloWorld123', 'Josh', 'Wang') with pytest.raises(HTTPError): user_remove(token + 'a', u_id)
def test_users_all_invalid_token(reset): ''' Invalid request with invalid token ''' j_token = register("*****@*****.**", "paris in the rain", "Josh", "Wang")[1] register("*****@*****.**", "asd;fkljas;dfljklas;df", "Ken", "Li") with pytest.raises(HTTPError): users_all(j_token + 'x')
def test_user_remove_invalid_u_id(reset): ''' removing a user who does not exist ''' admin_id, token = register( '*****@*****.**', 'HelloWorld', 'Yousif', 'Wang') u_id, _ = register('*****@*****.**', 'HelloWorld123', 'Josh', 'Wang') with pytest.raises(HTTPError): user_remove(token, u_id + admin_id)
def test_userpermission_change_invalid_token(reset): ''' Invalid request with invalid token ''' j_token = register("*****@*****.**", "paris in the rain", "Josh", "Wang")[1] k_id = register("*****@*****.**", "asd;fkljas;dfljklas;df", "Ken", "Li")[0] with pytest.raises(HTTPError): userpermission_change(j_token + 'x', k_id, 1)
def test_user_profile_setemail_reject_nonunique(reset): ''' handle is used by someone else ''' j_token = register("*****@*****.**", "cre4t1v3p4s5", "Joshua", "Wang")[1] register("*****@*****.**", "IAMAMUSICIAN", "Ken", "Li") with pytest.raises(HTTPError): user_profile_sethandle(j_token, "kenli")
def test_message_sendlater_not_in_channel(reset): ''' Testing requesting to send message later when not in channel ''' a_token = register('*****@*****.**', 'pass123456', 'Alan', 'Brown')[1] channel_id = channels_create(a_token, 'test_public', True) k_token = register('*****@*****.**', 'kenis123', 'Ken', 'Li')[1] with pytest.raises(HTTPError): message_sendlater(k_token, channel_id, 'Bad message', time.time() + 1) logout(a_token)
def test_userpermission_change_not_owner(reset): ''' Invalid request where a person who is not an admin tries request change ''' # this user is the owner j_id = register("*****@*****.**", "paris in the rain", "Josh", "Wang")[0] k_token = register( "*****@*****.**", "pianoforte", "Ken", "Li")[1] # normal member with pytest.raises(HTTPError): userpermission_change(k_token, j_id, 2)
def test_user_permission_change_invalid_permission(reset): ''' permission_id not a valid permission ''' # this user is the owner j_token = register("*****@*****.**", "paris in the rain", "Josh", "Wang")[1] k_id = register( "*****@*****.**", "pianoforte", "Ken", "Li")[0] # normal member with pytest.raises(HTTPError): userpermission_change(j_token, k_id, 3)
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)
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)
def test_login_multiple_users(reset): reg_token = register('*****@*****.**', 'wubbalubba', 'Max', 'Smith')[1] logout(reg_token) log_token = login('*****@*****.**', 'wubbalubba')[1] logout(log_token) reg_token = register('*****@*****.**', 'wubbalubba', 'Bob', 'Smith')[1] logout(reg_token) log_token = login('*****@*****.**', 'wubbalubba')[1] logout(log_token) reg_token = register('*****@*****.**', 'wubbalubba', 'Mike', 'Smith')[1] logout(reg_token) log_token = login('*****@*****.**', 'wubbalubba')[1] logout(log_token)
def test_message_unpin_slackr_owner_not_in_channel(reset): a_token = register('*****@*****.**', 'pass123456', 'Admin', 'Heeblo')[1] k_token = register('*****@*****.**', 'kenis123', 'Ken', 'Li')[1] # ken creates a channel k_channel_id = channels_create(k_token, 'test_public', True) msg0_id = message_send(k_token, k_channel_id, 'Kens message in his channel') message_pin(k_token, msg0_id) # admin unpins the message sent by ken message_unpin(a_token, msg0_id) msg_list = channel_messages(k_token, k_channel_id, 0)[0] assert not msg_list[0]['is_pinned'] logout(a_token) logout(k_token)
def test_login_user(reset): reg_token = register('*****@*****.**', 'wubbalubba', 'Max', 'Smith')[1] logout(reg_token) login_token = login('*****@*****.**', 'wubbalubba')[1] assert reg_token == login_token success = logout(login_token) assert success == True
def test_user_remove_own(reset): ''' Invalid request to remove one's ownself ''' admin_info, admin_token = register( '*****@*****.**', 'HelloWorld', 'Yousif', 'Wang') with pytest.raises(HTTPError): user_remove(admin_token, admin_info)
def test_message_unpin_not_pinned(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, 'Not pinned message') with pytest.raises(HTTPError): message_unpin(a_token, msg0_id) logout(a_token)
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)
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_user_profile_setemail_reject_invalid(reset): ''' reject if not valid email ''' j_token = register("*****@*****.**", "cre4t1v3p4s5", "Joshua", "Wang")[1] with pytest.raises(HTTPError): user_profile_setemail(j_token, "[email protected] m")
def test_user_profile_setname_last_over_50(reset): ''' long name ''' j_token = register("*****@*****.**", "cre4t1v3p4s5", "Joshua", "Wang")[1] with pytest.raises(HTTPError): user_profile_setname(j_token, "Freddie", "M" * 51)
def test_user_profile_setname_empty_last(reset): ''' last name empty ''' j_token = register("*****@*****.**", "cre4t1v3p4s5", "Joshua", "Wang")[1] with pytest.raises(HTTPError): user_profile_setname(j_token, "Freddie", "")
def test_userpermission_change_invalid_u_id(reset): ''' invalid request with invalid u_id ''' j_id, j_token = register("*****@*****.**", "paris in the rain", "Josh", "Wang") with pytest.raises(HTTPError): userpermission_change(j_token, j_id + 1, 1)
def test_message_unreact_no_existing_react(reset): a_token = register('*****@*****.**', 'pass123456', 'Admin', 'Heeblo')[1] channels_create(a_token, 'test_public', True) msg0_id = message_send(a_token, 1, 'I am new here.') with pytest.raises(HTTPError): message_unreact(a_token, msg0_id, 1) logout(a_token)
def test_user_profile_sethandle_invalid_token(reset): ''' invalid request with invalid token ''' j_token = register("*****@*****.**", "cre4t1v3p4s5", "Joshua", "Wang")[1] with pytest.raises(HTTPError): user_profile_sethandle(j_token + 'x', "joshwang234")
def test_channels_listall_empty(reset): # pylint: disable=unused-argument,redefined-outer-name ''' Testing return of empty payload when no channels exist ''' a_token = register('*****@*****.**', 'pass123456', 'Alan', 'Brown')[1] assert channels_listall(a_token) == [] logout(a_token)
def test_message_send_not_in_channel(): ''' Testing requesting to send message when not in channel ''' k_token = register('*****@*****.**', 'kenis123', 'Ken', 'Li')[1] with pytest.raises(HTTPError): message_send(k_token, 1, 'Bad message') logout(k_token)
def test_userpermission_change_demote_own(reset): ''' Invalid request to demote ones ownself ''' admin_id, admin_token = register( '*****@*****.**', 'asdasdasd', 'Yousif', 'Khalid') with pytest.raises(HTTPError): userpermission_change(admin_token, admin_id, 2)
def test_channels_list_empty(reset): # pylint: disable=unused-argument,redefined-outer-name ''' no channels created yet ''' a_token = register('*****@*****.**', 'pass123456', 'Alan', 'Brown')[1] payload = channels_list(a_token) # check the list is empty assert payload == [] logout(a_token)
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)