def test_manual_next(self, save): """The manual ordering is applied when the signup is on a trip.""" signup = models.SignUp(on_trip=True) signup_utils.next_in_order(signup, 3) save.assert_called_once() self.assertEqual(signup.manual_order, 3)
def test_leader_disagreement(self): """ If only one leader reports them as flaking, that's a flake. """ subject = { 'participant': self.participant, 'trip': self.three_trips[0] } models.SignUp(on_trip=True, **subject).save() # One leader says the participant didn't show FeedbackFactory.create(showed_up=False, comments="No show", **subject) self.assertEqual( self.ranker.number_ws_trips(self.participant), rank.TripCounts(attended=0, flaked=1, total=1), ) self.assertEqual(5, self.ranker.flake_factor(self.participant)) # Co-leaders didn't note person a flake (most likely, didn't know how) FeedbackFactory.create(showed_up=True, **subject) FeedbackFactory.create(showed_up=True, **subject) # However, we still consider them to have flaked on the first trip self.assertEqual( self.ranker.number_ws_trips(self.participant), rank.TripCounts(attended=0, flaked=1, total=1), ) self.assertEqual(5, self.ranker.flake_factor(self.participant))
def test_no_waitlist_entry(self, save): """When neither on the trip, nor the waitlist, nothing happens.""" signup = models.SignUp() # No corresponding waitlist entry for manual_order in [None, 3, 5]: signup_utils.next_in_order(signup, manual_order) save.assert_not_called() self.assertIsNone(signup.manual_order)
def test_wl_last_of_priority(self, wl_save, last_of_priority): """If no manual order is passed, `last_in_priority` is used.""" last_of_priority.return_value = 37 wl_signup = models.WaitListSignup(waitlist=models.WaitList()) signup = models.SignUp(waitlistsignup=wl_signup) signup_utils.next_in_order(signup, None) wl_save.assert_called_once() self.assertEqual(wl_signup.manual_order, 37)
def test_wl_invert_manual_order(self, wl_save): """Manual orderings are negative when updating waitlist entries. (nulls come after integers when reverse sorted, so anyone with a manual ordering integer will be first) """ signup = models.SignUp(waitlistsignup=models.WaitListSignup()) signup_utils.next_in_order(signup, 4) wl_save.assert_called_once() self.assertEqual(signup.waitlistsignup.manual_order, -4) # Negated!
def to_objects(self, signups): """ Convert POSTed JSON to an array of its corresponding objects. """ for signup_dict in signups: remove = bool(signup_dict.get('deleted')) if signup_dict['id']: signup = models.SignUp.objects.get(pk=signup_dict['id']) elif remove: continue # No point creating signup, only to remove later else: par_id = signup['participant']['id'] par = models.Participant.objects.get(pk=par_id) signup = models.SignUp(participant=par, trip=self.object) yield signup, remove
def test_last_of_priority(self, last_of_priority): """The signup is placed in last priority if already on trip. This makes the signup "priority," but below others. That is, leader-ordered signups should go above other signups. (Let's say that a leader is organizing signups, but new signups come in before they submit the ordering - we want to be sure all their ordering goes above any new signups). """ last_of_priority.return_value = 5 trip = models.Trip() with patch.object(models.SignUp, 'save') as save: signup = models.SignUp(trip=trip, on_trip=True) signup_utils.next_in_order(signup, None) save.assert_called_once() self.assertEqual(signup.manual_order, 5)