Ejemplo n.º 1
0
    def test_response_and_invited(self):
        """
        Users that are Invited Guests and that have responded should be returned.
        (In the event they initially applied (response) and then became an invited guest)
        """
        self.seed_static_data()

        candidates = self.add_n_users(3, organisation_id=self.dummy_org_id)
        db.session.add_all(candidates)

        invitation = InvitedGuest(
            event_id=self.event1_id,
            user_id=candidates[0].id,
            role='EveryRole'
        )

        db.session.add(invitation)
        db.session.commit()

        application = self.add_response(self.event1_application_form.id, candidates[0].id)

        # Make the request
        header = self.get_auth_header_for(self.event1_admin.email)
        params = {'event_id': self.event1_id}

        response = self.app.get('/api/v1/userprofilelist', headers=header, data=params)
        
        # Assert that request succeeds and Invited Guests are returned.
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.json), 1)
        self.assertEqual(response.json[0]['type'], 'Invited Guest')
Ejemplo n.º 2
0
 def add_invited_guest(self, user_id, event_id=1, role='Guest'):
     print(('Adding invited guest for user: {}, event: {}, role: {}'.format(
         user_id, event_id, role)))
     guest = InvitedGuest(event_id, user_id, role)
     db.session.add(guest)
     db.session.commit()
     return guest
Ejemplo n.º 3
0
    def test_invited_different_event(self):
        """
        Invited guests for one event, should not be returned from another event
        """
        self.seed_static_data()

        candidates = self.add_n_users(3, organisation_id=self.dummy_org_id)
        db.session.add_all(candidates)

        invitation = InvitedGuest(
            event_id=self.event2_id,
            user_id=candidates[0].id,
            role='EveryRole'
        )

        db.session.add(invitation)
        db.session.commit()

        # Make the request
        header = self.get_auth_header_for(self.event1_admin.email)
        params = {'event_id': self.event1_id}  # Not event2 as with the application

        response = self.app.get('/api/v1/userprofilelist', headers=header, data=params)
        print(response.json)
        # Assert that request succeeds as they applied to the same event.
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.json), 0)
Ejemplo n.º 4
0
    def test_no_response_and_invited(self):
        """
        Users that are Invited Guests that have not responded should be returned.
        """
        self.seed_static_data()

        candidates = self.add_n_users(3, organisation_id=self.dummy_org_id)
        db.session.add_all(candidates)

        user_id = candidates[0].id
        invitation = InvitedGuest(
            event_id=self.event1_id,
            user_id=user_id,
            role='EveryRole'
        )

        db.session.add(invitation)
        db.session.commit()

        # Make the request
        header = self.get_auth_header_for(self.event1_admin.email)
        params = {'event_id': self.event1_id}

        response = self.app.get('/api/v1/userprofilelist', headers=header, data=params)

        # Assert that request succeeds and no users of the correct type are returned.
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.json), 1)
        self.assertEqual(response.json[0]['user_id'], user_id)
        self.assertEqual(response.json[0]['type'], 'Invited Guest')
Ejemplo n.º 5
0
    def test_registered_invited_guest(self):
        """Check that statuses are correct for a registered invited guest."""
        self.seed_static_data()
        invited = InvitedGuest(event_id=self.event.id,
                               user_id=self.user1.id,
                               role='Mentor')
        db.session.add(invited)

        # Check un-confirmed guest registration
        guest_registration = GuestRegistration(
            user_id=self.user1.id,
            registration_form_id=self.registration_form.id,
            confirmed=False)

        db.session.add(guest_registration)
        db.session.commit()

        status = event_status.get_event_status(self.event.id, self.user1.id)
        self.assertEqual(status.invited_guest, 'Mentor')
        self.assertEqual(status.registration_status, 'Not Confirmed')
        self.assertIsNone(status.application_status)
        self.assertIsNone(status.outcome_status)
        self.assertIsNone(status.offer_status)

        # Check confirmed guest registration
        guest_registration.confirm(datetime.now())
        db.session.commit()

        status = event_status.get_event_status(self.event.id, self.user1.id)
        self.assertEqual(status.invited_guest, 'Mentor')
        self.assertEqual(status.registration_status, 'Confirmed')
        self.assertIsNone(status.application_status)
        self.assertIsNone(status.outcome_status)
        self.assertIsNone(status.offer_status)
Ejemplo n.º 6
0
Archivo: api.py Proyecto: mxaba/Baobab
    def post(self, send_email=True):
        args = self.req_parser.parse_args()
        event_id = args['event_id']
        email = args['email']
        role = args['role']

        user = user_repository.get_by_email(email, g.organisation.id)

        if not user:
            return USER_NOT_FOUND

        event = event_repository.get_by_id(event_id)
        if not event:
            return EVENT_NOT_FOUND

        existingInvitedGuest = db.session.query(InvitedGuest).filter(
            InvitedGuest.event_id == event_id).filter(
                InvitedGuest.user_id == user.id).first()

        if existingInvitedGuest:
            return INVITED_GUEST_FOR_EVENT_EXISTS

        invitedGuest = InvitedGuest(event_id=event_id,
                                    user_id=user.id,
                                    role=role)

        db.session.add(invitedGuest)

        try:
            db.session.commit()
        except IntegrityError:
            LOGGER.error("Failed to add invited guest: {}".format(email))
            return ADD_INVITED_GUEST_FAILED

        if send_email:
            try:
                send_mail(recipient=user.email,
                          subject='Your invitation to {}'.format(event.name),
                          body_text=GUEST_EMAIL_TEMPLATE.format(
                              user_title=user.user_title,
                              firstname=user.firstname,
                              lastname=user.lastname,
                              role=role,
                              event_name=event.name,
                              event_key=event.key,
                              system_name=g.organisation.system_name,
                              host=misc.get_baobab_host()))
            except Exception as e:
                LOGGER.error(
                    'Failed to send email to invited guest with user Id {}, due to {}'
                    .format(user.id, e))
                return INVITED_GUEST_EMAIL_FAILED

        return invitedGuest_info(invitedGuest, user), 201
Ejemplo n.º 7
0
    def post(self, send_email=True):
        args = self.req_parser.parse_args()
        event_id = args['event_id']
        email = args['email']
        role = args['role']

        user = user_repository.get_by_email(email, g.organisation.id)

        if not user:
            return USER_NOT_FOUND

        event = event_repository.get_by_id(event_id)
        if not event:
            return EVENT_NOT_FOUND

        existingInvitedGuest = db.session.query(InvitedGuest).filter(
            InvitedGuest.event_id == event_id).filter(InvitedGuest.user_id == user.id).first()

        if existingInvitedGuest:
            return INVITED_GUEST_FOR_EVENT_EXISTS

        invitedGuest = InvitedGuest(
            event_id=event_id,
            user_id=user.id,
            role=role
        )

        db.session.add(invitedGuest)

        try:
            db.session.commit()
        except IntegrityError:
            LOGGER.error(
                "Failed to add invited guest: {}".format(email))
            return ADD_INVITED_GUEST_FAILED

        if send_email:
            try:
                email_user(
                    'guest-invitation-with-registration' if event.is_registration_open else 'guest-invitation',
                    template_parameters=dict(
                        role=role,
                        system_name=g.organisation.system_name,
                        host=misc.get_baobab_host(),
                        event_key=event.key
                    ),
                    event=event,
                    user=user)

            except Exception as e:
                LOGGER.error('Failed to send email to invited guest with user Id {}, due to {}'.format(user.id, e))
                return INVITED_GUEST_EMAIL_FAILED

        return invitedGuest_info(invitedGuest, user), 201
Ejemplo n.º 8
0
    def test_get_attendance_list_2(self):
        self.seed_static_data()
        mrObama = AppUser('*****@*****.**', 'Barack', 'Obama', 'Mr', 1,
                          1, 'M', 'Harvard', 'Law', 'NA', 1,
                          datetime(1984, 12, 12), 'Eng', 'abc')
        db.session.add(mrObama)
        db.session.commit()
        invited_guest_id = mrObama.id
        role = "EveryRole"
        mrObamaInvitedGuest = InvitedGuest(event_id=1,
                                           user_id=invited_guest_id,
                                           role=role)
        db.session.add(mrObamaInvitedGuest)
        db.session.commit()
        header = self.get_auth_header_for('*****@*****.**')

        # Invited Guests always get returned
        params = {'event_id': 1}
        result = self.app.get('/api/v1/registration/confirmed',
                              headers=header,
                              data=params)
        data = json.loads(result.data)
        self.assertGreaterEqual(len(data), 1)
        is_invited_guest_returned = False
        for attendee in data:
            if (attendee['user_id'] == invited_guest_id):
                is_invited_guest_returned = True
        self.assertTrue(is_invited_guest_returned)

        # Confirm Attendance of Invited Guest
        params = {'user_id': invited_guest_id, 'event_id': 1}
        attendance_response = self.app.post('/api/v1/attendance',
                                            headers=header,
                                            data=params)

        response = json.loads(attendance_response.data)
        self.assertEquals(response['is_invitedguest'], True)
        self.assertEquals(response['invitedguest_role'], role)

        # No Invited Guest since he/she has already been signed in.
        params = {'event_id': 1, 'exclude_already_signed_in': True}
        result2 = self.app.get('/api/v1/registration/confirmed',
                               headers=header,
                               data=params)
        data2 = json.loads(result2.data)
        is_invited_guest_returned = False
        for attendee in data2:
            if (attendee['user_id'] == invited_guest_id):
                is_invited_guest_returned = True

        self.assertFalse(is_invited_guest_returned)
Ejemplo n.º 9
0
    def test_get_attendance_list_3(self):
        self.seed_static_data()
        # Add attendee as Invited Guest as well
        invited_guest_id = self.attendee.id
        dupl_attendee = InvitedGuest(event_id=1, user_id=invited_guest_id, role='EveryRole')
        db.session.add(dupl_attendee)
        db.session.commit()

        header = self.get_auth_header_for('*****@*****.**')
        params = { 'event_id': 1}
        result = self.app.get(
            '/api/v1/registration/confirmed', headers=header, data=params)
        data = json.loads(result.data)
        occurences_in_attendance_list = [att for att in data if att['user_id'] == invited_guest_id]
        num_occurences_in_attendance_list = len(occurences_in_attendance_list)
        self.assertEqual(num_occurences_in_attendance_list,1)
Ejemplo n.º 10
0
    def test_invited_guest_and_applied(self):
        """Check invited guest status when the user also applied."""
        self.seed_static_data()
        invited = InvitedGuest(event_id=self.event.id,
                               user_id=self.user1.id,
                               role='Mentor')
        db.session.add(invited)

        self.add_response(self.application_form.id, self.user1.id)

        status = event_status.get_event_status(self.event.id, self.user1.id)

        self.assertEqual(status.invited_guest, 'Mentor')
        self.assertIsNone(status.registration_status)
        self.assertIsNone(status.application_status)
        self.assertIsNone(status.outcome_status)
        self.assertIsNone(status.offer_status)
Ejemplo n.º 11
0
    def test_invited_guest_unregistered(self):
        """Check that un-registred invited guest statuses are correct."""
        self.seed_static_data()
        invited = InvitedGuest(event_id=self.event.id,
                               user_id=self.user1.id,
                               role='Mentor')
        db.session.add(invited)
        db.session.commit()

        status = event_status.get_event_status(self.event.id, self.user1.id)
        self.assertEqual(status.invited_guest, 'Mentor')
        self.assertIsNone(status.registration_status)
        self.assertIsNone(status.application_status)
        self.assertIsNone(status.outcome_status)
        self.assertIsNone(status.offer_status)

        # Check no interference with other user and other event
        status = event_status.get_event_status(self.event.id, self.user2.id)
        self.assertIsNone(status.invited_guest)

        status = event_status.get_event_status(self.event2.id, self.user1.id)
        self.assertIsNone(status.invited_guest)