def test_higher_priority_1(self):
        """Both exercise groups are occupied by Bolek and Lolek. Tola will
        enqueue to both with different priorities. She will end up in the group
        of higher priority regardless of the order in which Bolek and Lolek free
        up the places.
        """
        with patch(RECORDS_DATETIME, mock_datetime(2011, 10, 1, 12)):
            self.assertTrue(
                Record.enqueue_student(self.bolek,
                                       self.cooking_exercise_group_1))
            self.assertTrue(
                Record.enqueue_student(self.lolek,
                                       self.cooking_exercise_group_2))

        with patch(RECORDS_DATETIME, mock_datetime(2011, 10, 1, 13)):
            self.assertTrue(
                Record.enqueue_student(self.tola,
                                       self.cooking_exercise_group_1))
            self.assertTrue(
                Record.set_queue_priority(self.tola,
                                          self.cooking_exercise_group_1, 7))
            self.assertTrue(
                Record.enqueue_student(self.tola,
                                       self.cooking_exercise_group_2))
            self.assertTrue(
                Record.set_queue_priority(self.tola,
                                          self.cooking_exercise_group_2, 8))

        self.assertTrue(
            Record.is_recorded(self.tola, self.cooking_exercise_group_1))
        self.assertTrue(
            Record.is_recorded(self.tola, self.cooking_exercise_group_2))
        self.assertFalse(
            Record.is_enrolled(self.tola, self.cooking_exercise_group_1))
        self.assertFalse(
            Record.is_enrolled(self.tola, self.cooking_exercise_group_2))

        with patch(RECORDS_DATETIME, mock_datetime(2011, 10, 8, 12)):
            self.assertCountEqual(
                Record.remove_from_group(self.bolek,
                                         self.cooking_exercise_group_1),
                [self.cooking_exercise_group_1.pk])
        with patch(RECORDS_DATETIME, mock_datetime(2011, 10, 8, 13)):
            self.assertCountEqual(
                Record.remove_from_group(self.lolek,
                                         self.cooking_exercise_group_2),
                [self.cooking_exercise_group_2.pk])

        self.assertFalse(
            Record.is_recorded(self.tola, self.cooking_exercise_group_1))
        self.assertTrue(
            Record.is_enrolled(self.tola, self.cooking_exercise_group_2))
    def test_higher_priority_2(self):
        """The only difference between this test and the one above is the order
        in which Bolek and Lolek leave their groups.
        """
        with patch(RECORDS_DATETIME, mock_datetime(2011, 10, 1, 12)):
            self.assertTrue(
                Record.enqueue_student(self.bolek,
                                       self.cooking_exercise_group_1))
            self.assertTrue(
                Record.enqueue_student(self.lolek,
                                       self.cooking_exercise_group_2))

        with patch(RECORDS_DATETIME, mock_datetime(2011, 10, 1, 13)):
            self.assertTrue(
                Record.enqueue_student(self.tola,
                                       self.cooking_exercise_group_1))
            self.assertTrue(
                Record.set_queue_priority(self.tola,
                                          self.cooking_exercise_group_1, 7))
            self.assertTrue(
                Record.enqueue_student(self.tola,
                                       self.cooking_exercise_group_2))
            self.assertTrue(
                Record.set_queue_priority(self.tola,
                                          self.cooking_exercise_group_2, 8))

        self.assertTrue(
            Record.is_recorded(self.tola, self.cooking_exercise_group_1))
        self.assertTrue(
            Record.is_recorded(self.tola, self.cooking_exercise_group_2))
        self.assertFalse(
            Record.is_enrolled(self.tola, self.cooking_exercise_group_1))
        self.assertFalse(
            Record.is_enrolled(self.tola, self.cooking_exercise_group_2))

        with patch(RECORDS_DATETIME, mock_datetime(2011, 10, 8, 12)):
            self.assertCountEqual(
                Record.remove_from_group(self.lolek,
                                         self.cooking_exercise_group_2),
                [self.cooking_exercise_group_2.pk])
        with patch(RECORDS_DATETIME, mock_datetime(2011, 10, 8, 13)):
            self.assertCountEqual(
                Record.remove_from_group(self.bolek,
                                         self.cooking_exercise_group_1),
                [self.cooking_exercise_group_1.pk])

        self.assertFalse(
            Record.is_recorded(self.tola, self.cooking_exercise_group_1))
        self.assertTrue(
            Record.is_enrolled(self.tola, self.cooking_exercise_group_2))
Example #3
0
    def test_isim_not_involved(self):
        """When ISIM students are not involved, enrollment behaves normally."""
        with freeze_time(self.opening_time + timedelta(seconds=5)):
            Record.enqueue_student(self.bolek, self.group)
        with freeze_time(self.opening_time + timedelta(seconds=10)):
            Record.enqueue_student(self.lolek, self.group)
        with freeze_time(self.opening_time + timedelta(seconds=15)):
            Record.enqueue_student(self.reksio, self.group)

        self.assertTrue(Record.is_enrolled(self.bolek, self.group))
        self.assertTrue(Record.is_enrolled(self.lolek, self.group))
        self.assertFalse(Record.is_enrolled(self.reksio, self.group))
        self.assertTrue(Record.is_recorded(self.reksio, self.group))

        with freeze_time(self.opening_time + timedelta(minutes=5)):
            Record.remove_from_group(self.lolek, self.group)

        self.assertTrue(Record.is_enrolled(self.bolek, self.group))
        self.assertTrue(Record.is_enrolled(self.reksio, self.group))
        self.assertFalse(Record.is_recorded(self.lolek, self.group))
Example #4
0
    def test_one_isim_student(self):
        """When one ISIM student comes, he can take the guaranteed place."""
        with freeze_time(self.opening_time + timedelta(seconds=5)):
            Record.enqueue_student(self.bolek, self.group)
        with freeze_time(self.opening_time + timedelta(seconds=10)):
            Record.enqueue_student(self.lolek, self.group)
        with freeze_time(self.opening_time + timedelta(seconds=15)):
            Record.enqueue_student(self.reksio, self.group)

        # At this point one guy (Reksio) is in the queue.
        self.assertTrue(Record.is_enrolled(self.bolek, self.group))
        self.assertTrue(Record.is_enrolled(self.lolek, self.group))
        self.assertFalse(Record.is_enrolled(self.reksio, self.group))
        self.assertTrue(Record.is_recorded(self.reksio, self.group))

        with freeze_time(self.opening_time + timedelta(minutes=1)):
            Record.enqueue_student(self.tola, self.group)

        # Reksio is still waiting, but Tola took the ISIM guaranteed spot.
        self.assertTrue(Record.is_enrolled(self.bolek, self.group))
        self.assertTrue(Record.is_enrolled(self.lolek, self.group))
        self.assertFalse(Record.is_enrolled(self.reksio, self.group))
        self.assertTrue(Record.is_recorded(self.reksio, self.group))
        self.assertTrue(Record.is_enrolled(self.tola, self.group))

        with freeze_time(self.opening_time + timedelta(minutes=5)):
            Record.remove_from_group(self.lolek, self.group)

        self.assertTrue(Record.is_enrolled(self.bolek, self.group))
        self.assertTrue(Record.is_enrolled(self.reksio, self.group))
        self.assertFalse(Record.is_recorded(self.lolek, self.group))
        self.assertTrue(Record.is_enrolled(self.tola, self.group))

        with freeze_time(self.opening_time + timedelta(minutes=10)):
            Record.enqueue_student(self.lolek, self.group)

        # Now Lolek sits in the queue.
        self.assertTrue(Record.is_recorded(self.lolek, self.group))
        self.assertFalse(Record.is_enrolled(self.lolek, self.group))

        with freeze_time(self.opening_time + timedelta(minutes=15)):
            Record.remove_from_group(self.tola, self.group)

        # Now that Tola has left, the ISIM spot is free, but Lolek is still in
        # the queue.
        self.assertFalse(Record.is_recorded(self.tola, self.group))
        self.assertTrue(Record.is_recorded(self.lolek, self.group))
        self.assertFalse(Record.is_enrolled(self.lolek, self.group))