def invite_to_ch1(user1, user2, ch1): ''' Function for user1 to invite user2 to channel ''' channel.invite(user1['token'], ch1['channel_id'], user2['u_id']) return
def test_channel_invite_invalid_userid(): 'Invalid user case' workspace_reset() ret = register_and_create() user1 = ret['user'] token = user1['token'] channel_info = ret['channel'] channel_id = channel_info['channel_id'] # InputError when user tries to invite someone with an invalid user ID # Invalid user_id = 100 with pytest.raises(InputError) as e: channel.invite(token, channel_id, 100)
def test_channel_invite_invalid_channel(): 'Invalid channel case' workspace_reset() ret = register_and_create() user1 = ret['user'] token1 = user1['token'] channel_info = ret['channel'] user2 = reg_user2() u_id2 = user2['u_id'] # InputError when user2 is invited to an invalid channel # Invalid channel_id = 100 with pytest.raises(InputError) as e: channel.invite(token1, 100, u_id2)
def test_channel_invite_unauthorised(): 'User is not a member case' workspace_reset() ret = register_and_create() user1 = ret['user'] channel_info = ret['channel'] user2 = reg_user2() token2 = user2['token'] user3 = reg_user3() u_id3 = user3['u_id'] channel_id = channel_info['channel_id'] # AccessError when authorised user is not a member of the channel # user2 invites user3 after user1 creates the channel with pytest.raises(AccessError) as e: channel.invite(token2, channel_id, u_id3)
def test_channel_invite_existing_user(): 'Existing user case' workspace_reset() ret = register_and_create() user1 = ret['user'] token1 = user1['token'] channel_info = ret['channel'] user2 = reg_user2() u_id2 = user2['u_id'] channel_id = channel_info['channel_id'] # Invite user2 channel.invite(token1, channel_id, u_id2) # InputError when user tries to invite someone who is already a member of # the channel with pytest.raises(InputError) as e: channel.invite(token1, channel_id, u_id2)
def test_remove2(): ''' The admin of a channel is attempting to remove a message ''' workspace_reset() messages_store = get_messages_store() #register user1 and create channel1 ret = register_and_create() user1 = ret['user'] channel1 = ret['channel'] user2 = reg_user2() channel.invite(user1['token'], channel1['channel_id'], user2['u_id']) msg1 = send_msg1(user2, channel1) message.remove({'token': user1['token'], 'message_id': msg1['message_id']}) assert msg1 not in messages_store assert msg1 not in channel1['messages']
def test_channel_invite_successful(): 'Successful case' workspace_reset() ret = register_and_create() user1 = ret['user'] token1 = user1['token'] channel_info = ret['channel'] user2 = reg_user2() u_id2 = user2['u_id'] channel_id = channel_info['channel_id'] assert channel.invite(token1, channel_id, u_id2) == {}
def test_edit2(): ''' Test if an owner is editing another users message ''' workspace_reset() ret = register_and_create() user1 = ret['user'] channel1 = ret['channel'] user2 = reg_user2() channel.invite(user1['token'], channel1['channel_id'], user2['u_id']) msg1 = send_msg1(user2, channel1) message.edit({ 'token': user1['token'], 'message_id': msg1['message_id'], 'message': 'edit' }) assert msg1['message'] == 'edit'
def test_unauth_owner(): 'testing error case' #user is not an owner workspace_reset() ret = register_and_create() user1 = ret['user'] channel1 = ret['channel'] user2 = reg_user2() token = user1['token'] channel_id = channel1['channel_id'] u_id = user2['u_id'] channel.invite(token, channel_id, u_id) msg1 = send_msg1(user2, channel1) with pytest.raises(InputError): message.pin({ 'token': user2['token'], 'message_id': msg1['message_id'], }) # pylint: disable=C0304