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_user_leave(create_input): assert channel_leave_v1(create_input[0][1]["token"], create_input[1][0]["channel_id"]).json() == {} result = search_v2(create_input[0][1]["token"], "Hey nice to meet you").json() assert type(result) == dict assert len(result["messages"]) == 0
def test_success_owner_leave(create_input): # Add another owner to First Channel assert channel_addowner_v1( create_input[0][0]["token"], create_input[1][0]["channel_id"], create_input[0][4]["auth_user_id"]).json() == {} # length of *_members for First Channel before leave assert len( channel_details_v2( create_input[0][0]["token"], create_input[1][0]["channel_id"]).json()["owner_members"]) == 2 assert len( channel_details_v2( create_input[0][0]["token"], create_input[1][0]["channel_id"]).json()["all_members"]) == 4 # One owner leaves assert channel_leave_v1(create_input[0][0]["token"], create_input[1][0]["channel_id"]).json() == {} # length of *_members for First Channel after leave; testing for all involved users assert len( channel_details_v2( create_input[0][1]["token"], create_input[1][0]["channel_id"]).json()["owner_members"]) == 1 assert len( channel_details_v2( create_input[0][1]["token"], create_input[1][0]["channel_id"]).json()["all_members"]) == 3 assert len( channel_details_v2( create_input[0][2]["token"], create_input[1][0]["channel_id"]).json()["owner_members"]) == 1 assert len( channel_details_v2( create_input[0][2]["token"], create_input[1][0]["channel_id"]).json()["all_members"]) == 3 assert len( channel_details_v2( create_input[0][4]["token"], create_input[1][0]["channel_id"]).json()["owner_members"]) == 1 assert len( channel_details_v2( create_input[0][4]["token"], create_input[1][0]["channel_id"]).json()["all_members"]) == 3 assert channel_details_v2( create_input[0][0]["token"], create_input[1][0]["channel_id"]).status_code == ACCESS_ERROR # number of channels each user is a part of assert len( channels_list_v2(create_input[0][0]["token"]).json()["channels"]) == 0 assert len( channels_list_v2(create_input[0][1]["token"]).json()["channels"]) == 2 assert len( channels_list_v2(create_input[0][2]["token"]).json()["channels"]) == 2 assert len( channels_list_v2(create_input[0][4]["token"]).json()["channels"]) == 1
def test_fail_last_owner_leave(create_input): # length of *_members for First Channel before leave assert len( channel_details_v2( create_input[0][0]["token"], create_input[1][0]["channel_id"]).json()["owner_members"]) == 1 assert len( channel_details_v2( create_input[0][0]["token"], create_input[1][0]["channel_id"]).json()["all_members"]) == 3 assert channel_leave_v1( create_input[0][0]["token"], create_input[1][0]["channel_id"]).status_code == INPUT_ERROR
def test_not_channel_member_react(create_input): assert message_react_v1(create_input[0][2]['token'], create_input[3][0], 1).status_code == ACCESS_ERROR assert message_react_v1(create_input[0][3]['token'], create_input[3][1], 1).status_code == ACCESS_ERROR assert message_react_v1(create_input[0][3]['token'], create_input[3][4], 1).status_code == ACCESS_ERROR assert message_react_v1(create_input[0][4]['token'], create_input[4][3], 1).status_code == ACCESS_ERROR assert message_react_v1(create_input[0][3]['token'], create_input[4][1], 1).status_code == ACCESS_ERROR assert message_react_v1(create_input[0][3]['token'], create_input[4][4], 1).status_code == ACCESS_ERROR # Cannot occur (if the are not a member they can't have reacted - unless removed from channel) channel_join_v2(create_input[0][2]['token'], create_input[1][0]) message_react_v1(create_input[0][2]['token'], create_input[3][0], 1) channel_leave_v1(create_input[0][2]['token'], create_input[1][0]) assert message_unreact_v1(create_input[0][2]['token'], create_input[3][0], 1).status_code == ACCESS_ERROR message_react_v1(create_input[0][2]['token'], create_input[4][0], 1) dm_leave_v1(create_input[0][2]['token'], create_input[3][0]) assert message_unreact_v1(create_input[0][2]['token'], create_input[4][0], 1).status_code == ACCESS_ERROR
def test_channel_leave_stat(): clear_v1() result1 = auth_register_v2('*****@*****.**', 'password', 'comp', 'student').json() result2 = auth_register_v2('*****@*****.**', 'password', 'comp', 'student').json() channel1 = channels_create_v2(result2['token'], "The party channel 1", True).json() channel_addowner_v1(result2['token'], channel1['channel_id'], result1['auth_user_id']) channel_leave_v1(result2['token'], channel1['channel_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'] == 0 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'] == 0 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'] == 1 / 2
def test_both_invalid(create_input): # token, channel_id do not exist, # ACCESS_ERROR is prioritised assert channel_leave_v1('insertanotherinvalidtokenhere', 321).status_code == ACCESS_ERROR
def test_token_invalid(create_input): # token does not exist assert channel_leave_v1( 'insertinvalidtokenhere', create_input[1][0]["channel_id"]).status_code == ACCESS_ERROR
def test_channel_id_invalid(create_input): # channel_id 5 has not been created assert channel_leave_v1(create_input[0][0]["token"], 5).status_code == INPUT_ERROR