def leave_group_event(group_event_id, user: User):
    if group_event_id is None or not id_is_valid(group_event_id):
        return abort(400)

    group_event = group_event_dao.get(group_event_id)
    if group_event is None:
        return abort(404, "Group event is not found")

    event_member = event_member_dao.get_by_user_event(user.id, group_event_id)
    if event_member is None:
        return abort(404, "Event member is not found")

    # delete event if this member is last
    if len(group_event.member_id_list) == 1:
        if delete_group_event(group_event_id):
            return '', 204
        else:
            return abort(500, "Group event was not delete")

    if not group_event_dao.delete_member(group_event_id, event_member.id):
        return abort(500, "Event member was not delete from event")

    if not user_dao.delete_chat(event_member.user_id, group_event.chat_id):
        return abort(500, "Chat was not delete from user")
    if not user_dao.delete_event(event_member.user_id, group_event.id):
        return abort(500, "Event was not delete from user")

    event_member_dao.delete(event_member.id)
    return '', 204
Beispiel #2
0
def delete_event_member(member_id):
    member = event_member_dao.get(member_id)

    event = group_event_dao.get(member.event_id)

    user_dao.delete_chat(member.user_id, event.chat_id)
    user_dao.delete_event(member.user_id, event.id)

    event_member_dao.delete(member.id)
    def tearDown(self):
        user_dao.delete_user(self.sender_invites)
        user_dao.delete_user(self.receiver_invites)
        group_event_dao.delete(self.group_event_id)

        invite_dao.delete_invite(self.invite_to_friend_id_test_send)
        invite_dao.delete_invite(self.invite_to_event_id_test_send)

        invite_dao.delete_invite(self.invite_to_friend_id_test_accept_invite)
        invite_dao.delete_invite(self.invite_to_event_id_test_accept_invite)

        chat_dao.delete_event_chat(self.chat_id)
        event_member_dao.delete(self.member_id)
    def tearDown(self):
        user_dao.delete_user(self.user_id_1)
        user_dao.delete_user(self.user_id_2)

        group_event_dao.delete(self.group_event_id_test_create)
        group_event_dao.delete(self.group_event_id_test_delete)
        group_event_dao.delete(self.group_event_id_test_leave)

        event_member_dao.delete(self.member_id_test_create)
        event_member_dao.delete(self.member_id_test_delete_1)
        event_member_dao.delete(self.member_id_test_delete_2)
        event_member_dao.delete(self.member_id_test_leave_1)
        event_member_dao.delete(self.member_id_test_leave_2)
        chat_dao.delete_event_chat(self.event_chat_id)
    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)