def test_create_free_days(self): """ Test create_free_days """ FreeDay.objects.all().delete() create_free_days(start_year=2014, number_of_years=2) self.assertEqual(14, FreeDay.objects.count()) self.assertTrue( FreeDay.objects.filter(date__year=2014, date__day=1, date__month=1).exists()) self.assertTrue( FreeDay.objects.filter(date__year=2014, date__day=1, date__month=5).exists()) self.assertTrue( FreeDay.objects.filter(date__year=2014, date__day=1, date__month=6).exists()) self.assertTrue( FreeDay.objects.filter(date__year=2014, date__day=20, date__month=10).exists()) self.assertTrue( FreeDay.objects.filter(date__year=2014, date__day=12, date__month=12).exists()) self.assertTrue( FreeDay.objects.filter(date__year=2014, date__day=25, date__month=12).exists()) self.assertTrue( FreeDay.objects.filter(date__year=2014, date__day=26, date__month=12).exists()) self.assertTrue( FreeDay.objects.filter(date__year=2015, date__day=1, date__month=1).exists()) self.assertTrue( FreeDay.objects.filter(date__year=2015, date__day=1, date__month=5).exists()) self.assertTrue( FreeDay.objects.filter(date__year=2015, date__day=1, date__month=6).exists()) self.assertTrue( FreeDay.objects.filter(date__year=2015, date__day=20, date__month=10).exists()) self.assertTrue( FreeDay.objects.filter(date__year=2015, date__day=12, date__month=12).exists()) self.assertTrue( FreeDay.objects.filter(date__year=2015, date__day=25, date__month=12).exists()) self.assertTrue( FreeDay.objects.filter(date__year=2015, date__day=26, date__month=12).exists())
def test_annualleave_cumulative_leave_taken(self): """Test get_cumulative_leave_taken.""" FreeDay.objects.all().delete() create_free_days(start_year=2017, number_of_years=24) user = mommy.make("auth.User", first_name="Mosh", last_name="Pitt") staff = mommy.make("small_small_hr.StaffProfile", user=user) annual_leave = mommy.make( "small_small_hr.AnnualLeave", staff=staff, year=2017, leave_type=Leave.REGULAR, ) # note that 8/6/2017 is a FreeDay start = datetime(2017, 6, 5, 0, 0, 0, tzinfo=pytz.timezone(settings.TIME_ZONE)) end = datetime(2017, 6, 8, 0, 0, 0, tzinfo=pytz.timezone(settings.TIME_ZONE)) # add some 3 approved leave days mommy.make( "small_small_hr.Leave", staff=staff, start=start, end=end, leave_type=Leave.REGULAR, review_status=Leave.APPROVED, ) # get some rejected and pending leave days mommy.make( "small_small_hr.Leave", staff=staff, start=start, end=end, leave_type=Leave.REGULAR, review_status=Leave.REJECTED, ) mommy.make( "small_small_hr.Leave", staff=staff, start=start, end=end, leave_type=Leave.REGULAR, review_status=Leave.PENDING, ) annual_leave.refresh_from_db() self.assertEqual(3, annual_leave.get_cumulative_leave_taken()) # add some 2 approved leave days that fall between years # 1 day in 2017 and one in 2018 # Dec 30 and Dec 31 are Sat, Sun which are not counted start = datetime(2017, 12, 29, 0, 0, 0, tzinfo=pytz.timezone(settings.TIME_ZONE)) end = datetime(2018, 1, 1, 0, 0, 0, tzinfo=pytz.timezone(settings.TIME_ZONE)) mommy.make( "small_small_hr.Leave", staff=staff, start=start, end=end, leave_type=Leave.REGULAR, review_status=Leave.APPROVED, ) annual_leave.refresh_from_db() # we should have 4 days in 2017 self.assertEqual(4, annual_leave.get_cumulative_leave_taken()) # add 4 days of leave // 6/1/2018 is not counted start = datetime(2018, 1, 2, 0, 0, 0, tzinfo=pytz.timezone(settings.TIME_ZONE)) end = datetime(2018, 1, 6, 0, 0, 0, tzinfo=pytz.timezone(settings.TIME_ZONE)) mommy.make( "small_small_hr.Leave", staff=staff, start=start, end=end, leave_type=Leave.REGULAR, review_status=Leave.APPROVED, ) # we should have 5 days in 2018 annual_leave_2018 = mommy.make( "small_small_hr.AnnualLeave", staff=staff, year=2018, leave_type=Leave.REGULAR, ) self.assertEqual(5, annual_leave_2018.get_cumulative_leave_taken())