예제 #1
0
    def test_is_holiday(self):
        self.assertEqual(
            Holiday.is_holiday(datetime.date(year=2017, month=3, day=16)),
            [self.easter_2017.to_json()])

        self.assertFalse(Holiday.is_holiday(datetime.date(year=2017, month=3, day=15)))
        self.assertFalse(Holiday.is_holiday(datetime.date(year=2017, month=3, day=17)))
예제 #2
0
    def save(self, *args, **kwargs):
        user_profile = UserProfile.objects.get(user=self.created_by)
        super(RecurringTicket, self).save(*args, **kwargs)
        today = datetime.date.today()
        if self.form_id is None:
            self.form_id = self.get_unique_id(time=self.created_at,
                business=user_profile.business.short_name)
            self.save()

        no_current_tickets = not(bool(self.generalticket_set.filter(
            status__terminal=False).count()))

        if ((self.repeat_type == self.DAILY) and
            no_current_tickets and
            (today.weekday()<=4) and
            (not Holiday.is_holiday(today))):

            self.create_general_ticket()

        elif ((self.repeat_type == self.WEEKLY) and 
            no_current_tickets and
            (today.weekday() in self.get_weekdays) and
            (not Holiday.is_holiday(today))):

            self.create_general_ticket()

        elif ((self.repeat_type == self.MONTHLY) and
            no_current_tickets and
            (today.day in self.get_month_days) and
            (not Holiday.is_holiday(today))):

            self.create_general_ticket()

        elif ((self.repeat_type == self.NTH_WEEKDAY) and
            no_current_tickets and
            (today.weekday() in self.get_weekdays) and
            (not Holiday.is_holiday(today))):

            # do a second check to make sure Ordinal matches
            count = 0
            d = today.replace(day=1)
            while d <= today:
                if d.weekday() in self.get_weekdays:
                    count += 1
            if count == self.ordinal:
                self.create_general_ticket()

        elif ((self.repeat_type == self.YEARLY) and
            no_current_tickets and
            (today == self.start_date)):

            self.create_general_ticket()

        else:
            # determine when the next ticket should be created and save that date
            self.next_task_created = self.get_next_day()
            if self.next_task_created < datetime.date.today():
                self.create_general_task()
            super(RecurringTicket, self).save(*args, **kwargs)
예제 #3
0
    def test_is_holiday(self):
        self.assertEqual(
            Holiday.is_holiday(datetime.date(year=2017, month=1, day=1)),
            [self.new_years.to_json(2017)])

        self.assertFalse(
            Holiday.is_holiday(datetime.date(year=2017, month=1, day=2)))
        self.assertFalse(
            Holiday.is_holiday(datetime.date(year=2017, month=12, day=23)))
예제 #4
0
    def test_is_holiday(self):
        self.assertEqual(
            Holiday.is_holiday(datetime.date(year=2016, month=11, day=8)),
            [self.electionday.to_json(2016)])
        self.assertEqual(
            Holiday.is_holiday(datetime.date(year=2017, month=11, day=7)),
            [self.electionday.to_json(2017)])
        self.assertEqual(
            Holiday.is_holiday(datetime.date(year=2018, month=11, day=6)),
            [self.electionday.to_json(2018)])

        self.assertFalse(Holiday.is_holiday(datetime.date(year=2016, month=11, day=7)))
        self.assertFalse(Holiday.is_holiday(datetime.date(year=2017, month=11, day=6)))
        self.assertFalse(Holiday.is_holiday(datetime.date(year=2018, month=11, day=7)))
예제 #5
0
    def test_is_holiday(self):
        self.assertEqual(
            Holiday.is_holiday(datetime.date(year=2016, month=11, day=24)),
            [self.thanksgiving.to_json(2016)])
        self.assertEqual(
            Holiday.is_holiday(datetime.date(year=2017, month=11, day=23)),
            [self.thanksgiving.to_json(2017)])
        self.assertEqual(
            Holiday.is_holiday(datetime.date(year=2018, month=11, day=22)),
            [self.thanksgiving.to_json(2018)])

        self.assertFalse(Holiday.is_holiday(datetime.date(year=2016, month=11, day=23)))
        self.assertFalse(Holiday.is_holiday(datetime.date(year=2017, month=11, day=24)))
        self.assertFalse(Holiday.is_holiday(datetime.date(year=2018, month=11, day=23)))