def test_send_invite(self): # check that users were create self.assertTrue(user_dao.is_exist_by_id(self.sender_invites)) self.assertTrue(user_dao.is_exist_by_id(self.receiver_invites)) # send invite from user_1 to user_2 in friends self.invite_to_friend_id_test_send = user_utils.send_invite( self.sender_invites, self.receiver_invites, InviteType.FRIEND) # check invite id and invite existing self.assertTrue( invite_dao.is_exists(self.invite_to_friend_id_test_send)) # check that invite is added to user user = user_dao.get_user(self.receiver_invites) self.assertIn(self.invite_to_friend_id_test_send, user.invite_id_list) # send invite from user_1 to user_2 in event self.invite_to_event_id_test_send = user_utils.send_invite( self.sender_invites, self.receiver_invites, InviteType.EVENT, self.group_event_id) # check invite id and invite existing self.assertTrue(invite_dao.is_exists( self.invite_to_event_id_test_send)) # check that invite is added to user user = user_dao.get_user(self.receiver_invites) self.assertIn(self.invite_to_event_id_test_send, user.invite_id_list)
def test_accept_invite_to_friend(self): # INVITE TO FRIEND self.invite_to_friend_id_test_accept_invite = user_utils.send_invite( self.sender_invites, self.receiver_invites, InviteType.FRIEND) # check invite id and invite existing self.assertTrue( invite_dao.is_exists(self.invite_to_friend_id_test_accept_invite)) invite_to_friend = invite_dao.get_invite( self.invite_to_friend_id_test_accept_invite) # accept invite user_utils.accept_invite(self.invite_to_friend_id_test_accept_invite) # check invite type self.assertEqual(invite_to_friend.type, InviteType.FRIEND) receiver_user = user_dao.get_user(invite_to_friend.receiver_id) sender_user = user_dao.get_user(invite_to_friend.sender_id) # check that users became friends self.assertIn(invite_to_friend.sender_id, receiver_user.friend_id_list) self.assertIn(invite_to_friend.receiver_id, sender_user.friend_id_list) # check that invite was delete self.assertFalse( invite_dao.is_exists(self.invite_to_friend_id_test_accept_invite)) self.assertNotIn(self.invite_to_friend_id_test_accept_invite, receiver_user.invite_id_list)
def invite(): if request.method == 'POST': """Send invite :arg type - to friends or to group event :arg receiver_id - who receive this invite :arg event_id - optional is type is friend""" received_json = request.get_json() return user_utils.send_invite(received_json, current_user) if request.method == 'DELETE': """Accept or decline invite :arg id - invite id :arg action - accept or decline""" invite_id = request.args.get('id') action = request.args.get('action') return user_utils.handle_invite(invite_id, action, current_user)
def test_decline_invite(self): self.invite_id_test_decline_invite = user_utils.send_invite( self.sender_invites, self.receiver_invites, InviteType.FRIEND) # check that invite was sent self.assertTrue( invite_dao.is_exists(self.invite_id_test_decline_invite)) user_utils.decline_invite(self.invite_id_test_decline_invite) receiver_user = user_dao.get_user(self.receiver_invites) # check that invite was delete self.assertFalse( invite_dao.is_exists(self.invite_id_test_decline_invite)) self.assertNotIn(self.invite_id_test_decline_invite, receiver_user.invite_id_list)
def test_accept_invite_to_event(self): # INVITE TO EVENT self.invite_to_event_id_test_accept_invite = user_utils.send_invite( self.sender_invites, self.receiver_invites, InviteType.EVENT, self.group_event_id) # check invite id and invite existing self.assertTrue( invite_dao.is_exists(self.invite_to_event_id_test_accept_invite)) invite_to_event = invite_dao.get_invite( self.invite_to_event_id_test_accept_invite) # accept invite user_utils.accept_invite(self.invite_to_event_id_test_accept_invite) # check invite type self.assertEqual(invite_to_event.type, InviteType.EVENT) receiver_user = user_dao.get_user(invite_to_event.receiver_id) event = group_event_dao.get(invite_to_event.event_id) member = event_member_dao.get_by_user_event(receiver_user.id, event.id) # id's for removing after tests self.chat_id = event.chat_id self.member_id = member.id # check that user became event member self.assertIn(event.id, receiver_user.event_id_list) self.assertIn(member.id, event.member_id_list) # check that invite was delete self.assertFalse( invite_dao.is_exists(self.invite_to_event_id_test_accept_invite)) self.assertNotIn(self.invite_to_event_id_test_accept_invite, receiver_user.invite_id_list) self.assertEqual(event_member_dao.delete(member.id), 1)