def setUpTestData(cls): """ Create some trips to relate to the participant test object. (We do not start with the participant actually signed up/on the trip). """ cls.last_season_trips = [ TripFactory.create(activity='winter_school', trip_date=date(2017, 1, 15)), TripFactory.create(activity='winter_school', trip_date=date(2017, 1, 22)), ] cls.three_trips = [ TripFactory.create(activity='winter_school', trip_date=date(2018, 1, 13)), TripFactory.create(activity='winter_school', trip_date=date(2018, 1, 14)), TripFactory.create(activity='winter_school', trip_date=date(2018, 1, 20)), ] cls.all_trips = cls.last_season_trips + cls.three_trips
def test_leader_on_trip_creator(self): trip = TripFactory() self.assertTrue( perm_utils.leader_on_trip(trip.creator, trip, creator_allowed=True)) self.assertFalse( perm_utils.leader_on_trip(trip.creator, trip, creator_allowed=False))
def test_mini_trips_not_covered(self): """ Membership never needs to be renewed for 'mini trips' """ mini_trip = TripFactory.build( trip_date=date(2019, 11, 13), membership_required=False ) for membership_expires in [ date(2019, 10, 12), # week before current date (currently expired!) date(2019, 11, 12), # day before trip date(2019, 11, 13), # day of trip date(2019, 11, 14), # day after trip ]: self.assertFalse(self._should_renew_for(mini_trip, membership_expires))
def setUpTestData(cls): """ Create some trips to relate to the participant test object. (We do not start with the participant actually signed up/on the trip). """ cls.last_season_trips = [ TripFactory.create(activity='winter_school', trip_date=date(2017, 1, 15)), TripFactory.create(activity='winter_school', trip_date=date(2017, 1, 22)) ] cls.three_trips = [ TripFactory.create(activity='winter_school', trip_date=date(2018, 1, 13)), TripFactory.create(activity='winter_school', trip_date=date(2018, 1, 14)), TripFactory.create(activity='winter_school', trip_date=date(2018, 1, 20)) ] cls.all_trips = cls.last_season_trips + cls.three_trips
def test_normal_renewal(self): """ In normal cases (upcoming trip, membership required) we require renewal. """ # Trip takes place within the 40 day window (39 days) future_trip = TripFactory.build( trip_date=date(2019, 11, 27), membership_required=True ) # Participants with no membership should renew self.assertTrue(self._should_renew_for(future_trip, None)) # Participants with a membership expiring before the trip should renew self.assertTrue(self._should_renew_for(future_trip, date(2019, 11, 18))) # Participants with a membership expiring after the trip are cleared! self.assertFalse(self._should_renew_for(future_trip, date(2019, 11, 28))) self.assertFalse(self._should_renew_for(future_trip, date(2020, 10, 18)))
def test_deterministic_ranking(self): """ Ranking of a particular single trip is based on its pk. """ trip = TripFactory.create(activity='hiking', pk=822) # TODO: This test relies pretty heavily on the database and is very slow participants = [] for i in range(5): par = ParticipantFactory.create(name=f"Participant Num{i}") SignUpFactory.create(participant=par, trip=trip) participants.append(par) self.assertEqual( list(rank.SingleTripParticipantRanker(trip)), list(rank.SingleTripParticipantRanker(trip)), )
def test_trip_more_than_forty_days_out(self): """ For trips more than 40 days out, we don't ask people to renew. NOTE: This test will fail if the constant RENEWAL_ALLOWED_WITH_DAYS_LEFT changes to be something larger than 40. That's desired, though - we'd like to know if that changes, so we can actively opt in to the changes. """ # trip taking place 41 days in the future! future_trip = TripFactory.build( trip_date=date(2019, 11, 29), membership_required=True ) # Even if they currently have no membership, we don't consider it requiring renewal # (If a trip is announced over a year in advance, requiring 'renewal' # would prevent _any_ members from signing up) self.assertFalse(self._should_renew_for(future_trip, None)) # Membership will expire before the trip, but we don't request renewal self.assertFalse(self._should_renew_for(future_trip, date(2019, 11, 28)))
def test_leader_on_trip(self): trip = TripFactory() self.assertFalse(perm_utils.leader_on_trip(trip.creator, trip)) trip.leaders.add(trip.creator) self.assertTrue(perm_utils.leader_on_trip(trip.creator, trip))
def test_viewing_trips(self): """ Anonymous users can view trips (they just can't sign up). """ # Note: This test requires fixtures or other test data trip = TripFactory.create() view_trip = self.client.get(reverse('view_trip', kwargs={'pk': trip.pk})) self.assertEqual(view_trip.status_code, 200)
def create_ws_trip(trip_date): return TripFactory.create( program=enums.Program.WINTER_SCHOOL.value, trip_date=trip_date)