Ejemplo n.º 1
0
    def test_officer_post_delete(self):
        """Test that a user is removed from the appropriate groups on
        post-delete.
        """
        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 an exec officer position for this user, and the user's group
        # count should increase:
        officer_exec = Officer(user=self.user,
                               position=self.position_exec,
                               term=self.term)
        officer_exec.save()
        self.assertTrue(len(groups) < self.user.groups.count())

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

        # And delete the regular officer, and the user should be part of no
        # more groups:
        officer_reg.delete()
        self.assertFalse(self.user.groups.exists())
Ejemplo n.º 2
0
    def test_officer_post_delete(self):
        """Test that a user is removed from the appropriate groups on
        post-delete.
        """
        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 an exec officer position for this user, and the user's group
        # count should increase:
        officer_exec = Officer(user=self.user, position=self.position_exec, term=self.term)
        officer_exec.save()
        self.assertTrue(len(groups) < self.user.groups.count())

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

        # And delete the regular officer, and the user should be part of no
        # more groups:
        officer_reg.delete()
        self.assertFalse(self.user.groups.exists())