Example #1
0
    def testWorkalendar(self):
        class Woral:
            get_holiday_label = Mock(return_value="JOY JOY")

        woral = Woral()
        hols = Holidays()
        hols.register(woral)
        self.assertEqual(hols.srcs, [{}, woral])
        self.assertEqual(hols.get(dt.date(1999, 4, 30)), "JOY JOY")
        woral.get_holiday_label.assert_called_with(dt.date(1999, 4, 30))
Example #2
0
class GirotondoMonth:
    def __init__(self, year: int = None, month: int = None):
        if month is None:
            month = date.today().month
        self.month = month
        if year is None:
            year = date.today().year
        self.year = year
        self.next_month = self.month + 1
        self.next_month_year = self.year
        if self.next_month > 12:
            self.next_month_year = self.year + 1
            self.next_month = 1
        self.event_queryset = SimpleEventPage.objects.filter(
            date__gte=date(self.year, self.month, 1),
            date__lt=date(self.next_month_year, self.next_month, 1))

        # .union(MultidayEventPage.objects.filter(
        #    date_to__gte=date(self.year, self.month, 1),
        #    date_from__lt=date(self.next_month_year, self.next_month, 1))).order_by('owner_id')
        self.absences = Child.get_assignments_by_month(self.month, self.year)
        self.children = Child.get_children_per_care_group()
        self.holidays = Holidays()

    def is_girotondo_day(self, day: int) -> bool:
        test_date = date(self.year, self.month, day)
        if test_date.weekday() > 4:  # 5 = saturday, 6 = sunday
            return False
        if len(self.holidays.get(test_date)) > 0:
            return False
        for event in self.event_queryset:
            if event.date != test_date:
                continue
            if event.category is not None and event.category.name in (
                    'closed', 'Closed'):
                return False
        return True

    def get_children_in(self, day: int, group: str) -> List[str]:
        children_in = []
        if not self.is_girotondo_day(day):
            return []
        for child in self.children[group]:
            if child not in self.absences[day - 1][group]:
                children_in.append(child.first_name + ' ' + child.last_name)
        return children_in

    def get_children_out(self, day: int, group: str) -> List[str]:
        return [
            x.first_name + ' ' + x.last_name
            for x in self.absences[day - 1][group]
        ]
Example #3
0
 def testMultiHolidays(self):
     hols = Holidays()
     hols.add(dt.date(1999, 1, 1), "Gliffy")
     hols.add(dt.date(1999, 1, 1), "Whatnot")
     self.assertEqual(hols.get(dt.date(1999, 1, 1)),
                      "Gliffy, Whatnot, New Year's Day")
Example #4
0
 def testSimple(self):
     hols = Holidays()
     hols.add(dt.date(1999, 4, 29), "HAPPY HAPPY")
     self.assertEqual(hols.get(dt.date(1999, 4, 29)), "HAPPY HAPPY")
Example #5
0
 def testNZSetting(self):
     hols = Holidays()
     self.assertEqual(hols.get(dt.date(1999, 4, 25)), "Anzac Day")
Example #6
0
 def testNoSettings(self):
     del settings.JOYOUS_HOLIDAYS
     hols = Holidays()
     self.assertEqual(hols.simple, {})
     self.assertEqual(hols.srcs, [{}])
     self.assertEqual(hols.get(dt.date(1999, 4, 25)), "")