コード例 #1
0
    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))
コード例 #2
0
    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))
コード例 #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))
コード例 #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))
コード例 #5
0
    def test_two_isim_students(self):
        """When there are two ISIM students, they compete for the regular spots
        and the guaranteed spot at the same time.
        """
        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.tola, self.group)
        # Bolek and Lolek are in the regular spots, Tola has taken the
        # ISIM-guaranteed extra spot.
        self.assertTrue(Record.is_enrolled(self.bolek, self.group))
        self.assertTrue(Record.is_enrolled(self.lolek, self.group))
        self.assertTrue(Record.is_enrolled(self.tola, self.group))

        with freeze_time(self.opening_time + timedelta(seconds=20)):
            Record.enqueue_student(self.reksio, self.group)
        with freeze_time(self.opening_time + timedelta(seconds=25)):
            Record.enqueue_student(self.uszatek, self.group)
        # Now both Reksio and Uszatek are waiting.
        self.assertFalse(Record.is_enrolled(self.reksio, self.group))
        self.assertFalse(Record.is_enrolled(self.uszatek, self.group))

        with freeze_time(self.opening_time + timedelta(seconds=30)):
            Record.remove_from_group(self.tola, self.group)
        # Now Uszatek jumps into the guaranteed spot even though he is not first
        # in line.
        self.assertFalse(Record.is_enrolled(self.reksio, self.group))
        self.assertTrue(Record.is_enrolled(self.uszatek, self.group))

        with freeze_time(self.opening_time + timedelta(seconds=35)):
            Record.enqueue_student(self.tola, self.group)
            Record.remove_from_group(self.lolek, self.group)
        # Now Reksio takes up the regular spot. Tola is waiting.
        self.assertTrue(Record.is_enrolled(self.reksio, self.group))
        self.assertFalse(Record.is_enrolled(self.tola, self.group))

        with freeze_time(self.opening_time + timedelta(seconds=40)):
            Record.enqueue_student(self.lolek, self.group)
        with freeze_time(self.opening_time + timedelta(seconds=45)):
            Record.remove_from_group(self.bolek, self.group)
        # Now Tola assumes the regular spot, because she was in line before
        # Lolek.
        self.assertTrue(Record.is_enrolled(self.uszatek, self.group))
        self.assertTrue(Record.is_enrolled(self.tola, self.group))
        self.assertFalse(Record.is_enrolled(self.lolek, self.group))