Пример #1
0
    def test_calculate_flextime_multiple_months(self):
        month_archive = archive.Archive()
        month_1 = month.Month("2014-09")
        next_day = month_1.next_workday()
        while next_day.startswith("2014-09-"):
            month_1.add_day(next_day).report("8:00", "1:00", "17:05")
            next_day = month_1.next_workday()

        month_2 = month.Month("2014-10")
        next_day = month_2.next_workday()
        while next_day.startswith("2014-10-"):
            month_2.add_day(next_day).report("8:10", "1:00", "17:00")
            next_day = month_2.next_workday()

        month_3 = month.Month("2014-11")
        next_day = month_3.next_workday()
        while next_day.startswith("2014-11-"):
            month_3.add_day(next_day).report("8:00", "0:30", "17:00")
            next_day = month_3.next_workday()

        month_archive.archive_month(month_1)
        expected_flex = len(month_1.days) * datetime.timedelta(minutes=5)
        nt.assert_equal(month_archive.calculate_flextime(), expected_flex)

        month_archive.archive_month(month_2)
        expected_flex += len(month_2.days) * datetime.timedelta(minutes=-10)
        nt.assert_equal(month_archive.calculate_flextime(), expected_flex)

        month_archive.archive_month(month_3)
        expected_flex += len(month_3.days) * datetime.timedelta(minutes=30)
        nt.assert_equal(month_archive.calculate_flextime(), expected_flex)
Пример #2
0
    def test_next_month(self):
        month_archive = archive.Archive()
        nt.assert_equal(month_archive.next_month(), "")
        month_1 = month.Month("2013-11")
        next_day = month_1.next_workday()
        while next_day.startswith("2013-11-"):
            month_1.add_day(next_day).report("8:00", "1:00", "17:00")
            next_day = month_1.next_workday()
        month_archive.archive_month(month_1)
        nt.assert_true(month_archive.next_month(), "2013-12")

        month_2 = month.Month("2013-12")
        next_day = month_2.next_workday()
        while next_day.startswith("2013-12-"):
            month_2.add_day(next_day).report("8:00", "1:00", "17:00")
            next_day = month_2.next_workday()
        month_archive.archive_month(month_2)
        nt.assert_true(month_archive.next_month(), "2014-01")
Пример #3
0
    def test_archive_nonsequential(self):
        month_archive = archive.Archive()
        month_1 = month.Month("2014-09")
        next_day = month_1.next_workday()
        while next_day.startswith("2014-09-"):
            month_1.add_day(next_day).report("8:00", "1:00", "17:00")
            next_day = month_1.next_workday()

        month_2 = month.Month("2014-11")
        next_day = month_2.next_workday()
        while next_day.startswith("2014-11-"):
            month_2.add_day(next_day).report("8:00", "1:00", "17:00")
            next_day = month_2.next_workday()

        month_archive.archive_month(month_1)
        nt.assert_raises_regexp(
            errors.ReportError, "^Months must be archived sequentially. "
            "Expected 2014-10, got 2014-11.$", month_archive.archive_month,
            month_2)
Пример #4
0
 def test_archive_same_month_twice(self):
     month_archive = archive.Archive()
     month_1 = month.Month("2014-09")
     next_day = month_1.next_workday()
     while next_day.startswith("2014-09-"):
         month_1.add_day(next_day).report("8:00", "1:00", "17:00")
         next_day = month_1.next_workday()
     month_archive.archive_month(month_1)
     nt.assert_raises_regexp(
         errors.ReportError, "^Month {}-{} is allready archived.$".format(
             month_1.year, month_1.month), month_archive.archive_month,
         month_1)
Пример #5
0
    def test_calculate_flextime_one_month(self):
        month_archive = archive.Archive()
        nt.assert_equal(month_archive.calculate_flextime(),
                        datetime.timedelta())

        month_1 = month.Month("2014-09")
        next_day = month_1.next_workday()
        while next_day.startswith("2014-09-"):
            month_1.add_day(next_day).report("8:00", "1:00", "17:01")
            next_day = month_1.next_workday()
        expected_flex = len(month_1.days) * datetime.timedelta(minutes=1)
        month_archive.archive_month(month_1)
        nt.assert_equal(month_archive.calculate_flextime(), expected_flex)
Пример #6
0
    def test_archive_month(self):
        month_archive = archive.Archive()
        month_1 = month.Month("2014-09")
        nt.assert_raises_regexp(
            errors.ReportError, "^Month still has unreported workdays and "
            "can't be archived.$", month_archive.archive_month, month_1)

        next_day = month_1.next_workday()
        while next_day.startswith("2014-09-"):
            month_1.add_day(next_day).report("8:00", "1:00", "17:00")
            next_day = month_1.next_workday()
        month_archive.archive_month(month_1)
        nt.assert_true(month_1 in month_archive.months)
Пример #7
0
 def next_workday(self) -> str:
     if len(self.months) == 0:
         if self.force_start_date is None:
             tmp_month_string = "{}-01".format(self.year)
         else:
             tmp_month_string = self.force_start_date[:7]
         tmp_month = month.Month(tmp_month_string)
         month_holidays = self.holidays[tmp_month_string].items()
         for date_string, holiday in month_holidays:
             tmp_month.add_holiday(date_string, holiday)
         next_workday = tmp_month.next_workday()
     else:
         next_workday = self.months[-1].next_workday()
     return next_workday
Пример #8
0
    def add_day(self, date_string: str) -> day.Day:
        new_day = day.Day(date_string)
        if new_day.date.year != self.year:
            raise errors.ReportError(
                "New date string didn't match year. {} doesn't include {}.".
                format(self.year, date_string))

        if self.next_workday()[:7] == self.next_month():
            new_month = month.Month(self.next_month())
            for date, name in self.holidays[self.next_month()].items():
                new_month.add_holiday(date, name)
            self.months.append(new_month)
        day_1 = self.months[-1].add_day(date_string)
        return day_1
Пример #9
0
    def test_used_vacation(self):
        month_archive = archive.Archive()
        month_1 = month.Month("2014-09")
        day_1 = month_1.add_day(month_1.next_workday())
        day_1.day_type = DayType.vacation
        next_day = month_1.next_workday()
        while next_day.startswith("2014-09-"):
            month_1.add_day(next_day).report("8:00", "1:00", "17:05")
            next_day = month_1.next_workday()
        month_archive.archive_month(month_1)

        month_2 = month.Month("2014-10")
        day_2 = month_2.add_day(month_2.next_workday())
        day_2.day_type = DayType.vacation
        day_3 = month_2.add_day(month_2.next_workday())
        day_3.day_type = DayType.vacation
        next_day = month_2.next_workday()
        while next_day.startswith("2014-10-"):
            month_2.add_day(next_day).report("8:10", "1:00", "17:00")
            next_day = month_2.next_workday()
        month_archive.archive_month(month_2)

        nt.assert_equal(month_archive.used_vacation(), 3)