Beispiel #1
0
    def test_term_post_save(self):
        """Test that when terms are saved, the "Current" groups are kept
        up-to-date.
        """
        self.assertFalse(self.user.groups.exists())  # No groups yet

        # Add an exec officer position (for which the post-save should add
        # groups) in the current term:
        officer_exec = Officer(user=self.user,
                               position=self.position_exec,
                               term=self.term)
        officer_exec.save()
        expected_groups = set(
            self.position_exec.get_corresponding_groups(term=self.term))
        groups = list(self.user.groups.all())
        self.assertTrue(len(groups) > 0)
        self.assertItemsEqual(groups, expected_groups)

        # Make sure saving the current term is a no-op:
        self.term.save()
        groups = list(self.user.groups.all())
        self.assertItemsEqual(groups, expected_groups)

        # Add a regular officer position for this user in a new term (not
        # "current"), and the user's group count should increase:
        term_new = Term(term=Term.FALL, year=2012)
        term_new.save()
        officer_reg = Officer(user=self.user,
                              position=self.position_regular,
                              term=term_new)
        officer_reg.save()
        expected_groups.update(
            self.position_regular.get_corresponding_groups(term=term_new))
        groups = list(self.user.groups.all())
        self.assertItemsEqual(groups, expected_groups)

        # Now change the "new" term to be the current term:
        term_new.current = True
        term_new.save()

        # The self.term object is stale now, so re-fetch it from the database:
        self.term = Term.objects.get(pk=self.term.pk)

        # We should expect that the user should still be a "Current Officer",
        # but no longer "Current" for the groups specific to the exec position.
        groups = list(self.user.groups.all())
        # Get "expected_groups" over again, since the current term has changed:
        expected_groups = set(
            self.position_exec.get_corresponding_groups(term=self.term))
        expected_groups.update(
            self.position_regular.get_corresponding_groups(term=term_new))
        self.assertItemsEqual(groups, expected_groups)

        # Double-check some of the "Current" groups:
        self.assertNotIn(self.exec_group_curr, groups)
        self.assertNotIn(self.pos_exec_group_curr, groups)
        self.assertIn(self.officer_group_curr, groups)
        self.assertIn(self.pos_reg_group_curr, groups)
Beispiel #2
0
    def test_save(self):
        spring = Term(term=Term.SPRING, year=2012, current=False)
        spring.save()
        fall = Term(term=Term.FALL, year=2012, current=False)
        fall.save()

        self.assertFalse(Term.objects.filter(current=True).exists())

        spring.current = True
        spring.save()
        current = Term.objects.filter(current=True)
        self.assertEquals(len(current), 1)
        self.assertEquals(current[0].year, 2012)
        self.assertEquals(current[0].term, Term.SPRING)

        fall.current = True
        fall.save()
        current = Term.objects.filter(current=True)
        self.assertEquals(len(current), 1)
        self.assertEquals(current[0].year, 2012)
        self.assertEquals(current[0].term, Term.FALL)
Beispiel #3
0
    def test_save(self):
        spring = Term(term=Term.SPRING, year=2012, current=False)
        spring.save()
        fall = Term(term=Term.FALL, year=2012, current=False)
        fall.save()

        self.assertFalse(Term.objects.filter(current=True).exists())

        spring.current = True
        spring.save()
        current = Term.objects.filter(current=True)
        self.assertEquals(len(current), 1)
        self.assertEquals(current[0].year, 2012)
        self.assertEquals(current[0].term, Term.SPRING)

        fall.current = True
        fall.save()
        current = Term.objects.filter(current=True)
        self.assertEquals(len(current), 1)
        self.assertEquals(current[0].year, 2012)
        self.assertEquals(current[0].term, Term.FALL)
Beispiel #4
0
    def test_term_post_save(self):
        """Test that when terms are saved, the "Current" groups are kept
        up-to-date.
        """
        self.assertFalse(self.user.groups.exists())  # No groups yet

        # Add an exec officer position (for which the post-save should add
        # groups) in the current term:
        officer_exec = Officer(user=self.user, position=self.position_exec, term=self.term)
        officer_exec.save()
        expected_groups = set(self.position_exec.get_corresponding_groups(term=self.term))
        groups = list(self.user.groups.all())
        self.assertTrue(len(groups) > 0)
        self.assertItemsEqual(groups, expected_groups)

        # Make sure saving the current term is a no-op:
        self.term.save()
        groups = list(self.user.groups.all())
        self.assertItemsEqual(groups, expected_groups)

        # Add a regular officer position for this user in a new term (not
        # "current"), and the user's group count should increase:
        term_new = Term(term=Term.FALL, year=2012)
        term_new.save()
        officer_reg = Officer(user=self.user, position=self.position_regular, term=term_new)
        officer_reg.save()
        expected_groups.update(self.position_regular.get_corresponding_groups(term=term_new))
        groups = list(self.user.groups.all())
        self.assertItemsEqual(groups, expected_groups)

        # Now change the "new" term to be the current term:
        term_new.current = True
        term_new.save()

        # The self.term object is stale now, so re-fetch it from the database:
        self.term = Term.objects.get(pk=self.term.pk)

        # We should expect that the user should still be a "Current Officer",
        # but no longer "Current" for the groups specific to the exec position.
        groups = list(self.user.groups.all())
        # Get "expected_groups" over again, since the current term has changed:
        expected_groups = set(self.position_exec.get_corresponding_groups(term=self.term))
        expected_groups.update(self.position_regular.get_corresponding_groups(term=term_new))
        self.assertItemsEqual(groups, expected_groups)

        # Double-check some of the "Current" groups:
        self.assertNotIn(self.exec_group_curr, groups)
        self.assertNotIn(self.pos_exec_group_curr, groups)
        self.assertIn(self.officer_group_curr, groups)
        self.assertIn(self.pos_reg_group_curr, groups)