Exemplo n.º 1
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)
Exemplo n.º 2
0
    def test_offer(self):
        """Test statuses when offer."""
        self.seed_static_data()

        outcome = Outcome(self.event.id, self.user1.id, OutcomeStatus.ACCEPTED,
                          self.user2.id)
        db.session.add(outcome)

        self.add_response(self.application_form.id,
                          self.user1.id,
                          is_submitted=True)

        # Test pending offer
        offer = Offer(user_id=self.user1.id,
                      event_id=self.event.id,
                      offer_date=date.today(),
                      expiry_date=date.today() + timedelta(days=1),
                      payment_required=False,
                      travel_award=False,
                      accommodation_award=False)
        db.session.add(offer)
        db.session.commit()

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

        # Test accepted offer
        offer.candidate_response = True
        db.session.commit()
        status = event_status.get_event_status(self.event.id, self.user1.id)
        self.assertIsNone(status.invited_guest)
        self.assertIsNone(status.registration_status)
        self.assertEqual(status.application_status, 'Submitted')
        self.assertEqual(status.outcome_status, outcome.status.name)
        self.assertEqual(status.offer_status, 'Accepted')

        # Should still be accepted when past the expiry date
        offer.expiry_date = date.today() - timedelta(days=2)
        db.session.commit()
        status = event_status.get_event_status(self.event.id, self.user1.id)
        self.assertEqual(status.offer_status, 'Accepted')

        # Test expired offer
        offer.candidate_response = None
        db.session.commit()
        status = event_status.get_event_status(self.event.id, self.user1.id)
        self.assertEqual(status.offer_status, 'Expired')

        # Test rejected offer
        offer.candidate_response = False
        db.session.commit()
        status = event_status.get_event_status(self.event.id, self.user1.id)
        self.assertEqual(status.offer_status, 'Rejected')
Exemplo n.º 3
0
    def test_applied(self):
        """Test statuses when the user has applied."""
        self.seed_static_data()
        # Candidate has not submitted or withdrawn
        response = self.add_response(self.application_form.id, self.user1.id)

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

        self.assertIsNone(status.invited_guest)
        self.assertIsNone(status.registration_status)
        self.assertEqual(status.application_status, 'Not Submitted')
        self.assertIsNone(status.outcome_status)
        self.assertIsNone(status.offer_status)

        # Submitted
        response.submit()
        db.session.commit()

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

        self.assertIsNone(status.invited_guest)
        self.assertIsNone(status.registration_status)
        self.assertEqual(status.application_status, 'Submitted')
        self.assertIsNone(status.outcome_status)
        self.assertIsNone(status.offer_status)

        # Withdrawn
        response.withdraw()
        db.session.commit()

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

        self.assertIsNone(status.invited_guest)
        self.assertIsNone(status.registration_status)
        self.assertEqual(status.application_status, 'Withdrawn')
        self.assertIsNone(status.outcome_status)
        self.assertIsNone(status.offer_status)

        status = event_status.get_event_status(self.event.id, self.user2.id)
        self.assertIsNone(status.invited_guest)
        self.assertIsNone(status.registration_status)
        self.assertIsNone(status.application_status)
        self.assertIsNone(status.outcome_status)
        self.assertIsNone(status.offer_status)

        status = event_status.get_event_status(self.event2.id, self.user1.id)
        self.assertIsNone(status.invited_guest)
        self.assertIsNone(status.registration_status)
        self.assertIsNone(status.application_status)
        self.assertIsNone(status.outcome_status)
        self.assertIsNone(status.offer_status)
Exemplo n.º 4
0
    def post(self):
        args = self.req_parser.parse_args()
        event_id = args['event_id']
        user = get_user_from_request()
        status = event_status.get_event_status(event_id, user['id'])

        if (not status.is_event_attendee):
            return UNAUTHORIZED

        return 200
Exemplo n.º 5
0
    def test_registered(self):
        """Test statusess for registered attendees."""
        self.seed_static_data()

        outcome = Outcome(self.event.id, self.user1.id, OutcomeStatus.ACCEPTED,
                          self.user2.id)
        db.session.add(outcome)

        self.add_response(self.application_form.id,
                          self.user1.id,
                          is_submitted=True)

        offer = Offer(user_id=self.user1.id,
                      event_id=self.event.id,
                      offer_date=date.today(),
                      expiry_date=date.today() + timedelta(days=1),
                      payment_required=False,
                      travel_award=False,
                      accommodation_award=False,
                      candidate_response=True)
        db.session.add(offer)
        db.session.commit()

        registration = Registration(offer.id, self.registration_form.id)
        db.session.add(registration)
        db.session.commit()

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

        registration.confirm()
        db.session.commit()

        status = event_status.get_event_status(self.event.id, self.user1.id)
        self.assertEqual(status.registration_status, 'Confirmed')
Exemplo n.º 6
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)
Exemplo n.º 7
0
    def test_outcome(self):
        """Check statuses when the user has an outcome."""
        self.seed_static_data()

        # Check that status is invalid if there is an outcome with not application (response)
        outcome = Outcome(self.event.id, self.user1.id, OutcomeStatus.ACCEPTED,
                          self.user2.id)
        db.session.add(outcome)

        with self.assertRaises(ValueError):
            event_status.get_event_status(self.event.id, self.user1.id)

        # Check status when user has applied and has an outcome
        self.add_response(self.application_form.id,
                          self.user1.id,
                          is_submitted=True)

        status = event_status.get_event_status(self.event.id, self.user1.id)
        self.assertIsNone(status.invited_guest)
        self.assertIsNone(status.registration_status)
        self.assertEqual(status.application_status, 'Submitted')
        self.assertEqual(status.outcome_status, outcome.status.name)
        self.assertIsNone(status.offer_status)
Exemplo n.º 8
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)
Exemplo n.º 9
0
    def get(self):
        args = self.req_parser.parse_args()

        user_id = g.current_user['id']
        language = args['language']
        if language is None or len(language) > 2:
            LOGGER.warning(
                "Missing or invalid language parameter for EventsByKeyAPI. Defaulting to 'en'"
            )
            default_language = 'en'
            language = default_language

        event = event_repository.get_by_key(args['event_key'])
        if not event:
            return EVENT_WITH_KEY_NOT_FOUND

        if not event.has_specific_translation(language):
            return EVENT_WITH_TRANSLATION_NOT_FOUND

        info = event_info(g.current_user['id'], event,
                          event_status.get_event_status(event.id, user_id),
                          language)
        return info, 200
Exemplo n.º 10
0
    def get(self):
        user_id = g.current_user["id"]
        language = request.args['language']
        default_language = 'en'

        upcoming_events = event_repository.get_upcoming_for_organisation(
            g.organisation.id)
        attended_events = event_repository.get_attended_by_user_for_organisation(
            g.organisation.id, user_id)

        returnEvents = []

        for event in itertools.chain(upcoming_events, attended_events):
            if not event.has_specific_translation(language):
                LOGGER.error('Missing {} translation for event {}.'.format(
                    language, event.id))
                language = default_language
            status = None if user_id == 0 else event_status.get_event_status(
                event.id, user_id)
            returnEvents.append(event_info(user_id, event, status, language))
            language = request.args['language']

        return returnEvents, 200