def test_invite_global_owner(create_input): """ Tests that when a global owner is invited to a channel, they will have owner permissions in that channel. """ channel_1 = create_input[1][1] assert channel_invite_v2(create_input[0][1]['token'], channel_1['channel_id'], create_input[0][0]['auth_user_id']).status_code == SUCCESS assert channel_invite_v2(create_input[0][1]['token'], channel_1['channel_id'], create_input[0][2]['auth_user_id']).status_code == SUCCESS # create_input[0][0] is a global owner, so when invited, they should join # as a member but have owner permissions # create_input[0][2] is a member assert len(channel_details_v2(create_input[0][1]['token'], channel_1['channel_id']).json()['owner_members']) == 1 assert len(channel_details_v2(create_input[0][1]['token'], channel_1['channel_id']).json()['all_members']) == 3 # create_input[0][0] should be able to promote create_input[0][2] to a # channel owner assert channel_addowner_v1(create_input[0][0]['token'], channel_1['channel_id'], create_input[0][2]['auth_user_id']).status_code == SUCCESS
def test_pinning_non_owner(create_input): channel_invite_v2(create_input[0][0]['token'], create_input[1][0], create_input[0][1]['auth_user_id']) assert message_pin_v1(create_input[0][1]['token'], create_input[3][0]).status_code == ACCESS_ERROR assert message_pin_v1(create_input[0][2]['token'], create_input[4][0]).status_code == ACCESS_ERROR
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 test_multiple_channel_react(create_input): channel_invite_v2(create_input[0][0]['token'], create_input[1][0], create_input[0][1]['auth_user_id']) channel_invite_v2(create_input[0][0]['token'], create_input[1][0], create_input[0][2]['auth_user_id']) channel_invite_v2(create_input[0][0]['token'], create_input[1][0], create_input[0][3]['auth_user_id']) channel_invite_v2(create_input[0][0]['token'], create_input[1][0], create_input[0][4]['auth_user_id']) message_react_v1(create_input[0][0]['token'], create_input[3][0], 1) message_react_v1(create_input[0][1]['token'], create_input[3][0], 1) message_react_v1(create_input[0][2]['token'], create_input[3][0], 1) assert len( channel_messages_v2(create_input[0][0]['token'], create_input[1][0], 0).json()['messages'][4]['reacts']) == 1 assert channel_messages_v2( create_input[0][0]['token'], create_input[1][0], 0).json()['messages'][4]['reacts'][0]['react_id'] == 1 assert channel_messages_v2( create_input[0][0]['token'], create_input[1][0], 0).json()['messages'][4]['reacts'][0]['is_this_user_reacted'] == True assert len( channel_messages_v2( create_input[0][0]['token'], create_input[1][0], 0).json()['messages'][4]['reacts'][0]['u_ids']) == 3 assert create_input[0][0]['auth_user_id'] in channel_messages_v2( create_input[0][0]['token'], create_input[1][0], 0).json()['messages'][4]['reacts'][0]['u_ids'] assert create_input[0][1]['auth_user_id'] in channel_messages_v2( create_input[0][0]['token'], create_input[1][0], 0).json()['messages'][4]['reacts'][0]['u_ids'] assert create_input[0][2]['auth_user_id'] in channel_messages_v2( create_input[0][0]['token'], create_input[1][0], 0).json()['messages'][4]['reacts'][0]['u_ids']
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_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_unauthorised_user_exception(create_input): """ Tests when the authorised user is not already a member of the channel """ user_1, user_2, user_3, user_4, user_5 = create_input[0] # Create a channel with user_in_channel as the only member user_in_channel = auth_register_v2("*****@*****.**", "wawaweewa", "Already", "Exists").json() channel = channels_create_v2(user_in_channel['token'], "Library", True).json() assert channel_invite_v2(user_1['token'], channel['channel_id'], user_2['auth_user_id']).status_code == ACCESS_ERROR assert channel_invite_v2(user_2['token'], channel['channel_id'], user_3['auth_user_id']).status_code == ACCESS_ERROR assert channel_invite_v2(user_3['token'], channel['channel_id'], user_4['auth_user_id']).status_code == ACCESS_ERROR assert channel_invite_v2(user_4['token'], channel['channel_id'], user_5['auth_user_id']).status_code == ACCESS_ERROR assert channel_invite_v2(user_5['token'], channel['channel_id'], user_1['auth_user_id']).status_code == ACCESS_ERROR
def test_successful_invites(create_input): """ Tests for multiple successful invites to a channel """ # Create a set of users not in the channel yet user_1, user_2, user_3, user_4, user_5 = create_input[0] channel_1, channel_2, channel_3 = create_input[1] # Test for successful calls and that users have been immediately added into # their channels # Invite user2, user3, user4, user5 to channel 1 assert channel_invite_v2(user_1['token'], channel_1['channel_id'], user_2['auth_user_id']).status_code == SUCCESS assert channel_invite_v2(user_1['token'], channel_1['channel_id'], user_3['auth_user_id']).status_code == SUCCESS assert channel_invite_v2(user_1['token'], channel_1['channel_id'], user_4['auth_user_id']).status_code == SUCCESS assert channel_invite_v2(user_1['token'], channel_1['channel_id'], user_5['auth_user_id']).status_code == SUCCESS # Invite user4, user5 to channel 2 assert channel_invite_v2(user_2['token'], channel_2['channel_id'], user_4['auth_user_id']).status_code == SUCCESS assert channel_invite_v2(user_2['token'], channel_2['channel_id'], user_5['auth_user_id']).status_code == SUCCESS # Invite user1 to channel 3 assert channel_invite_v2(user_3['token'], channel_3['channel_id'], user_1['auth_user_id']).status_code == SUCCESS # Check that users have been added to channels channel_detail_1 = channel_details_v2(user_1['token'], channel_1['channel_id']).json() channel_detail_2 = channel_details_v2(user_2['token'], channel_2['channel_id']).json() channel_detail_3 = channel_details_v2(user_3['token'], channel_3['channel_id']).json() # Check channel 1 assert channel_detail_1['all_members'][0]['u_id'] == user_1['auth_user_id'] assert channel_detail_1['all_members'][1]['u_id'] == user_2['auth_user_id'] assert channel_detail_1['all_members'][2]['u_id'] == user_3['auth_user_id'] assert channel_detail_1['all_members'][3]['u_id'] == user_4['auth_user_id'] assert channel_detail_1['all_members'][4]['u_id'] == user_5['auth_user_id'] # Check channel 2 assert channel_detail_2['all_members'][0]['u_id'] == user_2['auth_user_id'] assert channel_detail_2['all_members'][1]['u_id'] == user_4['auth_user_id'] assert channel_detail_2['all_members'][2]['u_id'] == user_5['auth_user_id'] # Check channel 3 assert channel_detail_3['all_members'][0]['u_id'] == user_3['auth_user_id'] assert channel_detail_3['all_members'][1]['u_id'] == user_1['auth_user_id']
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
def test_success_private_channel(create_input): """ Tests that users can be invited into private channels too. """ channel_private = create_input[1][2] assert channel_invite_v2(create_input[0][2]['token'], channel_private['channel_id'], create_input[0][0]['auth_user_id']).status_code == SUCCESS assert len(channel_details_v2(create_input[0][2]['token'], channel_private['channel_id']).json()['owner_members']) == 1 assert len(channel_details_v2(create_input[0][2]['token'], channel_private['channel_id']).json()['all_members']) == 2
def test_order_of_exceptions(): """ Tests that the function raises exceptions in the order as assumed. The order should be: 1. AccessError from invalid token 2. InputError from invalid channel id 3. InputError from invalid user id 4. AccessError when any of the authorised user is not already part of a channel """ clear_v1() user_1 = auth_register_v2("*****@*****.**", "f244332fsd", "Tom", "Cruise").json() user_2 = auth_register_v2("*****@*****.**", "password09123", "Dummy", "Dog").json() channel = channels_create_v2(user_1['token'], "General", True).json() user_test = auth_register_v2("*****@*****.**", "watermelon", "Max", "Rex").json() # Pass in invalid user_id, invalid auth_user_id, invalid channel_id, # auth_user not part of the channel. This should raise an access error. assert channel_invite_v2(user_2['token'] + 'bug', channel['channel_id'] + 5, user_test['auth_user_id'] + 5).status_code == ACCESS_ERROR # Pass in invalid user_id, valid token, invalid channel_id, # auth_user not part of the channel. This should raise an access error. assert channel_invite_v2(user_2['token'], channel['channel_id'] + 5, user_test['auth_user_id'] + 5).status_code == INPUT_ERROR # Pass in valid user_id, valid token, valid channel_id, # auth_user not part of the channel. This should raise an input error. assert channel_invite_v2(user_2['token'], channel['channel_id'], user_test['auth_user_id'] + 5).status_code == INPUT_ERROR # Pass in valid user_id, valid token, valid channel_id, # auth_user not part of the channel. This should raise an access error. assert channel_invite_v2(user_2['token'], channel['channel_id'], user_test['auth_user_id']).status_code == ACCESS_ERROR
def test_channel_invite_stat(): 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_invite_v2(result1['token'], channel1['channel_id'], result2['auth_user_id']) output = user_stats(result1['token']).json() output1 = user_stats(result2['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'] == 0 assert output['user_stats']['involvement_rate'] == 1 assert len(output1['user_stats']) == 4 assert output1['user_stats']['channels_joined'][-1][ 'num_channels_joined'] == 1 assert output1['user_stats']['dms_joined'][-1]['num_dms_joined'] == 0 assert output1['user_stats']['messages_sent'][-1]['num_messages_sent'] == 0 assert output1['user_stats']['involvement_rate'] == 1 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'] == 0 assert dreams['dreams_stats']['utilization_rate'] == 2 / 2
def test_self_invite(create_input): """ Test for user trying to invite themselves. The function should call successfully and not add the user again to the channel. """ user_1, user_2, user_3, user_4, user_5 = create_input[0] channel_1, channel_2, channel_3 = create_input[1] # Owner inviting themselves assert channel_invite_v2(user_1['token'], channel_1['channel_id'], user_1['auth_user_id']).status_code == SUCCESS channel_1_details = channel_details_v2(user_1['token'], channel_1['channel_id']).json() assert len(channel_1_details['all_members']) == 1 assert channel_invite_v2(user_2['token'], channel_2['channel_id'], user_2['auth_user_id']).status_code == SUCCESS channel_2_details = channel_details_v2(user_2['token'], channel_2['channel_id']).json() assert len(channel_2_details['all_members']) == 1 assert channel_invite_v2(user_3['token'], channel_3['channel_id'], user_3['auth_user_id']).status_code == SUCCESS channel_3_details = channel_details_v2(user_3['token'], channel_3['channel_id']).json() assert len(channel_3_details['all_members']) == 1 # User 4 inviting themselves after being invited by user 1 assert channel_invite_v2(user_1['token'], channel_1['channel_id'], user_4['auth_user_id']).status_code == SUCCESS assert channel_invite_v2(user_4['token'], channel_1['channel_id'], user_4['auth_user_id']).status_code == SUCCESS channel_1_details = channel_details_v2(user_1['token'], channel_1['channel_id']).json() assert len(channel_1_details['all_members']) == 2 # User 5 inviting themselves after being invited by user 4 assert channel_invite_v2(user_4['token'], channel_1['channel_id'], user_5['auth_user_id']).status_code == SUCCESS assert channel_invite_v2(user_5['token'], channel_1['channel_id'], user_5['auth_user_id']).status_code == SUCCESS channel_1_details = channel_details_v2(user_1['token'], channel_1['channel_id']).json() assert len(channel_1_details['all_members']) == 3
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"], "Channel 1", True).json(), channels_create_v2(data_test_users[1]["token"], "Private", False).json(), ] # User1, User3, User 4 in channel 1 # User2, User 5 in channel 2 channel_join_v2(data_test_users[2]["token"], data_test_channels[0]["channel_id"]) channel_join_v2(data_test_users[3]["token"], data_test_channels[0]["channel_id"]) channel_invite_v2(data_test_users[1]["token"], data_test_channels[1]["channel_id"], data_test_users[4]["auth_user_id"]) # User 1, user3, user4 sends a message to channel 1 # User2, user5 sends a message to channel 2 data_test_channel_messages = [ message_send_v2( data_test_users[0]["token"], data_test_channels[0]["channel_id"], "Look, I was gonna go easy on you \ Not to hurt your feelings \ But I'm only going to get this one chance \ Something's wrong, I can feel it", ).json(), message_send_v2( data_test_users[1]["token"], data_test_channels[1]["channel_id"], "Can we pretend that airplanes in the night \ sky are like shootin' stars \ I could really use a wish right now, wish right \ now, wish right now Can we pretend that \ airplanes in the night sky are like shootin'", ).json(), message_send_v2( data_test_users[2]["token"], data_test_channels[0]["channel_id"], "All I want is nothing more \ To hear you knocking at my door \ 'Cause if I could see your face once more \ I could die a happy man I'm sure", ).json(), message_send_v2( data_test_users[3]["token"], data_test_channels[0]["channel_id"], "I've been staring at the edge of the water \ 'Long as I can remember \ Never really knowing why", ).json(), message_send_v2( data_test_users[4]["token"], data_test_channels[1]["channel_id"], "I am so so so so so sick of writing these tests \ someone please send help i am so tired lol.", ).json(), ] # user 1 has dm with user 2 # user 3 has dm with user 4 # user 5 has dm with user 2 data_test_dms = [ dm_create_v1(data_test_users[0]["token"], [data_test_users[1]["auth_user_id"]]).json(), dm_create_v1(data_test_users[2]["token"], [data_test_users[3]["auth_user_id"]]).json(), dm_create_v1(data_test_users[4]["token"], [data_test_users[1]["auth_user_id"]]).json(), ] # user 1, user_2 sends dm to dm_1 # user 3, user 4 sends dm to dm_2 # user 5 sends dm to dm_3 data_test_dm_messages = [ message_senddm_v1(data_test_users[0]["token"], data_test_dms[0]["dm_id"], "Hello user 2!").json(), message_senddm_v1(data_test_users[1]["token"], data_test_dms[0]["dm_id"], "Hi user 1!").json(), message_senddm_v1(data_test_users[2]["token"], data_test_dms[1]["dm_id"], "How are you user 4?").json(), message_senddm_v1(data_test_users[3]["token"], data_test_dms[1]["dm_id"], "I am fine user 3!").json(), message_senddm_v1(data_test_users[4]["token"], data_test_dms[2]["dm_id"], "Shut up user 2.").json(), ] return [ data_test_users, data_test_channels, data_test_channel_messages, data_test_dms, data_test_dm_messages ]
def test_further_mixed_harder(): 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() result4 = auth_register_v2('*****@*****.**', 'password', 'comp', 'student').json() channel1 = channels_create_v2(result1['token'], "The party channel 1", True).json() channel2 = channels_create_v2(result2['token'], "The party channel 2", True).json() dm_create_v1(result1['token'], [result2['auth_user_id'], result3['auth_user_id']]) dm_create_v1(result2['token'], [result4['auth_user_id'], result3['auth_user_id']]) output1 = user_stats(result1['token']).json() output2 = user_stats(result2['token']).json() output3 = user_stats(result3['token']).json() output4 = user_stats(result4['token']).json() assert len(output1['user_stats']) == 4 assert output1['user_stats']['channels_joined'][-1][ 'num_channels_joined'] == 1 assert output1['user_stats']['dms_joined'][-1]['num_dms_joined'] == 1 assert output1['user_stats']['messages_sent'][-1]['num_messages_sent'] == 0 assert output1['user_stats']['involvement_rate'] == 2 / 4 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'] == 2 assert output2['user_stats']['messages_sent'][-1]['num_messages_sent'] == 0 assert output2['user_stats']['involvement_rate'] == 3 / 4 assert len(output3['user_stats']) == 4 assert output3['user_stats']['channels_joined'][-1][ 'num_channels_joined'] == 0 assert output3['user_stats']['dms_joined'][-1]['num_dms_joined'] == 2 assert output3['user_stats']['messages_sent'][-1]['num_messages_sent'] == 0 assert output3['user_stats']['involvement_rate'] == 2 / 4 assert len(output4['user_stats']) == 4 assert output4['user_stats']['channels_joined'][-1][ 'num_channels_joined'] == 0 assert output4['user_stats']['dms_joined'][-1]['num_dms_joined'] == 1 assert output4['user_stats']['messages_sent'][-1]['num_messages_sent'] == 0 assert output4['user_stats']['involvement_rate'] == 1 / 4 dreams = users_stats(result1['token']).json() 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'] == 2 assert dreams['dreams_stats']['messages_exist'][-1][ 'num_messages_exist'] == 0 assert dreams['dreams_stats']['utilization_rate'] == 1 channel_invite_v2(result1['token'], channel1['channel_id'], result3['auth_user_id']) channel_invite_v2(result2['token'], channel2['channel_id'], result3['auth_user_id']) message1 = message_send_v2(result1['token'], channel1['channel_id'], 'Hello, how are you?').json() message_send_v2(result1['token'], channel1['channel_id'], 'Hello, how are you?') message_send_v2(result1['token'], channel1['channel_id'], 'Hello, how are you?') message_send_v2(result2['token'], channel2['channel_id'], 'Hello, how are you?') message2 = message_send_v2(result3['token'], channel2['channel_id'], 'Hello, how are you?').json() message_remove_v1(result1['token'], message1['message_id']) message_remove_v1(result3['token'], message2['message_id']) auth_register_v2('*****@*****.**', 'password', 'comp', 'student') output1 = user_stats(result1['token']).json() output2 = user_stats(result2['token']).json() output3 = user_stats(result3['token']).json() output4 = user_stats(result4['token']).json() dreams = users_stats(result1['token']).json() assert len(output1['user_stats']) == 4 assert output1['user_stats']['channels_joined'][-1][ 'num_channels_joined'] == 1 assert output1['user_stats']['dms_joined'][-1]['num_dms_joined'] == 1 assert output1['user_stats']['messages_sent'][-1]['num_messages_sent'] == 3 assert output1['user_stats']['involvement_rate'] == 5 / 7 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'] == 2 assert output2['user_stats']['messages_sent'][-1]['num_messages_sent'] == 1 assert output2['user_stats']['involvement_rate'] == 4 / 7 assert len(output3['user_stats']) == 4 assert output3['user_stats']['channels_joined'][-1][ 'num_channels_joined'] == 2 assert output3['user_stats']['dms_joined'][-1]['num_dms_joined'] == 2 assert output3['user_stats']['messages_sent'][-1]['num_messages_sent'] == 1 assert output3['user_stats']['involvement_rate'] == 5 / 7 assert len(output4['user_stats']) == 4 assert output4['user_stats']['channels_joined'][-1][ 'num_channels_joined'] == 0 assert output4['user_stats']['dms_joined'][-1]['num_dms_joined'] == 1 assert output4['user_stats']['messages_sent'][-1]['num_messages_sent'] == 0 assert output4['user_stats']['involvement_rate'] == 1 / 7 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'] == 2 assert dreams['dreams_stats']['messages_exist'][-1][ 'num_messages_exist'] == 3 assert dreams['dreams_stats']['utilization_rate'] == 4 / 5 clear_v1()
def test_added_to_channel(create_input): """ Tests the expected return value when a user is added to a channel """ user_1, user_2, user_3, user_4, user_5 = create_input[0] user_1_handle, _, user_3_handle, _, user_5_handle = create_input[1] channel_1 = create_input[2][0] dm_1, dm_2, dm_3 = create_input[3] channel_invite_v2(user_1['token'], channel_1['channel_id'], user_2['auth_user_id']) channel_invite_v2(user_1['token'], channel_1['channel_id'], user_3['auth_user_id']) channel_invite_v2(user_1['token'], channel_1['channel_id'], user_4['auth_user_id']) # Also test for channel_addowner channel_addowner_v1(user_1['token'], channel_1['channel_id'], user_5['auth_user_id']) assert notifications_get_v1(user_2['token']).json() == { 'notifications': [{ 'channel_id': channel_1['channel_id'], 'dm_id': -1, 'notification_message': f"{user_1_handle['user']['handle_str']} added you to Channel 1" }, { 'channel_id': -1, 'dm_id': dm_3['dm_id'], 'notification_message': f"{user_5_handle['user']['handle_str']} added you to {dm_3['dm_name']}" }, { 'channel_id': -1, 'dm_id': dm_1['dm_id'], 'notification_message': f"{user_1_handle['user']['handle_str']} added you to {dm_1['dm_name']}" }] } assert notifications_get_v1(user_3['token']).json() == { 'notifications': [{ 'channel_id': channel_1['channel_id'], 'dm_id': -1, 'notification_message': f"{user_1_handle['user']['handle_str']} added you to Channel 1" }] } assert notifications_get_v1(user_4['token']).json() == { 'notifications': [{ 'channel_id': channel_1['channel_id'], 'dm_id': -1, 'notification_message': f"{user_1_handle['user']['handle_str']} added you to Channel 1" }, { 'channel_id': -1, 'dm_id': dm_2['dm_id'], 'notification_message': f"{user_3_handle['user']['handle_str']} added you to {dm_2['dm_name']}" }] } assert notifications_get_v1(user_5['token']).json() == { 'notifications': [ { 'channel_id': channel_1['channel_id'], 'dm_id': -1, 'notification_message': f"{user_1_handle['user']['handle_str']} added you to Channel 1" }, ] }