def test_multi_channel_dm_and_messages_half_involved(reg_user, crt_channel, crt_dm, send_msg, involvement): clear_v2() user_1_token = reg_user(0)['token'] user_2 = reg_user(1) user_2_token = user_2['token'] user_2_id = user_2['auth_user_id'] crt_count = 10 for _ in range(crt_count): # User is involved in half of all activities inv_channel_id = crt_channel(user_1_token)['channel_id'] uninv_channel_id = crt_channel(user_2_token)['channel_id'] crt_dm(user_1_token, [user_2_id]) crt_dm(user_2_token, [user_2_id]) send_msg(user_1_token, inv_channel_id) send_msg(user_2_token, uninv_channel_id) user_stats = user_stats_v1(user_1_token)['user_stats'] inv = involvement(crt_count, crt_count, crt_count, 2 * crt_count, 2 * crt_count, 2 * crt_count) assert user_stats['channels_joined'][-1][ 'num_channels_joined'] == crt_count assert user_stats['dms_joined'][-1]['num_dms_joined'] == crt_count assert user_stats['messages_sent'][-1]['num_messages_sent'] == crt_count assert user_stats['involvement_rate'] == inv
def test_search_v2_token(reg_user): clear_v2() query_str = 'x' * 200 reg_user(0) fake_token = 'random values r32fecaswd' with pytest.raises(AccessError): search_v2(fake_token, query_str)
def test_non_existent_channel_id(reg_user, crt_channel): # Give invalid channel id clear_v2() user_token = reg_user(0)['token'] channel_id = crt_channel(user_token, True)['channel_id'] with pytest.raises(InputError): channel_details_v2(user_token, channel_id + 1)
def test_multi_channel_dm_and_messages_all_involved(reg_user, crt_channel, crt_dm, send_msg, involvement): clear_v2() user = reg_user(0) token = user['token'] user_id = user['auth_user_id'] crt_count = 10 for _ in range(crt_count): channel_id = crt_channel(token)['channel_id'] crt_dm(token, [user_id]) send_msg(token, channel_id) user_stats = user_stats_v1(token)['user_stats'] inv = involvement(crt_count, crt_count, crt_count, crt_count, crt_count, crt_count) assert user_stats['channels_joined'][-1][ 'num_channels_joined'] == crt_count assert user_stats['dms_joined'][-1]['num_dms_joined'] == crt_count assert user_stats['messages_sent'][-1]['num_messages_sent'] == crt_count assert user_stats['involvement_rate'] == inv
def test_channel_create_v2_token(reg_user, basic_channel_name): clear_v2() reg_user(0)['token'] channel_name = basic_channel_name fake_token = 'random values r32fecaswd' with pytest.raises(AccessError): channels_create_v2(fake_token, channel_name, True)
def test_channel_create_v2_name_greater_than_twenty_characters(reg_user): clear_v2() token_1 = reg_user(0)['token'] channel_name = 'Rip memeber crying room 10000000000000 and there was 3' is_public = True with pytest.raises(InputError): channels_create_v2(token_1, channel_name, is_public) # should not work as channel ....
def test_invalid_token(reg_user, crt_channel, send_message): clear_v2() user_token = reg_user(0)['token'] channel_id = crt_channel(user_token)['channel_id'] message_id = send_message(user_token, channel_id)['message_id'] with pytest.raises(AccessError): message_remove_v1("Invalid token", message_id)
def test_user_not_in_channel(reg_user): clear_v2() auth_user_token = reg_user(0)['token'] channel_list = channels_list_v2(auth_user_token)['channels'] assert len(channel_list) == 0
def test_auth_passwordreset_reset_invalid_reset_code(): clear_v2() auth_register_v2("*****@*****.**", "iteration3", "cameron", "burrell") email = "*****@*****.**" auth_passwordreset_request_v1(email) with pytest.raises(InputError): auth_passwordreset_reset_v1("@#$$**!!", "hdwdssdw111")
def test_nonexistent_message_id(reg_user, crt_channel, send_message): clear_v2() user_token = reg_user(0)['token'] channel_id = crt_channel(user_token)['channel_id'] message_id = send_message(user_token, channel_id)['message_id'] with pytest.raises(InputError): message_remove_v1(user_token, message_id + 1)
def test_commom_more(reg_user): clear_v2() user = reg_user(0) token = user['token'] user_2 = reg_user(1) user_2_id = user_2['auth_user_id'] # more dm id dm1 = dm_create_v1(token, [user_2_id]) dm_id1 = dm1['dm_id'] dm2 = dm_create_v1(token, [user_2_id]) dm_id2 = dm2['dm_id'] dm3 = dm_create_v1(token, [user_2_id]) dm_id3 = dm3['dm_id'] dm_remove_v1(token, dm_id1) dm_remove_v1(token, dm_id2) dm_remove_v1(token, dm_id3) dm_list = dm_list_v1(token)['dms'] assert not len(dm_list) # dm become invaild with pytest.raises(InputError): dm_details_v1(token, dm_id1) with pytest.raises(InputError): dm_details_v1(token, dm_id2) with pytest.raises(InputError): dm_details_v1(token, dm_id3)
def test_message_longer_than_one_thousand(reg_user, crt_channel): clear_v2() message_string = "a" * 1001 user_token = reg_user(0)['token'] channel_id = crt_channel(user_token)['channel_id'] with pytest.raises(InputError): message_send_v2(user_token, channel_id, message_string)
def test_sender_non_channel_member(reg_user, crt_channel, send_message): clear_v2() user_1_token = reg_user(0)['token'] channel_id = crt_channel(user_1_token)['channel_id'] user_2_token = reg_user(1)['token'] with pytest.raises(AccessError): send_message(user_2_token, channel_id, 0)
def test_dm_message_senddm_v1_no_valid_dm_id_found(reg_user, basic_message): clear_v2() token_sender = reg_user(0)['token'] dm_id = 'random values asf3q2vdvdsan cjewqjfqpfd' message = basic_message with pytest.raises(InputError): message_senddm_v1(token_sender, dm_id, message) #invalid dm_id so cant sent a message this will fail
def test_50_messages(reg_user): clear_v2() sender = reg_user(0) token_sender = sender['token'] id_sender = sender['auth_user_id'] auth_user_id_receiver = reg_user(1)['auth_user_id'] dm_id = dm_create_v1(token_sender, [auth_user_id_receiver])['dm_id'] start = 0 message_ids = [] message_count = 50 for i in range(message_count): message = f"Test{i}" message_id = message_senddm_v1(token_sender, dm_id, message)['message_id'] message_ids.append(message_id) message_dict = dm_messages_v1(token_sender, dm_id, start) messages = message_dict['messages'] messages.reverse() # Most recent message should now be last # Reverse for purpose of comparison assert len(messages) == message_count assert message_dict['start'] == start assert message_dict['end'] == -1 for i in range(message_count): message_details = messages[i] assert message_details['message_id'] == message_ids[i] assert message_details['u_id'] == id_sender assert message_details['message'] == f"Test{i}"
def test_more_than_50_messages(reg_user, basic_channel_name): clear_v2() user_1 = reg_user(0) token_1 = user_1['token'] id_1 = user_1['auth_user_id'] channel_name = basic_channel_name channel_id = channels_create_v2(token_1, channel_name, True)['channel_id'] message_count = 51 message_ids = [] for i in range(message_count): message = f"Test{i}" message_id = message_send_v2(token_1, channel_id, message)['message_id'] message_ids.append(message_id) start = 0 message_dict = channel_messages_v2(token_1, channel_id, start) messages = message_dict['messages'] messages.reverse() # Most recent message should now be last # Reverse for purpose of comparison assert len(messages) == message_count - 1 assert message_dict['start'] == start assert message_dict['end'] == 50 for i in range(len(messages)): message_details = messages[i] assert message_details['message_id'] == message_ids[i+1] assert message_details['u_id'] == id_1 assert message_details['message'] == f"Test{i+1}"
def test_logout_then_channels_listall( reg_user): # Ensure that token becomes invalid after logout clear_v2() user_token = reg_user(0)['token'] assert auth_logout_v1(user_token)['is_success'] with pytest.raises(AccessError): channels_listall_v2(user_token)
def test_invalid_token(reg_user): clear_v2() handle_str = 'stresspuppy' with pytest.raises(AccessError): user_profile_sethandle_v1("invalid_token", handle_str)
def test_channel_messages_v2_channel_id_not_valid_non_negative(reg_user): clear_v2() token_1 = reg_user(0)['token'] channel_id = 'garbage values' start = 0 with pytest.raises(InputError): channel_messages_v2(token_1, channel_id, start) #this should not work as channel is not valid
def test_common_case(reg_user, create_channel): clear_v2() # new user new_user = reg_user(0) user_token = new_user['token'] user_id = new_user['auth_user_id'] # new channel channel_id = create_channel(user_token)['channel_id'] # new dm new_dm = dm_create_v1(user_token, [user_id]) dm_id = new_dm['dm_id'] # new message og_message_text = 'Hi !' og_message_id = message_send_v2(user_token, channel_id, og_message_text)['message_id'] shared_message_text = "Hello World !" shared_message_id = message_share_v1(user_token, og_message_id, shared_message_text, channel_id, dm_id)['shared_message_id'] channel_messages = channel_messages_v2(user_token, channel_id, 0)['messages'] for msg in channel_messages: if msg['message_id'] == shared_message_id: assert msg[ 'message'] == f'{shared_message_text}\n\n{og_message_text}'
def test_users_all_v1_multiple(reg_user): clear_v2() u_id_list = [] user_register = reg_user(0) u_id_list.append(user_register['auth_user_id']) for i in range(1, 15): user_register_id = reg_user(i)['auth_user_id'] u_id_list.append(user_register_id) users_info = users_all_v1(user_register['token'])['users'] user_list = [] #make 15 versions of what the infomtion should be for i in range(0, 15): user_dict = {} user_dict['email'] = f"example{i}@email.com" user_dict['firstname'] = f"fname{i}" user_dict['lastname'] = f"lname{i}" user_dict['handle'] = f"fname{i}lname{i}" user_dict[ 'profile_img_url'] = url + 'static/profile_photos/default.jpg' user_list.append(user_dict) #check that they all match for i in range(0, 15): assert users_info[i]['u_id'] in u_id_list assert user_list[i]['email'] == users_info[i]['email'] assert user_list[i]['firstname'] == users_info[i]['name_first'] assert user_list[i]['lastname'] == users_info[i]['name_last'] assert user_list[i]['handle'] == users_info[i]['handle_str'] assert user_list[i]['profile_img_url'] == users_info[i][ 'profile_img_url']
def test_channels_listall_v2_correct(user_details): clear_v2() email, pwd, fName, lName = user_details token = auth_register_v2(email, pwd, fName, lName)['token'] name_1 = "Stress Puppy" name_2 = "Sweet Britney" name_3 = "Small Room" is_public_1 = True is_public_2 = False is_public_3 = False channel_id_1 = channels_create_v2(token, name_1, is_public_1)['channel_id'] channel_id_2 = channels_create_v2(token, name_2, is_public_2)['channel_id'] channel_id_3 = channels_create_v2(token, name_3, is_public_3)['channel_id'] assert channels_listall_v2(token) == { 'channels': [{ 'channel_id': channel_id_1, 'name': name_1 }, { 'channel_id': channel_id_2, 'name': name_2 }, { 'channel_id': channel_id_3, 'name': name_3 }] }
def test_common_case_dm(reg_user, crt_dm): clear_v2() # new user new_user = reg_user(0) user_token = new_user['token'] new_user_2 = reg_user(1) # new channel dm_id = crt_dm(user_token, [new_user_2['auth_user_id']])['dm_id'] # new dm new_dm = crt_dm(user_token, [new_user_2['auth_user_id']]) new_dm_id = new_dm['dm_id'] # new message og_message_text = 'Hi !' og_message_id = message_senddm_v1(user_token, dm_id, og_message_text)['message_id'] shared_message_text = "Hello World !" shared_message_id = message_share_v1(user_token, og_message_id, shared_message_text, -1, new_dm_id)['shared_message_id'] messages = dm_messages_v1(user_token, new_dm_id, 0)['messages'] for msg in messages: if msg['message_id'] == shared_message_id: assert msg[ 'message'] == f'{shared_message_text}\n\n{og_message_text}'
def test_change_non_author_non_dreams_owner_channel_owner( reg_user, create_channel): clear_v2() # new user reg_user( 0 ) # Create first user, who is a dreams owner (for testing purposes, we want non-dreams-owners) new_user = reg_user(1) user_token = new_user['token'] new_user_2 = reg_user(2) # new channel channel_id = create_channel(user_token)['channel_id'] channel_join_v2(new_user_2['token'], channel_id) # new message message_id = message_send_v2(new_user_2['token'], channel_id, "Hi Britney!")['message_id'] message = "Hello World!" message_edit_v2(user_token, message_id, message) messages = channel_messages_v2(user_token, channel_id, 0)['messages'] for msg in messages: if msg['message_id'] == message_id: assert msg['message'] == "Hello World!"
def test_used_email(reg_user, email): clear_v2() user_1_token = reg_user(0)['token'] reg_user(1) user_2_email = email(1) with pytest.raises(InputError): user_profile_setemail_v1(user_1_token, user_2_email)
def test_single_change(reg_user, email): clear_v2() user = reg_user(0) new_email = email(1) user_profile_setemail_v1(user['token'], new_email) user_details = user_profile_v2(user['token'], user['auth_user_id'])['user'] assert user_details['email'] == new_email
def test_channels_listall_v2_no_channel(user_details): clear_v2() email, pwd, fName, lName = user_details token = auth_register_v2(email, pwd, fName, lName)['token'] assert (channels_listall_v2(token) == { 'channels': [] }) # InputError with no channel
def test_invalid_token(reg_user): clear_v2() name_first = "first" name_last = "second" with pytest.raises(AccessError): user_profile_setname_v2("invalid_token", name_first, name_last)
def test_channel_invite_v2_channel_not_exist_non_negative(reg_user): clear_v2() token_1 = reg_user(0)['token'] # this maker of the channel u_id = reg_user(1)['auth_user_id'] # this is the invitee of the channel channel_id = 'garbage values' with pytest.raises(InputError): channel_invite_v2(token_1, channel_id, u_id) # channel_id does not exist
def test_negative_channel_id(reg_user, crt_channel): # Give invalid channel id clear_v2() auth_user_token = reg_user(0)['token'] crt_channel(auth_user_token, True)['channel_id'] joined_user_token = reg_user(1)['token'] with pytest.raises( InputError): # Test negative channel_id (always invalid) assert channel_join_v2(joined_user_token, -1)