Ejemplo n.º 1
0
    def test_remove_groups(self):
        # Test the Officer method for removing the user from groups. Note that
        # unlike test_add_groups, this method saves the Officer objets, as the
        # _remove_user_from_officer_groups method depends on database entries
        # to work properly. Thus, this method relies on post-save functions for
        # adding groups for a user. (Post-saves are also tested separately.)
        self.assertFalse(self.user.groups.exists())  # No groups yet

        # Add a regular officer position (for which the post-save should add
        # groups):
        officer_reg = Officer(user=self.user,
                              position=self.position_regular,
                              term=self.term)
        officer_reg.save()
        groups = list(self.user.groups.all())
        self.assertTrue(len(groups) > 0)

        # Add the groups for an exec officer position manually so that the
        # Officer object is not in the database (and does not need to be
        # deleted here before we can test the removal function), and the user's
        # group count should increase:
        officer_exec = Officer(user=self.user,
                               position=self.position_exec,
                               term=self.term)
        officer_exec._add_user_to_officer_groups()
        self.assertTrue(len(groups) < self.user.groups.count())

        # Now remove groups from the exec position, and the user's groups
        # should return to the same positions as from before the exec position
        # added any:
        officer_exec._remove_user_from_officer_groups()
        self.assertItemsEqual(groups, list(self.user.groups.all()))
Ejemplo n.º 2
0
    def test_remove_groups(self):
        # Test the Officer method for removing the user from groups. Note that
        # unlike test_add_groups, this method saves the Officer objets, as the
        # _remove_user_from_officer_groups method depends on database entries
        # to work properly. Thus, this method relies on post-save functions for
        # adding groups for a user. (Post-saves are also tested separately.)
        self.assertFalse(self.user.groups.exists())  # No groups yet

        # Add a regular officer position (for which the post-save should add
        # groups):
        officer_reg = Officer(user=self.user, position=self.position_regular, term=self.term)
        officer_reg.save()
        groups = list(self.user.groups.all())
        self.assertTrue(len(groups) > 0)

        # Add the groups for an exec officer position manually so that the
        # Officer object is not in the database (and does not need to be
        # deleted here before we can test the removal function), and the user's
        # group count should increase:
        officer_exec = Officer(user=self.user, position=self.position_exec, term=self.term)
        officer_exec._add_user_to_officer_groups()
        self.assertTrue(len(groups) < self.user.groups.count())

        # Now remove groups from the exec position, and the user's groups
        # should return to the same positions as from before the exec position
        # added any:
        officer_exec._remove_user_from_officer_groups()
        self.assertItemsEqual(groups, list(self.user.groups.all()))