Example #1
0
    def test_applications_needing_recommendation(self):
        """ Consider applications without a chair recommendation as requiring one! """
        # We have three chairs!
        self.assertEqual(perm_utils.num_chairs(enums.Activity.CLIMBING), 3)

        # The application is in a pending state, while awaiting recommendation & rating
        alice_manager = self._manager_for(self.alice)
        pending_apps = alice_manager.pending_applications()
        self.assertEqual(pending_apps, [self.application])
        self.assertEqual(alice_manager.needs_rec(pending_apps),
                         [self.application])

        # Once Alice makes a recommendation, it no longer needs a rec from her
        self._make_recommendation(creator=self.alice)
        # Refresh pending applications, as viewed from Alice's perspective
        pending_apps = alice_manager.pending_applications()
        self.assertEqual(alice_manager.needs_rec(pending_apps), [])

        # The application does, however, need recommendations from the other chairs!
        for other_chair in [self.bob, self.charlie]:
            manager = self._manager_for(other_chair)
            # Get pending apps from that chair's perspective!
            pending_apps = manager.pending_applications()
            self.assertEqual(manager.needs_rec(pending_apps),
                             [self.application])
Example #2
0
    def num_chairs(self):
        """ Return the number of chairs for this activity. """

        # It's important that this remain a property (dynamically requested, not stored at init)
        # This way, views that want to get activity from self.kwargs can inherit from the mixin
        if not hasattr(self, '_num_chairs'):
            self._num_chairs = perm_utils.num_chairs(self.activity)
        return self._num_chairs
Example #3
0
    def num_chairs(self):
        """ Return the number of chairs for this activity. """

        # It's important that this remain a property (dynamically requested, not stored at init)
        # This way, views that want to get activity from self.kwargs can inherit from the mixin
        if not hasattr(self, '_num_chairs'):
            activity_enum = enums.Activity(self.activity)
            self._num_chairs = perm_utils.num_chairs(activity_enum)
        return self._num_chairs
Example #4
0
    def test_make_chair(self):
        """ Users can be promoted to being activity chairs. """
        # To begin with, our user is not a chair (nobody is, for that matter)
        user = UserFactory.create()
        self.assertFalse(perm_utils.is_chair(user, enums.Activity.CLIMBING))
        self.assertEqual(perm_utils.num_chairs(enums.Activity.CLIMBING), 0)

        # We promote them to be a climbing chair
        perm_utils.make_chair(user, enums.Activity.CLIMBING)
        self.assertTrue(perm_utils.is_chair(user, enums.Activity.CLIMBING))
        self.assertEqual(perm_utils.num_chairs(enums.Activity.CLIMBING), 1)

        # chair_or_admin works now too, and the user is definitely not a superuser
        self.assertTrue(
            perm_utils.chair_or_admin(user, enums.Activity.CLIMBING))
        self.assertFalse(user.is_superuser)

        # Sanity check: The user wasn't accidentally made the chair of other activities
        self.assertFalse(perm_utils.is_chair(user, enums.Activity.BOATING))
Example #5
0
    def test_make_chair(self):
        """ Users can be promoted to being activity chairs. """
        # To begin with, our user is not a chair (nobody is, for that matter)
        climbing = models.BaseRating.CLIMBING
        user = UserFactory.create()
        self.assertFalse(perm_utils.is_chair(user, climbing))
        self.assertEqual(perm_utils.num_chairs(climbing), 0)

        # We promote them to be a climbing chair
        perm_utils.make_chair(user, climbing)
        self.assertTrue(perm_utils.is_chair(user, climbing))
        self.assertEqual(perm_utils.num_chairs(climbing), 1)

        # chair_or_admin works now too, and the user is definitely not a superuser
        self.assertTrue(perm_utils.chair_or_admin(user, climbing))
        self.assertFalse(user.is_superuser)

        # Sanity check: The user wasn't accidentally made the chair of other activities
        self.assertFalse(perm_utils.is_chair(user, models.BaseRating.BOATING))
Example #6
0
    def test_applications_needing_recommendation(self):
        """ Consider applications without a chair recommendation as requiring one! """
        # We have three chairs!
        self.assertEqual(perm_utils.num_chairs(models.BaseRating.CLIMBING), 3)

        # The application is in a pending state, while awaiting recommendation & rating
        alice_manager = self._manager_for(self.alice)
        pending_apps = alice_manager.pending_applications()
        self.assertEqual(pending_apps, [self.application])
        self.assertEqual(alice_manager.needs_rec(pending_apps), [self.application])

        # Once Alice makes a recommendation, it no longer needs a rec from her
        self._make_recommendation(creator=self.alice)
        # Refresh pending applications, as viewed from Alice's perspective
        pending_apps = alice_manager.pending_applications()
        self.assertEqual(alice_manager.needs_rec(pending_apps), [])

        # The application does, however, need recommendations from the other chairs!
        for other_chair in [self.bob, self.charlie]:
            manager = self._manager_for(other_chair)
            # Get pending apps from that chair's perspective!
            pending_apps = manager.pending_applications()
            self.assertEqual(manager.needs_rec(pending_apps), [self.application])
Example #7
0
 def num_chairs(self):
     return perm_utils.num_chairs(self.activity)
Example #8
0
 def test_admin_not_counted_in_list(self):
     """ The admin isn't considered in the count of chairs. """
     self.assertEqual(perm_utils.num_chairs(enums.Activity.CLIMBING), 0)
Example #9
0
 def test_admin_not_counted_in_list(self):
     """ The admin isn't considered in the count of chairs. """
     self.assertEqual(perm_utils.num_chairs(models.BaseRating.CLIMBING), 0)