def test_volunteers(self): # and test it through volunteers as well self.assertEqual( len( helpers.filter_vacant( Volunteer.objects, "holiday__since", "holiday__until", date(year=2015, month=8, day=20), date(year=2015, month=8, day=30), ) ), 1, ) self.assertEqual( len( helpers.filter_vacant( Volunteer.objects, "holiday__since", "holiday__until", date(year=2015, month=3, day=1), date(year=2015, month=3, day=30), ) ), 0, )
def test_vacancy_basic(self): self.assertEqual( len( helpers.filter_vacant( Holiday.objects, "since", "until", date(year=2015, month=7, day=1), date(year=2015, month=7, day=30) ) ), 6, ) self.assertEqual( len( helpers.filter_vacant( Holiday.objects, "since", "until", date(year=2015, month=7, day=1), date(year=2015, month=7, day=14) ) ), 5, ) self.assertEqual( len( helpers.filter_vacant( Holiday.objects, "since", "until", date(year=2015, month=7, day=5), date(year=2015, month=7, day=5) ) ), 4, ) self.assertEqual( len( helpers.filter_vacant( Holiday.objects, "since", "until", date(year=2015, month=7, day=26), date(year=2015, month=7, day=30), ) ), 1, ) self.assertEqual( len( helpers.filter_vacant( Holiday.objects, "since", "until", date(year=2015, month=3, day=1), date(year=2015, month=3, day=30) ) ), 0, )
def filter_vacant_only(cls, start, end): return h.filter_vacant( cls.objects, 'since', 'until', start, end )
def queryset(self, request, queryset): if self.value() == 'true': return h.filter_vacant( queryset, 'holiday__since', 'holiday__until', now(), now(), ) elif self.value() == 'false': return h.filter_vacant( queryset, 'holiday__since', 'holiday__until', now(), now(), inverted = True, )
def notOnHoliday(self, when = now()): query = h.filter_vacant( Holiday.objects.filter(volunteer = self), 'since', 'until', when, when, ) if query.count() > 0: return False return True
def test_vacancy_uncertain_ending(self): # two for uncertain end # one which partly cover the starting day self.assertEqual( len( helpers.filter_vacant( Holiday.objects, "since", "until", date(year=2015, month=8, day=10), date(year=2015, month=8, day=20), ) ), 1, ) # one search inside of the uncertain vaccancy self.assertEqual( len( helpers.filter_vacant( Holiday.objects, "since", "until", date(year=2015, month=8, day=20), date(year=2015, month=8, day=30), ) ), 1, ) self.assertEqual( len( helpers.filter_vacant( Holiday.objects, "since", "until", date(year=2015, month=8, day=20), date(year=2015, month=8, day=20), ) ), 1, )
def test_volunteers_inverted(self): # check for cases between two entries for a volunteer self.assertEqual( len( helpers.filter_vacant( Volunteer.objects, "holiday__since", "holiday__until", date(year=2015, month=7, day=10), date(year=2015, month=7, day=10), inverted=True, ) ), 8, ) # a volunteer with multiple entries, we are in middle of one self.assertEqual( len( helpers.filter_vacant( Volunteer.objects, "holiday__since", "holiday__until", date(year=2015, month=7, day=15), date(year=2015, month=7, day=15), inverted=True, ) ), 7, ) # check if we can filter out volunteers WITHOUT a vacancy at a moment self.assertEqual( len( helpers.filter_vacant( Volunteer.objects, "holiday__since", "holiday__until", date(year=2015, month=3, day=1), date(year=2015, month=3, day=30), inverted=True, ) ), 10, ) self.assertEqual( len( helpers.filter_vacant( Volunteer.objects, "holiday__since", "holiday__until", date(year=2015, month=3, day=1), date(year=2015, month=3, day=1), inverted=True, ) ), 10, ) # everyone except the uncertain end should be available self.assertEqual( len( helpers.filter_vacant( Volunteer.objects, "holiday__since", "holiday__until", date(year=2015, month=8, day=20), date(year=2015, month=8, day=20), inverted=True, ) ), 9, )