def test_two_tags(): clear_v1() user1 = auth_register_v2("*****@*****.**", "finalpassword", "Eric", "Zheng").json() user2 = auth_register_v2("*****@*****.**", "validpassword", "Josh", "Hatton").json() channel1 = channels_create_v2(user1['token'], 'Channel 1', True).json() channel_join_v2(user2['token'], channel1['channel_id']) msg1str = "@ericzheng @joshhatton" message_send_v2(user1['token'], channel1['channel_id'], msg1str) assert notifications_get_v1(user1['token']).json() == { 'notifications': [{ 'channel_id': channel1['channel_id'], 'dm_id': -1, 'notification_message': f"ericzheng tagged you in Channel 1: {msg1str[0:20]}" }] } assert notifications_get_v1(user2['token']).json() == { 'notifications': [{ 'channel_id': channel1['channel_id'], 'dm_id': -1, 'notification_message': f"ericzheng tagged you in Channel 1: {msg1str[0:20]}" }] }
def test_assorted_notifications(): clear_v1() user1 = auth_register_v2("*****@*****.**", "finalpassword", "Eric", "Zheng").json() user2 = auth_register_v2("*****@*****.**", "validpassword", "Josh", "Hatton").json() channel1 = channels_create_v2(user1['token'], 'Channel 1', True).json() channel_invite_v2(user1['token'], channel1['channel_id'], user2['auth_user_id']) msg1str = "Welcome to the channel @joshhatton" msg1 = message_send_v2(user1['token'], channel1['channel_id'], msg1str).json() message_react_v1(user2['token'], msg1['message_id'], 1) msg2str = "Thanks for having me @ericzheng" msg2 = message_send_v2(user2['token'], channel1['channel_id'], msg2str).json() message_react_v1(user1['token'], msg2['message_id'], 1) assert notifications_get_v1(user1['token']).json() == { 'notifications': [{ 'channel_id': channel1['channel_id'], 'dm_id': -1, 'notification_message': f"joshhatton tagged you in Channel 1: {msg2str[0:20]}" }, { 'channel_id': channel1['channel_id'], 'dm_id': -1, 'notification_message': "joshhatton reacted to your message in Channel 1" }] } assert notifications_get_v1(user2['token']).json() == { 'notifications': [ { 'channel_id': channel1['channel_id'], 'dm_id': -1, 'notification_message': "ericzheng reacted to your message in Channel 1" }, { 'channel_id': channel1['channel_id'], 'dm_id': -1, 'notification_message': f"ericzheng tagged you in Channel 1: {msg1str[0:20]}" }, { 'channel_id': channel1['channel_id'], 'dm_id': -1, 'notification_message': "ericzheng added you to Channel 1" }, ] }
def create_input(): clear_v1() data_test_users = [ auth_register_v2("*****@*****.**", "peterpiper", "Eric", "Zheng").json(), auth_register_v2("*****@*****.**", "maryreider", "Josh", "Hatton").json(), auth_register_v2("*****@*****.**", "globalempire4", "Bunny", "Dong").json(), auth_register_v2("*****@*****.**", "runescape4lyfe", "Dean", "Zworestine").json(), auth_register_v2("*****@*****.**", "iheartnewyork", "Jordan", "Milch").json() ] data_test_channels = [ channels_create_v2(data_test_users[0]['token'], "General", True).json(), channels_create_v2(data_test_users[1]['token'], "Party", True).json(), channels_create_v2(data_test_users[2]['token'], "Private", False).json() ] return [data_test_users, data_test_channels]
def create_input(): clear_v1() data_test_users = [ auth_register_v2("*****@*****.**", "validpassword", "Josh", "Hatton").json(), auth_register_v2("*****@*****.**", "anotherpassword", "Bunny", "Dong").json(), auth_register_v2("*****@*****.**", "password3", "Jordan", "Milch").json(), auth_register_v2("*****@*****.**", "4thpassword", "Dean", "Zworestine").json(), auth_register_v2("*****@*****.**", "finalpassword", "Eric", "Zheng").json(), ] data_test_dms = [ dm_create_v1(data_test_users[0]["token"], [ data_test_users[1]["auth_user_id"], data_test_users[2]["auth_user_id"] ]).json(), dm_create_v1(data_test_users[1]["token"], [data_test_users[3]["auth_user_id"]]).json(), ] return [data_test_users, data_test_dms]
def create_input(): clear_v1() data_test_users = [ auth_register_v2("*****@*****.**", "validpassword", "Josh", "Hatton").json(), auth_register_v2("*****@*****.**", "anotherpassword", "Bunny", "Dong").json(), auth_register_v2("*****@*****.**", "password3", "Jordan", "Milch").json(), auth_register_v2("*****@*****.**", "4thpassword", "Dean", "Zworestine").json(), auth_register_v2("*****@*****.**", "finalpassword", "Eric", "Zheng").json(), ] data_test_channels = [ channels_create_v2(data_test_users[0]["token"], "First Channel", True).json(), channels_create_v2(data_test_users[1]["token"], "Second Channel", True).json(), channels_create_v2(data_test_users[2]["token"], "Third Channel", False).json(), ] channel_join_v2(data_test_users[1]["token"], data_test_channels[0]["channel_id"]) channel_join_v2(data_test_users[2]["token"], data_test_channels[0]["channel_id"]) return [data_test_users, data_test_channels]
def test_mixed_decrement(): clear_v1() result1 = auth_register_v2('*****@*****.**', 'password', 'comp', 'student').json() result2 = auth_register_v2('*****@*****.**', 'password', 'comp', 'student').json() channel1 = channels_create_v2(result1['token'], "The party channel 1", True).json()['channel_id'] message1 = message_send_v2(result1['token'], channel1, 'hello how are you').json()['message_id'] message_remove_v1(result1['token'], message1) channel_join_v2(result2['token'], channel1) channel_leave_v1(result2['token'], channel1) output = user_stats(result1['token']).json() assert output['user_stats']['channels_joined'][-1][ 'num_channels_joined'] == 1 assert output['user_stats']['messages_sent'][-1]['num_messages_sent'] == 1 output1 = user_stats(result2['token']).json() assert output1['user_stats']['channels_joined'][-1][ 'num_channels_joined'] == 0 dreams = users_stats(result1['token']).json() assert dreams['dreams_stats']['channels_exist'][-1][ 'num_channels_exist'] == 1 assert dreams['dreams_stats']['messages_exist'][-1][ 'num_messages_exist'] == 0
def test_message_remove_stat(): clear_v1() result1 = auth_register_v2('*****@*****.**', 'password', 'comp', 'student').json() result2 = auth_register_v2('*****@*****.**', 'password', 'comp', 'student').json() result3 = auth_register_v2('*****@*****.**', 'password', 'comp', 'student').json() dm1 = dm_create_v1( result1['token'], [result2['auth_user_id'], result3['auth_user_id']]).json() message1 = message_senddm_v1(result1['token'], dm1['dm_id'], 'Hello, how are you?').json() message_remove_v1(result1['token'], message1['message_id']) output = user_stats(result1['token']).json() dreams = users_stats(result1['token']).json() assert len(output['user_stats']) == 4 assert output['user_stats']['channels_joined'][-1][ 'num_channels_joined'] == 0 assert output['user_stats']['dms_joined'][-1]['num_dms_joined'] == 1 assert output['user_stats']['messages_sent'][-1]['num_messages_sent'] == 1 assert output['user_stats']['involvement_rate'] == 2 assert len(dreams['dreams_stats']) == 4 assert dreams['dreams_stats']['channels_exist'][-1][ 'num_channels_exist'] == 0 assert dreams['dreams_stats']['dms_exist'][-1]['num_dms_exist'] == 1 assert dreams['dreams_stats']['messages_exist'][-1][ 'num_messages_exist'] == 0 assert dreams['dreams_stats']['utilization_rate'] == 1
def test_no_notifications(): """ Assume that notifications_get_v1 returns an empty dictionary of list when there are no notifiactions to display """ clear_v1() user_1 = auth_register_v2("*****@*****.**", "finalpassword", "Eric", "Zheng").json() user_2 = auth_register_v2("*****@*****.**", "validpassword", "Josh", "Hatton").json() user_3 = auth_register_v2("*****@*****.**", "anotherpassword", "Bunny", "Dong").json() user_4 = auth_register_v2("*****@*****.**", "password3", "Jordan", "Milch").json() user_5 = auth_register_v2("*****@*****.**", "4thpassword", "Dean", "Zworestine").json() assert notifications_get_v1(user_1['token']).json() == { 'notifications': [] } assert notifications_get_v1(user_2['token']).json() == { 'notifications': [] } assert notifications_get_v1(user_3['token']).json() == { 'notifications': [] } assert notifications_get_v1(user_4['token']).json() == { 'notifications': [] } assert notifications_get_v1(user_5['token']).json() == { 'notifications': [] }
def test_message_edit_stat(): clear_v1() result1 = auth_register_v2('*****@*****.**', 'password', 'comp', 'student').json() channel1 = channels_create_v2(result1['token'], "The party channel 1", True).json() message1 = message_send_v2(result1['token'], channel1['channel_id'], 'Hello, how are you?').json() message2 = message_send_v2(result1['token'], channel1['channel_id'], 'Hello, how are you?').json() message_edit_v2(result1['token'], message1['message_id'], 'Hi Im user 1') message_edit_v2(result1['token'], message2['message_id'], '') #message_remove_v1(result1['token'], message2['message_id']) output = user_stats(result1['token']).json() dreams = users_stats(result1['token']).json() assert len(output['user_stats']) == 4 assert output['user_stats']['channels_joined'][-1][ 'num_channels_joined'] == 1 assert output['user_stats']['dms_joined'][-1]['num_dms_joined'] == 0 assert output['user_stats']['messages_sent'][-1]['num_messages_sent'] == 2 assert output['user_stats']['involvement_rate'] == 3 / 2 assert len(dreams['dreams_stats']) == 4 assert dreams['dreams_stats']['channels_exist'][-1][ 'num_channels_exist'] == 1 assert dreams['dreams_stats']['dms_exist'][-1]['num_dms_exist'] == 0 assert dreams['dreams_stats']['messages_exist'][-1][ 'num_messages_exist'] == 1 assert dreams['dreams_stats']['utilization_rate'] == 1
def test_mixed_basic(): clear_v1() result1 = auth_register_v2('*****@*****.**', 'password', 'comp', 'student').json() result2 = auth_register_v2('*****@*****.**', 'password', 'comp', 'student').json() auth_register_v2('*****@*****.**', 'password', 'comp', 'student') channels_create_v2(result1['token'], "The party channel 1", True) channels_create_v2(result1['token'], "The party channel 2", True) dm_create_v1(result1['token'], [result2['auth_user_id']]) output = user_stats(result1['token']).json() dreams = users_stats(result1['token']).json() assert len(output['user_stats']) == 4 assert output['user_stats']['channels_joined'][-1][ 'num_channels_joined'] == 2 assert output['user_stats']['dms_joined'][-1]['num_dms_joined'] == 1 assert output['user_stats']['messages_sent'][-1]['num_messages_sent'] == 0 assert output['user_stats']['involvement_rate'] == 1 assert len(dreams['dreams_stats']) == 4 assert dreams['dreams_stats']['channels_exist'][-1][ 'num_channels_exist'] == 2 assert dreams['dreams_stats']['dms_exist'][-1]['num_dms_exist'] == 1 assert dreams['dreams_stats']['messages_exist'][-1][ 'num_messages_exist'] == 0 assert dreams['dreams_stats']['utilization_rate'] == 2 / 3
def test_successful_remove(create_input): user_1, user_2, user_3, user_4, user_5 = create_input[0] assert admin_user_remove_v1(user_1["token"], user_2["auth_user_id"]).status_code == SUCCESS assert admin_user_remove_v1(user_1["token"], user_3["auth_user_id"]).status_code == SUCCESS assert admin_user_remove_v1(user_1["token"], user_4["auth_user_id"]).status_code == SUCCESS assert admin_user_remove_v1(user_1["token"], user_5["auth_user_id"]).status_code == SUCCESS # check to see that these users are indeed removed # only user_1 should be shown when calling users_all assert users_all_v1(user_1["token"]).json() == { "users": [ user_profile_v2(user_1["token"], user_1["auth_user_id"]).json()["user"] ] } # calling channels list should raise an input error as their u_id's are invalid assert channels_list_v2(user_2["token"]).status_code == ACCESS_ERROR assert channels_list_v2(user_3["token"]).status_code == ACCESS_ERROR assert channels_list_v2(user_4["token"]).status_code == ACCESS_ERROR assert channels_list_v2(user_5["token"]).status_code == ACCESS_ERROR # Check to see each removed user's profile is retrievable and their name is # now 'Removed user' for user in [user_2, user_3, user_4, user_5]: user_profile = user_profile_v2(user_1["token"], user["auth_user_id"]).json() assert type(user_profile) == dict assert ( f"{user_profile['user']['name_first']}{user_profile['user']['name_last']}" == "Removed user" or f"{user_profile['user']['name_first']} {user_profile['user']['name_last']}" == "Removed user") # CHECK THAT MESSAGES SENT ARE 'REMOVED USER' # check channel messages for user 2 channel_join_v2(user_1["token"], create_input[1][1]["channel_id"]) channel_1_messages = channel_messages_v2(user_1["token"], create_input[1][1]["channel_id"], 0).json() for message in channel_1_messages["messages"]: if message["message_id"] == create_input[2][1]: assert message["message"] == "Removed user" # check channel messages for user 3 channel_join_v2(user_1["token"], create_input[1][0]["channel_id"]) channel_2_messages = channel_messages_v2(user_1["token"], create_input[1][0]["channel_id"], 0).json() for message in channel_2_messages["messages"]: if message["message_id"] == create_input[2][2]: assert message["message"] == "Removed user" clear_v1()
def test_invalid_token(): """Raise an access error when the token passed in does not refer to a valid user """ clear_v1() user_1 = auth_register_v2("*****@*****.**", "finalpassword", "Eric", "Zheng").json() user_2 = auth_register_v2("*****@*****.**", "validpassword", "Josh", "Hatton").json() assert admin_user_remove_v1( user_1["token"] + "bug", user_2["auth_user_id"]).status_code == ACCESS_ERROR assert admin_user_remove_v1( user_1["token"] + "yum", user_2["auth_user_id"]).status_code == ACCESS_ERROR assert admin_user_remove_v1( user_1["token"] + "discodisco", user_2["auth_user_id"]).status_code == ACCESS_ERROR assert admin_user_remove_v1( user_1["token"] + "34897", user_2["auth_user_id"]).status_code == ACCESS_ERROR assert admin_user_remove_v1( user_1["token"] + "t", user_2["auth_user_id"]).status_code == ACCESS_ERROR clear_v1()
def test_removed_dms(): """Tests that sent dm messages are now 'Removed user' after the user is removed """ clear_v1() user_1 = auth_register_v2("*****@*****.**", "finalpassword", "Eric", "Zheng").json() user_2 = auth_register_v2("*****@*****.**", "validpassword", "Josh", "Hatton").json() dm_1 = dm_create_v1(user_1["token"], [user_2["auth_user_id"]]).json() message_senddm_v1(user_1["token"], dm_1["dm_id"], "Hello user 2!") message_2 = message_senddm_v1(user_2["token"], dm_1["dm_id"], "Nice to meet you user 1").json() message_senddm_v1(user_2["token"], dm_1["dm_id"], "you are a donkey :)") assert admin_user_remove_v1(user_1["token"], user_2["auth_user_id"]).status_code == SUCCESS dm_1_messages = dm_messages_v1(user_1["token"], dm_1["dm_id"], 0).json() for dm in dm_1_messages["messages"]: if dm["message_id"] == message_2["message_id"]: assert dm["message"] == "Removed user" clear_v1()
def test_invalid_token(): clear_v1() result1 = auth_register_v2('*****@*****.**', 'password', 'comp', 'student').json() auth_register_v2('*****@*****.**', 'password', 'comp', 'student') channels_create_v2(result1['token'], "The party channel 1", True) channels_create_v2(result1['token'], "The party channel 2", True) user_stats('abcdef').status_code == ACCESS_ERROR
def create_input(): clear_v1() users = [ auth_register_v2("*****@*****.**", "validpassword", "Josh", "Hatton").json(), auth_register_v2("*****@*****.**", "anotherpassword", "Bunny", "Dong").json(), auth_register_v2("*****@*****.**", "password3", "Jordan", "Milch").json(), auth_register_v2("*****@*****.**", "4thpassword", "Dean", "Zworestine").json(), auth_register_v2("*****@*****.**", "finalpassword", "Eric", "Zheng").json(), ] channels = [ channels_create_v2(users[0]["token"], "First Channel", True).json()['channel_id'], channels_create_v2(users[1]["token"], "Second Channel", False).json()['channel_id'] ] dms = [ dm_create_v1(users[0]['token'], [users[2]['auth_user_id']]).json()['dm_id'], dm_create_v1(users[1]['token'], [users[3]['auth_user_id'], users[4]['auth_user_id'] ]).json()['dm_id'] ] # Send 5 messages to First Channel channel_1_messages = [] for i in range(0, 5): channel_1_messages.append( message_send_v2( users[0]["token"], channels[0], f"First channel message {i}.").json()['message_id']) # Send 5 messages to Second Channel for i in range(0, 5): message_send_v2(users[1]["token"], channels[1], f"Second channel message {i}.") # Send 5 messages to First DM dm_1_messages = [] for i in range(0, 5): dm_1_messages.append( message_senddm_v1(users[0]["token"], dms[0], f"First dm message {i}.").json()['message_id']) # Send 5 messages to Second DM for i in range(0, 5): message_senddm_v1(users[1]["token"], dms[1], f"Second dm message {i}.") return [users, channels, dms, channel_1_messages, dm_1_messages]
def test_only_owner(): """Raise an input error when the user is currently the only owner""" clear_v1() user_1 = auth_register_v2("*****@*****.**", "finalpassword", "Eric", "Zheng").json() assert admin_user_remove_v1( user_1["token"], user_1["auth_user_id"]).status_code == INPUT_ERROR clear_v1()
def test_remove_from_users_all(): """ Tests that a user is removed from users_all list""" clear_v1() user_1 = auth_register_v2("*****@*****.**", "finalpassword", "Eric", "Zheng").json() user_2 = auth_register_v2("*****@*****.**", "validpassword", "Josh", "Hatton").json() admin_user_remove_v1(user_1["token"], user_2["auth_user_id"]) users = users_all_v1(user_1["token"]).json()["users"] assert user_2["auth_user_id"] not in [u["u_id"] for u in users]
def test_invalid_channel_id_exception(): """ Tests when channel_id does not refer to a valid channel. """ clear_v1() user_1 = auth_register_v2("*****@*****.**", "password34", "Eric", "Zheng").json() user_2 = auth_register_v2("*****@*****.**", "password3", "Jordan", "Milch").json() channel_invite_1 = channel_invite_v2(user_1['token'], 0, user_2['auth_user_id']) channel_invite_2 = channel_invite_v2(user_2['token'], 1, user_1['auth_user_id']) assert channel_invite_1.status_code == INPUT_ERROR assert channel_invite_2.status_code == INPUT_ERROR
def test_exception_priority(): """ When there are multiple errors, an AccessError should be the first one raised for invalid token. """ clear_v1() auth_register_v2("*****@*****.**", "Hihjile", "Eric", "Zheng") user_2 = auth_register_v2("*****@*****.**", "ccas1122", "Joshua", "Hatton").json() user_3 = auth_register_v2("*****@*****.**", "bunnyyipyip", "Bunny", "Dong").json() assert admin_userpermission_change_v1(user_3['token'] + 'bug', user_2['auth_user_id'] + 5, 3).status_code == ACCESS_ERROR
def test_removed_from_dm(): """Tests that a user is removed from a dm""" clear_v1() user_1 = auth_register_v2("*****@*****.**", "finalpassword", "Eric", "Zheng").json() user_2 = auth_register_v2("*****@*****.**", "validpassword", "Josh", "Hatton").json() dm_1 = dm_create_v1(user_1["token"], []).json() dm_invite_v1(user_1["token"], dm_1["dm_id"], user_2["auth_user_id"]) admin_user_remove_v1(user_1["token"], user_2["auth_user_id"]) members = dm_details_v1(user_1["token"], dm_1["dm_id"]).json()["members"] assert user_2["auth_user_id"] not in [m["u_id"] for m in members]
def test_auth_not_owner(): """Raise an access error when the authorised user is not an owner""" clear_v1() # Register the Dreams owner first auth_register_v2("*****@*****.**", "finalpassword", "Eric", "Zheng") user_2 = auth_register_v2("*****@*****.**", "validpassword", "Josh", "Hatton").json() user_3 = auth_register_v2("*****@*****.**", "anotherpassword", "Bunny", "Dong").json() assert admin_user_remove_v1( user_2["token"], user_3["auth_user_id"]).status_code == ACCESS_ERROR assert admin_user_remove_v1( user_3["token"], user_2["auth_user_id"]).status_code == ACCESS_ERROR clear_v1()
def test_removed_from_channel(): """Tests that a user is removed from a channel""" clear_v1() user_1 = auth_register_v2("*****@*****.**", "finalpassword", "Eric", "Zheng").json() user_2 = auth_register_v2("*****@*****.**", "validpassword", "Josh", "Hatton").json() channel_1 = channels_create_v2(user_1["token"], "Test", True).json() channel_join_v2(user_2["token"], channel_1["channel_id"]) admin_user_remove_v1(user_1["token"], user_2["auth_user_id"]) members = channel_details_v2(user_1["token"], channel_1["channel_id"]).json()["all_members"] assert user_2["auth_user_id"] not in [m["u_id"] for m in members]
def test_mixed_harder(): clear_v1() result1 = auth_register_v2('*****@*****.**', 'password', 'comp', 'student').json() result2 = auth_register_v2('*****@*****.**', 'password', 'comp', 'student').json() channel1 = channels_create_v2(result1['token'], "The party channel 1", True).json()['channel_id'] message_send_v2(result1['token'], channel1, 'hello how are you') dm_create_v1(result1['token'], [result2['auth_user_id']]) output = user_stats(result1['token']).json() assert len(output['user_stats']) == 4 assert output['user_stats']['channels_joined'][-1][ 'num_channels_joined'] == 1 assert output['user_stats']['dms_joined'][-1]['num_dms_joined'] == 1 assert output['user_stats']['messages_sent'][-1]['num_messages_sent'] == 1 assert output['user_stats']['involvement_rate'] == 1 channels_create_v2(result1['token'], "The party channel 2", True) channel3 = channels_create_v2(result2['token'], "The party channel 3", True).json()['channel_id'] channel_addowner_v1(result2['token'], channel3, result1['auth_user_id']) message_send_v2(result2['token'], channel3, 'hello how are you') output1 = user_stats(result1['token']).json() output2 = user_stats(result2['token']).json() assert len(output1['user_stats']) == 4 assert output1['user_stats']['channels_joined'][-1][ 'num_channels_joined'] == 3 assert output1['user_stats']['dms_joined'][-1]['num_dms_joined'] == 1 assert output1['user_stats']['messages_sent'][-1]['num_messages_sent'] == 1 assert output1['user_stats']['involvement_rate'] == 5 / 6 assert len(output2['user_stats']) == 4 assert output2['user_stats']['channels_joined'][-1][ 'num_channels_joined'] == 1 assert output2['user_stats']['dms_joined'][-1]['num_dms_joined'] == 1 assert output2['user_stats']['messages_sent'][-1]['num_messages_sent'] == 1 assert output2['user_stats']['involvement_rate'] == 3 / 6 dreams = users_stats(result1['token']).json() assert len(dreams['dreams_stats']) == 4 assert dreams['dreams_stats']['channels_exist'][-1][ 'num_channels_exist'] == 3 assert dreams['dreams_stats']['dms_exist'][-1]['num_dms_exist'] == 1 assert dreams['dreams_stats']['messages_exist'][-1][ 'num_messages_exist'] == 2 assert dreams['dreams_stats']['utilization_rate'] == 1
def create_input(): clear_v1() data_test_users = [ auth_register_v2("*****@*****.**", "finalpassword", "Eric", "Zheng").json(), auth_register_v2("*****@*****.**", "validpassword", "Josh", "Hatton").json(), auth_register_v2("*****@*****.**", "anotherpassword", "Bunny", "Dong").json(), auth_register_v2("*****@*****.**", "password3", "Jordan", "Milch").json(), auth_register_v2("*****@*****.**", "4thpassword", "Dean", "Zworestine").json(), ] data_test_channels = [ channels_create_v2(data_test_users[0]['token'], "General", True).json(), channels_create_v2(data_test_users[1]['token'], "Party", True).json(), channels_create_v2(data_test_users[2]['token'], "Private", False).json(), ] return [data_test_users, data_test_channels]
def create_input(): clear_v1() data_test_users = [ auth_register_v2("*****@*****.**", "validpassword", "Josh", "Hatton").json(), auth_register_v2("*****@*****.**", "anotherpassword", "Bunny", "Dong").json(), auth_register_v2("*****@*****.**", "password3", "Jordan", "Milch").json(), auth_register_v2("*****@*****.**", "4thpassword", "Dean", "Zworestine").json(), auth_register_v2("*****@*****.**", "finalpassword", "Eric", "Zheng").json(), ] data_test_channels = [ channels_create_v2(data_test_users[0]["token"], "First Channel", True).json(), channels_create_v2(data_test_users[1]["token"], "Second Channel", True).json(), channels_create_v2(data_test_users[2]["token"], "Third Channel", False).json(), ] # Send 10 messages to First Channel for i in range(0, 10): message_send_v2(data_test_users[0]["token"], data_test_channels[0]["channel_id"], f"First channel message {i}.") # Send 55 messages to Second Channel for i in range(0, 55): message_send_v2(data_test_users[1]["token"], data_test_channels[1]["channel_id"], f"Second channel message {i}.") # Send 120 messages to Third Channel for i in range(0, 120): message_send_v2(data_test_users[2]["token"], data_test_channels[2]["channel_id"], f"Third channel message {i}.") return [data_test_users, data_test_channels]
def test_invalid_token_exception(): """ Tests when the authorised user is an invalid id """ clear_v1() # Create a valid channel with user as owner user = auth_register_v2("*****@*****.**", "mangofruit1", "Adam", "Apple").json() channel = channels_create_v2(user['token'], "Valid channel", True).json() assert channel_invite_v2(user['token'] + 'bug', channel['channel_id'], user['auth_user_id']).status_code == ACCESS_ERROR assert channel_invite_v2(user['token'] + 'pipswe23', channel['channel_id'], user['auth_user_id']).status_code == ACCESS_ERROR assert channel_invite_v2(user['token'] + '5000', channel['channel_id'], user['auth_user_id']).status_code == ACCESS_ERROR assert channel_invite_v2(user['token'] + '689d', channel['channel_id'], user['auth_user_id']).status_code == ACCESS_ERROR assert channel_invite_v2(user['token'] + 'd', channel['channel_id'], user['auth_user_id']).status_code == ACCESS_ERROR
def test_invalid_u_id(): """ Should raise an InputError when passed in an invalid user id """ clear_v1() user_1 = auth_register_v2("*****@*****.**", "WaffleNow!", "Eric", "Zheng").json() # Invalid u_id should raise an InputError assert admin_userpermission_change_v1(user_1['token'], user_1['auth_user_id'] + 5, 2).status_code == INPUT_ERROR assert admin_userpermission_change_v1(user_1['token'], user_1['auth_user_id'] + 10, 2).status_code == INPUT_ERROR assert admin_userpermission_change_v1(user_1['token'], user_1['auth_user_id'] - 5, 1).status_code == INPUT_ERROR assert admin_userpermission_change_v1(user_1['token'], user_1['auth_user_id'] - 500, 1).status_code == INPUT_ERROR
def test_invalid_u_id(): """Raise an input error when u_id does not refer to a valid user id""" clear_v1() user_1 = auth_register_v2("*****@*****.**", "finalpassword", "Eric", "Zheng").json() user_2 = auth_register_v2("*****@*****.**", "validpassword", "Josh", "Hatton").json() assert admin_user_remove_v1(user_1["token"], user_1["auth_user_id"] + 5).status_code == INPUT_ERROR assert admin_user_remove_v1(user_1["token"], user_1["auth_user_id"] + 50).status_code == INPUT_ERROR assert admin_user_remove_v1(user_1["token"], user_2["auth_user_id"] + 1).status_code == INPUT_ERROR assert admin_user_remove_v1(user_1["token"], user_2["auth_user_id"] + 50).status_code == INPUT_ERROR assert admin_user_remove_v1(user_1["token"], user_2["auth_user_id"] + 500).status_code == INPUT_ERROR clear_v1()
def test_invalid_token(): """ Tests return of expected output when given a token that doesn't exist, or if the user is not in the channel/dm. """ clear_v1() # Token doesnt exist user_1 = auth_register_v2('*****@*****.**', 'happydays1', 'Eric', 'Zheng').json() assert notifications_get_v1(user_1['token'] + 'bug').status_code == ACCESS_ERROR # User not in channel user_2 = auth_register_v2('*****@*****.**', 'happydays2', 'Josh', 'Hatton').json() channel_1 = channels_create_v2(user_1['token'], 'Channel 1', True).json() user_2_handle = user_profile_v2(user_1['token'], user_2['auth_user_id']).json() message_send_v2(user_1['token'], channel_1['channel_id'], f"Hi @{user_2_handle['user']['handle_str']}") assert notifications_get_v1(user_2['token']).json() == { 'notifications': [] } # User not in dm dm_1 = dm_create_v1(user_1['token'], [user_2['auth_user_id']]).json() user_3 = auth_register_v2('*****@*****.**', 'hihihi!!!', 'Bunny', 'Dong').json() user_3_handle = user_profile_v2(user_1['token'], user_3['auth_user_id']).json() message_senddm_v1(user_1['token'], dm_1['dm_id'], f"Hello @{user_3_handle['user']['handle_str']}") assert notifications_get_v1(user_3['token']).json() == { 'notifications': [] }
def test_invalid_user_id_exception(): """ Tests when u_id does not refer to a valid user. """ clear_v1() # Create a valid user and add them to a valid channel user = auth_register_v2("*****@*****.**", "peterpiper", "Eric", "Zheng").json() channel = channels_create_v2(user['token'], "Lalaland", True).json() # Test for InputError when invalid users are invited to channel assert channel_invite_v2(user['token'], channel['channel_id'], user['auth_user_id'] + 5).status_code == INPUT_ERROR assert channel_invite_v2(user['token'], channel['channel_id'], user['auth_user_id'] + 500).status_code == INPUT_ERROR assert channel_invite_v2(user['token'], channel['channel_id'], user['auth_user_id'] - 5).status_code == INPUT_ERROR assert channel_invite_v2(user['token'], channel['channel_id'], user['auth_user_id'] - 5000).status_code == INPUT_ERROR assert channel_invite_v2(user['token'], channel['channel_id'], user['auth_user_id'] + 50000).status_code == INPUT_ERROR