예제 #1
0
    def test_add_day_wrong(self):
        year_1 = year.Year("2014")
        nt.assert_raises_regexp(
            errors.ReportError,
            "^New date string didn't match year. 2014 doesn't include "
            "2015-01-01.$", year_1.add_day, "2015-01-01")

        year_1 = year.Year("2015")
        nt.assert_raises_regexp(
            errors.ReportError,
            "^New date string didn't match year. 2015 doesn't include "
            "2014-01-01.$", year_1.add_day, "2014-01-01")
예제 #2
0
 def test_report_full_year(self):
     year_1 = year.Year("2014")
     while year_1.next_workday() != "2015-01-01":
         day_1 = year_1.add_day(year_1.next_workday())
         day_1.report("8:00", "1:00", "17:00")
     nt.assert_equal(len(year_1.months), 12)
     nt.assert_true(year_1.complete())
예제 #3
0
 def test_add_another_year_with_forced_start_date(self):
     year_1 = year.Year("2013", start_date="2013-09-01")
     nt.assert_equal(year_1.next_workday(), "2013-09-02")
     nt.assert_false(year_1.complete())
     while year_1.next_workday() != "2014-01-01":
         day_1 = year_1.add_day(year_1.next_workday())
         day_1.report("8:00", "1:00", "17:00")
     nt.assert_true(year_1.complete())
     nt.assert_equal(len(year_1.months), 4)
예제 #4
0
 def test_add_year_with_holidays(self):
     year_1 = year.Year("2014")
     nt.assert_equal(year_1.next_workday(), "2014-01-01")
     year_1.add_holiday("2014-01-01", "New years day")
     nt.assert_equal(year_1.next_workday(), "2014-01-02")
     year_1.add_day("2014-01-02").report("8:00", "1:00", "17:00")
     nt.assert_equal(year_1.calculate_flextime(), datetime.timedelta())
     year_1.add_holiday("2014-01-02", "Ancestry day")
     nt.assert_equal(year_1.calculate_flextime(),
                     datetime.timedelta(hours=8))
예제 #5
0
    def test_calculate_flextime_with_incomming_flex(self):
        year_1 = year.Year("2014",
                           flextime=datetime.timedelta(hours=3, minutes=14))

        nt.assert_equal(year_1.calculate_flextime(),
                        datetime.timedelta(hours=3, minutes=14))

        year_1.add_day("2014-01-01").report("10:00", "1:29", "16:00")
        nt.assert_equal(year_1.calculate_flextime(),
                        datetime.timedelta(minutes=-15))
예제 #6
0
 def test_add_another_empty_year(self):
     year_1 = year.Year("2015")
     nt.assert_equal(year_1.year, 2015)
     nt.assert_equal(year_1.months, [])
     nt.assert_false(year_1.complete())
     nt.assert_equal(year_1.next_workday(), "2015-01-01")
     nt.assert_equal(year_1.next_month(), "2015-01")
     nt.assert_equal(year_1.next_year(), "2016")
     nt.assert_equal(year_1.calculate_flextime(), datetime.timedelta())
     nt.assert_equal(year_1.used_vacation(), 0)
     nt.assert_equal(year_1.sick_days(), 0)
예제 #7
0
 def add_day(self, date_string: str) -> Day:
     """Add a day.
     :type date_string string:  The new date
     :rtype: Day
     """
     if self.next_workday()[:4] == self.next_year():
         new_year = year.Year(self.next_year())
         for date, name in self.holidays.items():
             new_year.add_holiday(date, name)
         self.years.append(new_year)
     new_day = self.current_year().add_day(date_string)
     return new_day
예제 #8
0
    def test_report_day_to_year(self):
        year_1 = year.Year("2013")
        day_1 = year_1.add_day("2013-01-01")
        nt.assert_equal(day_1.date,
                        datetime.datetime(year=2013, month=1, day=1).date())

        nt.assert_equal(len(year_1.months), 1)
        nt.assert_equal(year_1.months[0].year, 2013)
        nt.assert_equal(year_1.months[0].month, 1)
        nt.assert_equal(len(year_1.months[0].days), 1)
        nt.assert_equal(year_1.months[0].days[0], day_1)

        nt.assert_equal(year_1.next_workday(), "2013-01-02")
        nt.assert_equal(year_1.next_month(), "2013-02")
예제 #9
0
    def test_add_year(self):
        user_1 = user.User(employed_date="2014-09-01")
        year_1 = year.Year("2014")
        user_1.add_year(year_1)
        nt.assert_equal(len(user_1.years), 1)
        nt.assert_true(user_1.years[0], year_1)
        year_2 = year.Year("2015")
        nt.assert_raises_regexp(
            errors.YearError,
            "Previous year \(2014\) must be completed first.", user_1.add_year,
            year_2)

        user_2 = user.User(employed_date="2014-09-01")
        year_3 = year.Year("2014")
        year_3.add_day("2014-01-01")
        nt.assert_raises_regexp(errors.YearError,
                                "Added year can't contain any reported days.",
                                user_2.add_year, year_3)

        user_3 = user.User(employed_date="2014-09-01")
        user_3.years[0].add_holiday("2014-01-01", "New Years Day")
        nt.assert_raises_regexp(errors.YearError,
                                "Added year can't contain any reported days.",
                                user_2.add_year, year_3)
예제 #10
0
    def __init__(self,
                 name: str = "",
                 employed_date: Optional[str] = None,
                 employment: int = 100,
                 payed_vacation: int = 0,
                 vacation_month: int = 1,
                 extra_vacation: int = 0):
        self.name = name
        self.years = []
        if employed_date is not None:
            self.employed_date = datetime.strptime(employed_date,
                                                   "%Y-%m-%d").date()

            self.years.append(
                year.Year(str(self.employed_date.year),
                          start_date=self.employed_date.isoformat()))
        else:
            self.employed_date = None
        self.employment = employment
        self.flextime = timedelta()
        self.payed_vacation = payed_vacation
        self.vacation_month = vacation_month
        self.extra_vacation = extra_vacation
        self.holidays = {}
예제 #11
0
 def test_used_vacation(self):
     year_1 = year.Year("2013")
     nt.assert_equal(year_1.used_vacation(), 0)
     year_1.add_day("2013-01-01").day_type = DayType.vacation
     nt.assert_equal(year_1.used_vacation(), 1)
예제 #12
0
 def test_sick_days(self):
     year_1 = year.Year("2013")
     nt.assert_equal(year_1.sick_days(), 0)
     year_1.add_day("2013-01-01").day_type = DayType.sick_day
     nt.assert_equal(year_1.sick_days(), 1)
예제 #13
0
 def test_calculate_flextime(self):
     year_1 = year.Year("2013")
     nt.assert_equal(year_1.calculate_flextime(), datetime.timedelta())
     year_1.add_day("2013-01-01").report("8:00", "0:30", "17:00")
     nt.assert_equal(year_1.calculate_flextime(),
                     datetime.timedelta(minutes=30))
예제 #14
0
 def test_report_full_month(self):
     year_1 = year.Year("2014")
     while year_1.next_workday()[:7] == "2014-01":
         day_1 = year_1.add_day(year_1.next_workday())
         day_1.report("8:00", "1:00", "17:00")
     nt.assert_true(year_1.months[0].complete())