Ejemplo n.º 1
0
    def test_auto_assign_two(self):
        """
        Assign two shifts to a member.
        """
        shift1 = RegularWorkshift.objects.create(
            workshift_type=self.wtype1,
            pool=self.p1,
            hours=2,
        )
        shift2 = RegularWorkshift.objects.create(
            workshift_type=self.wtype1,
            pool=self.p1,
            hours=3,
        )

        unfinished = utils.auto_assign_shifts(self.semester)
        self.assertEqual([], unfinished)
        self.assertIn(self.profile, shift1.current_assignees.all())
        self.assertIn(self.profile, shift2.current_assignees.all())

        for shift in [shift1, shift2]:
            instances = WorkshiftInstance.objects.filter(
                weekly_workshift=shift,
            )
            self.assertGreater(instances.count(), 0)
            self.assertTrue(all(
                instance.workshifter == self.profile
                for instance in instances
            ))

        pool_hours = self.profile.pool_hours.get(pool=self.p1)
        self.assertEqual(
            pool_hours.assigned_hours,
            pool_hours.hours,
        )
Ejemplo n.º 2
0
    def test_auto_assign_one_overflow(self):
        """
        Don't assign one shift to a member because it pushes them over their
        weekly requirement.
        """
        shift1 = RegularWorkshift.objects.create(
            workshift_type=self.wtype1,
            pool=self.p1,
            hours=6,
        )
        unfinished = utils.auto_assign_shifts(self.semester)
        self.assertEqual([self.profile], unfinished)
        self.assertNotIn(self.profile, shift1.current_assignees.all())

        instances = WorkshiftInstance.objects.filter(weekly_workshift=shift1)
        self.assertGreater(instances.count(), 0)
        self.assertTrue(all(
            instance.workshifter is None
            for instance in instances
        ))

        pool_hours = self.profile.pool_hours.get(pool=self.p1)
        self.assertEqual(
            pool_hours.assigned_hours,
            0,
        )
Ejemplo n.º 3
0
    def test_pre_assigned(self):
        """
        Test that assignment behaves correctly when members are already
        assigned to other workshifts.
        """
        shift1 = RegularWorkshift.objects.create(
            workshift_type=self.wtype1,
            pool=self.p1,
            hours=5,
        )
        shift2 = RegularWorkshift.objects.create(
            workshift_type=self.wtype3,
            pool=self.p1,
            hours=1,
        )
        shift2.current_assignees = [self.profile]

        unfinished = utils.auto_assign_shifts(self.semester)
        self.assertEqual([self.profile], unfinished)
        self.assertNotIn(self.profile, shift1.current_assignees.all())

        pool_hours = self.profile.pool_hours.get(pool=self.p1)
        self.assertEqual(
            pool_hours.assigned_hours,
            1,
        )
Ejemplo n.º 4
0
 def test_pre_fill_and_assign(self):
     """
     Tests that shifts can be correctly assigned after
     farnsworth/pre_fill.py is run. This is a good test of how the
     assignment code functions "in the wild," rather than with many
     duplicates of the same shift.
     """
     users = []
     for i in range(1, 50):
         users.append(User.objects.create_user(username="******".format(i)))
     pre_fill.main(["--managers", "--workshift"])
     utils.make_workshift_pool_hours(semester=self.semester)
     # Assign manager shifts beforehand
     for user, manager in zip(users, Manager.objects.all()):
         manager.incumbent = UserProfile.objects.get(user=user)
         manager.save()
     unfinished = utils.auto_assign_shifts(self.semester)
     self.assertEqual([], unfinished)
Ejemplo n.º 5
0
 def _test_pre_fill_and_assign_humor(self):
     """
     Tests that humor shifts can be correctly assigned after
     farnsworth/pre_fill.py is run.
     """
     for i in range(1, 50):
         User.objects.create_user(username="******".format(i))
     pre_fill.main(["--managers", "--workshift"])
     utils.make_workshift_pool_hours(semester=self.semester)
     # Assign manager shifts beforehand
     manager_shifts = RegularWorkshift.objects.filter(
         pool=self.p1, workshift_type__auto_assign=False,
     )
     profiles = WorkshiftProfile.objects.all()
     for profile, shift in zip(profiles, manager_shifts):
         shift.current_assignees.add(profile)
         shift.save()
     unfinished = utils.auto_assign_shifts(
         self.semester, pool=WorkshiftPool.objects.get(title="Humor Shift")
     )
     self.assertEqual([], unfinished)
Ejemplo n.º 6
0
    def _test_auto_assign_one_hundred_and_fifty(self):
        """
        Assign 150 members to 150 shifts, with each shift providing 5 hours
        of workshift. Ensures that the assignments don't mysteriously break or
        run for an extremely long time for large houses.
        """
        shifts = []
        for i in range(150):
            shifts.append(
                RegularWorkshift.objects.create(
                    workshift_type=self.wtype1,
                    pool=self.p1,
                    hours=5,
                    )
                )
        for i in range(1, 150):
            User.objects.create_user(username="******".format(i))

        utils.make_workshift_pool_hours(semester=self.semester)
        unfinished = utils.auto_assign_shifts(self.semester)
        self.assertEqual([], unfinished)
        for shift in shifts:
            self.assertEqual(1, shift.current_assignees.count())
Ejemplo n.º 7
0
 def save(self):
     unfinished = utils.auto_assign_shifts(
         self.semester, pool=self.cleaned_data['pool'],
         )
     return unfinished
Ejemplo n.º 8
0
 def save(self):
     unfinished = utils.auto_assign_shifts(
         self.semester,
         pool=self.cleaned_data['pool'],
     )
     return unfinished