Esempio n. 1
0
    def test_warn_if_missing_after_lectures(self):
        """If lectures have ended, we warn participants without attendance."""
        factories.LectureAttendanceFactory.create(
            participant=self.participant, year=2022
        )
        # Participants cannot set attendance; that time has passed.
        self._allow_setting_attendance(False)

        # A future WS trip exists, which is a strong clue: it must be first week of WS
        with freeze_time("2022-01-04 12:00:00 EST"):
            factories.TripFactory(
                trip_date=date(2022, 1, 8),
                program=enums.Program.WINTER_SCHOOL.value,
            )

        # It's after 9 pm on Thursday (with future WS trips). Must be lecture day.
        with freeze_time("2022-01-06 22:00:00 EST"):
            resp = self.client.get('/')

        # This participant did not record their attendance!
        soup = BeautifulSoup(resp.content, 'html.parser')
        attendance = soup.find('h3', string='Lecture Attendance')
        self.assertEqual(
            strip_whitespace(attendance.find_next('p').text),
            "Attended You have attended this year's lectures!",
        )
Esempio n. 2
0
    def test_model_ordering(self):
        """ We can manually order some waitlist signups.

        The primary use case for manually re-ordering the waitlist is for when a
        participant who was previously on the trip has to be removed for some reason
        (lack of cars, is one example). Out of fairness, we manually order to the top.
        """
        trip = factories.TripFactory()

        # Order in which the signups are created will not determine waitlist order!
        spot_2 = factories.SignUpFactory.create(trip=trip, on_trip=False)
        spot_1 = factories.SignUpFactory.create(trip=trip, on_trip=False)
        spot_4 = factories.SignUpFactory.create(trip=trip, on_trip=False)
        spot_3 = factories.SignUpFactory.create(trip=trip, on_trip=False)
        # Demonstrate that signups are sorted by time of creation (since none have manual order)
        self.assertEqual(
            list(models.SignUp.objects.filter(trip=trip)),
            [spot_2, spot_1, spot_4, spot_3],
        )

        # Use a mix of manual ordering & falling back on ranking by creation time
        factories.WaitListSignupFactory.create(signup=spot_3, manual_order=None)
        factories.WaitListSignupFactory.create(signup=spot_2, manual_order=10)
        factories.WaitListSignupFactory.create(signup=spot_1, manual_order=11)
        factories.WaitListSignupFactory.create(signup=spot_4, manual_order=None)

        self.assertEqual(list(trip.waitlist.signups), [spot_1, spot_2, spot_3, spot_4])
Esempio n. 3
0
    def test_can_add_to_bottom_of_priority(self):
        """Adding signups with priority puts them beneath other priorities, but above non."""
        trip = factories.TripFactory()

        spot_3 = factories.SignUpFactory.create(trip=trip, on_trip=False)
        spot_1 = factories.SignUpFactory.create(trip=trip, on_trip=False)
        spot_2 = factories.SignUpFactory.create(trip=trip, on_trip=False)

        # Start with a simple waitlist with no manual ordering
        spot_5 = factories.SignUpFactory.create(trip=trip, on_trip=False)
        spot_4 = factories.SignUpFactory.create(trip=trip, on_trip=False)
        signup_utils.add_to_waitlist(spot_4)
        signup_utils.add_to_waitlist(spot_5)
        self.assertEqual(list(trip.waitlist.signups), [spot_4, spot_5])

        # Add each new signup to priority, but not the top spot
        signup_utils.add_to_waitlist(spot_1, prioritize=True, top_spot=False)
        self.assertEqual(list(trip.waitlist.signups), [spot_1, spot_4, spot_5])
        signup_utils.add_to_waitlist(spot_2, prioritize=True, top_spot=False)
        self.assertEqual(list(trip.waitlist.signups),
                         [spot_1, spot_2, spot_4, spot_5])
        signup_utils.add_to_waitlist(spot_3, prioritize=True, top_spot=False)
        self.assertEqual(list(trip.waitlist.signups),
                         [spot_1, spot_2, spot_3, spot_4, spot_5])

        # Adding to the top spot still works!
        signup = factories.SignUpFactory.create(trip=trip, on_trip=True)
        signup_utils.add_to_waitlist(signup, prioritize=True, top_spot=True)
        self.assertEqual(
            list(trip.waitlist.signups),
            [signup, spot_1, spot_2, spot_3, spot_4, spot_5],
        )
Esempio n. 4
0
    def test_creator_is_eligible_as_participant(self):
        """So long as the creator is not a leader, they count as a non-trip participant."""
        trip = factories.TripFactory()
        self.assertNotIn(trip.creator, trip.leaders.all())
        self.assertIn(trip.creator, signup_utils.non_trip_participants(trip))

        trip.leaders.add(trip.creator)

        self.assertIn(trip.creator, trip.leaders.all())
        self.assertNotIn(trip.creator,
                         signup_utils.non_trip_participants(trip))
Esempio n. 5
0
    def test_created_first(self):
        """ Without manual ordering, waitlist signups are ordered by creation time. """
        trip = factories.TripFactory()

        # Order in which the signups are created will not determine waitlist order!
        spot_2 = factories.SignUpFactory.create(trip=trip, on_trip=False)
        spot_1 = factories.SignUpFactory.create(trip=trip, on_trip=False)
        spot_4 = factories.SignUpFactory.create(trip=trip, on_trip=False)
        spot_3 = factories.SignUpFactory.create(trip=trip, on_trip=False)
        # Demonstrate that signups are sorted by time of creation (since none have manual order)
        self.assertEqual(
            list(models.SignUp.objects.filter(trip=trip)),
            [spot_2, spot_1, spot_4, spot_3],
        )

        # However, when we create waitlist signups, they're sorted by time of addition
        for signup in [spot_1, spot_2, spot_3, spot_4]:
            factories.WaitListSignupFactory.create(signup=signup)

        self.assertEqual(list(trip.waitlist.signups), [spot_1, spot_2, spot_3, spot_4])
Esempio n. 6
0
    def test_participants_on_trip(self):
        """All participants not signed up for the trip are returned."""
        trip = factories.TripFactory()
        on_trip = factories.ParticipantFactory.create()
        factories.SignUpFactory.create(participant=on_trip,
                                       trip=trip,
                                       on_trip=True)
        off_trip = factories.ParticipantFactory.create()
        signed_up_not_on_trip = factories.ParticipantFactory.create()
        factories.SignUpFactory.create(participant=signed_up_not_on_trip,
                                       trip=trip,
                                       on_trip=False)

        other_trip_signup = factories.SignUpFactory.create(on_trip=True)

        participants = signup_utils.non_trip_participants(trip)
        self.assertNotIn(on_trip, participants)
        self.assertIn(off_trip, participants)
        self.assertIn(signed_up_not_on_trip, participants)
        self.assertIn(other_trip_signup.participant, participants)
Esempio n. 7
0
    def test_can_add_to_top_of_list(self):
        """We can add somebody to the waitlist, passing all others."""
        trip = factories.TripFactory()

        # Build a waitlist with a mixture of ordered by time added & manually ordered
        spot_1 = factories.SignUpFactory.create(trip=trip, on_trip=False)
        spot_2 = factories.SignUpFactory.create(trip=trip, on_trip=False)
        spot_3 = factories.SignUpFactory.create(trip=trip, on_trip=False)
        spot_4 = factories.SignUpFactory.create(trip=trip, on_trip=False)
        factories.WaitListSignupFactory(signup=spot_3)
        factories.WaitListSignupFactory(signup=spot_4)
        factories.WaitListSignupFactory(signup=spot_2, manual_order=10)
        factories.WaitListSignupFactory(signup=spot_1, manual_order=11)
        self.assertEqual(list(trip.waitlist.signups),
                         [spot_1, spot_2, spot_3, spot_4])

        signup = factories.SignUpFactory.create(trip=trip, on_trip=True)
        signup_utils.add_to_waitlist(signup, prioritize=True, top_spot=True)
        self.assertEqual(list(trip.waitlist.signups),
                         [signup, spot_1, spot_2, spot_3, spot_4])
Esempio n. 8
0
    def test_attendance_not_shown_in_week_two(self):
        """We don't tell participants that they attended lectures after the first week."""
        factories.LectureAttendanceFactory.create(
            participant=self.participant, year=2022
        )

        # We created a trip for Saturday in the first weekend
        with freeze_time("2022-01-04 12:00:00 EST"):
            factories.TripFactory(
                trip_date=date(2022, 1, 8),
                program=enums.Program.WINTER_SCHOOL.value,
            )

        # It's Monday *after* the first week's trips.
        # It's possible that no new future trips exist.
        with freeze_time("2022-01-10 22:00:00 EST"):
            resp = self.client.get('/')

        # Because the participant *did* attend lectures, we don't take up space telling them that
        soup = BeautifulSoup(resp.content, 'html.parser')
        self.assertFalse(soup.find('h3', string='Lecture Attendance'))