def setUp(self):
     rule = Rule(frequency="WEEKLY",
                 end_recurring_period=datetime.datetime(
                     2008, 5, 5, 0, 0, tzinfo=timezone.utc))
     rule.save()
     cal = Calendar(name="MyCal")
     cal.save()
     data = {
         'start': datetime.datetime(2008, 1, 5, 8, 0, tzinfo=timezone.utc),
         'end': datetime.datetime(2008, 1, 5, 9, 0, tzinfo=timezone.utc),
         'rule': rule,
         'calendar': cal
     }
     data2 = {
         'start': datetime.datetime(2008, 1, 5, 8, 0, tzinfo=timezone.utc),
         'end': datetime.datetime(2008, 1, 5, 9, 0, tzinfo=timezone.utc),
         'calendar': cal
     }
     recurring_event = Event(**data)
     recurring_event.save()
     singular_event = Event(**data2)
     singular_event.save()
     self.period = Period(events=Event.objects.source_events(),
                          start=datetime.datetime(2008,
                                                  1,
                                                  4,
                                                  7,
                                                  0,
                                                  tzinfo=timezone.utc),
                          end=datetime.datetime(2008,
                                                1,
                                                21,
                                                7,
                                                0,
                                                tzinfo=timezone.utc))
示例#2
0
    def test_get_for_object(self):
        user = User.objects.create_user('john', '*****@*****.**',
                                        'johnpassword')
        event_relations = list(Event.objects.get_for_object(user, 'owner'))
        self.assertEqual(len(event_relations), 0)

        rule = Rule(frequency="DAILY")
        rule.save()
        cal = Calendar(name='MyCal')
        cal.save()
        event = self.__create_event(
            'event test',
            datetime.datetime(2013, 1, 5, 8, 0, tzinfo=timezone.utc),
            datetime.datetime(2013, 1, 5, 9, 0, tzinfo=timezone.utc), cal)
        event.save()
        events = list(Event.objects.get_for_object(user, 'owner'))
        self.assertEqual(len(events), 0)
        EventRelation.objects.save_relation(event, user, 'owner')

        self.assertEqual(len(list(event.eventrelation_set.all())), 1)

        events = list(Event.objects.get_for_object(user, 'owner'))
        self.assertEqual(len(events), 1)
        self.assertEqual(type(events[0]), TestSubEvent)
        self.assertEqual(event, events[0])
示例#3
0
    def test_recurring_event_get_occurrences_after_with_moved_occ(self):

        cal = Calendar(name="MyCal")
        cal.save()
        rule = Rule(frequency="WEEKLY",
                    end_recurring_period=datetime.datetime(
                        2008, 5, 5, 0, 0, tzinfo=timezone.utc))
        rule.save()
        recurring_event = self.__create_recurring_event(
            datetime.datetime(2008, 1, 1, 2, 0, tzinfo=timezone.utc),
            datetime.datetime(2008, 1, 1, 3, 0, tzinfo=timezone.utc),
            rule,
            cal,
        )

        recurring_event.save()
        occurrence = recurring_event.get_occurrence(
            datetime.datetime(2008, 1, 8, 2, 0, tzinfo=timezone.utc), True)
        occurrence.move(
            datetime.datetime(2008, 1, 15, 2, 0, tzinfo=timezone.utc),
            datetime.datetime(2008, 1, 15, 3, 0, tzinfo=timezone.utc))
        occurrence2 = recurring_event.get_occurrence(
            datetime.datetime(2008, 1, 14, 8, 0, tzinfo=timezone.utc))
        self.assertEqual(occurrence, occurrence2)
        self.assertEqual(
            datetime.datetime(2008, 1, 15, 2, 0, tzinfo=timezone.utc),
            occurrence2.start)
示例#4
0
    def test_recurring_event_get_occurrences(self):

        cal = Calendar(name="MyCal")
        cal.save()
        rule = Rule(frequency="WEEKLY",
                    end_recurring_period=datetime.datetime(
                        2008, 5, 5, 0, 0, tzinfo=timezone.utc))
        rule.save()

        recurring_event = self.__create_recurring_event(
            datetime.datetime(2008, 1, 5, 8, 0, tzinfo=timezone.utc),
            datetime.datetime(2008, 1, 5, 9, 0, tzinfo=timezone.utc),
            rule,
            cal,
        )
        recurring_event.save()

        occurrences = recurring_event.get_occurrences(
            start=datetime.datetime(2008, 1, 12, 0, 0, tzinfo=timezone.utc),
            end=datetime.datetime(2008, 1, 20, 0, 0, tzinfo=timezone.utc))

        self.assertEqual(
            ["%s to %s" % (o.start, o.end) for o in occurrences], [
                '2008-01-12 08:00:00+00:00 to 2008-01-12 09:00:00+00:00',
                '2008-01-19 08:00:00+00:00 to 2008-01-19 09:00:00+00:00'
            ])
示例#5
0
    def test_recurring_event_get_occurrence(self):

        cal = Calendar(name="MyCal")
        cal.save()
        rule = Rule(frequency="WEEKLY",
                    end_recurring_period=datetime.datetime(
                        2008, 5, 5, 0, 0, tzinfo=timezone.utc))
        rule.save()

        event = self.__create_recurring_event(
            datetime.datetime(2008, 1, 5, 8, 0, tzinfo=timezone.utc),
            datetime.datetime(2008, 1, 5, 9, 0, tzinfo=timezone.utc),
            rule,
            cal,
        )
        event.save()

        occurrence = event.get_occurrence(
            datetime.datetime(2008, 1, 5, 8, 0, tzinfo=timezone.utc))
        occurrence.save()
        self.assertEqual(occurrence.start,
                         datetime.datetime(2008, 1, 5, 8, tzinfo=timezone.utc))
        occurrence = event.get_occurrence(
            datetime.datetime(2008, 1, 5, 8, 0, tzinfo=timezone.utc))
        self.assertTrue(occurrence.pk is not None)
 def test_get_calendar_for_object(self):
     calendar = Calendar(name='My Cal')
     calendar.save()
     rule = Rule()
     rule.save()
     calendar.create_relation(rule)
     result = Calendar.objects.get_calendar_for_object(rule)
     self.assertEqual(result.name, 'My Cal')
 def test_get_or_create_calendar_for_object_withouth_name(self):
     """
         Test with already created calendar
     """
     rule = Rule()
     rule.save()
     calendar = Calendar.objects.get_or_create_calendar_for_object(rule)
     calendar_from_rule = Calendar.objects.get_calendars_for_object(rule)[0]
     self.assertEqual(calendar, calendar_from_rule)
 def test_get_or_create_calendar_for_object_without_calendar(self):
     """
         Creation test
     """
     rule = Rule()
     rule.save()
     calendar = Calendar.objects.get_or_create_calendar_for_object(
         rule, name='My Cal')
     self.assertEqual(calendar.name, 'My Cal')
     calendar_from_rule = Calendar.objects.get_calendars_for_object(rule)[0]
     self.assertEqual(calendar, calendar_from_rule)
 def test_get_calendar_for_object_with_more_than_one_calendar(self):
     calendar_1 = Calendar(name='My Cal 1')
     calendar_1.save()
     calendar_2 = Calendar(name='My Cal 2')
     calendar_2.save()
     rule = Rule()
     rule.save()
     calendar_1.create_relation(rule)
     calendar_2.create_relation(rule)
     with self.assertRaises(AssertionError):
         result = Calendar.objects.get_calendar_for_object(rule)
示例#10
0
    def test_occurrence_by_slug(self):
        cal = Calendar(name="MyCal")
        cal.save()
        rule = Rule(frequency="WEEKLY",
                    end_recurring_period=datetime.datetime(
                        2008, 5, 5, 0, 0, tzinfo=timezone.utc))
        rule.save()

        event = self.__create_recurring_event(
            datetime.datetime(2008, 1, 5, 8, 0, tzinfo=timezone.utc),
            datetime.datetime(2008, 1, 5, 9, 0, tzinfo=timezone.utc),
            rule,
            cal,
        )
        event.save()

        occurrence = Event.objects.get(
            slug="%i-%s" %
            (event.pk,
             datetime.datetime(2008, 1, 12, 8, 0, tzinfo=timezone.utc
                               ).strftime('%Y-%m-%d-%H-%M%z')))
        self.assertEqual(
            occurrence.start,
            datetime.datetime(2008, 1, 12, 8, tzinfo=timezone.utc))

        occurrence2 = Event.objects.get(
            slug="%i-%s" %
            (event.pk,
             datetime.datetime(2008, 1, 13, 8, 0, tzinfo=timezone.utc
                               ).strftime('%Y-%m-%d-%H-%M%z')))
        self.assertEqual(
            occurrence2.start,
            datetime.datetime(2008, 1, 19, 8, tzinfo=timezone.utc))

        filtered1 = Event.objects.filter(
            slug="%i-%s" %
            (event.pk,
             datetime.datetime(2008, 1, 12, 8, 0, tzinfo=timezone.utc
                               ).strftime('%Y-%m-%d-%H-%M%z')))
        #can we avoid inifinite recursion?
        filtered1._fetch_all()
        self.assertEqual(
            filtered1[0].start,
            datetime.datetime(2008, 1, 12, 8, tzinfo=timezone.utc))

        filtered2 = Event.objects.filter(
            slug="%i-%s" %
            (event.pk,
             datetime.datetime(2008, 1, 13, 8, 0, tzinfo=timezone.utc
                               ).strftime('%Y-%m-%d-%H-%M%z')))
        self.assertEqual(
            filtered2[0].start,
            datetime.datetime(2008, 1, 19, 8, tzinfo=timezone.utc))
示例#11
0
    def test_occurences_with_recurrent_event_end_recurring_period_edge_case(
            self):

        start = timezone.now() + datetime.timedelta(days=1)
        cal = Calendar(name='MyCal')
        cal.save()
        rule = Rule(frequency="DAILY",
                    end_recurring_period=start + datetime.timedelta(days=10))
        rule.save()
        event = self.__create_recurring_event(
            start, start + datetime.timedelta(hours=1), rule, cal)
        event.save()
        occurrences = list(event.occurrences_after())
        self.assertEqual(len(occurrences), 11)
示例#12
0
 def setUp(self):
     rule = Rule(frequency="WEEKLY",
                 end_recurring_period=datetime.datetime(
                     2008, 5, 5, 0, 0, tzinfo=timezone.utc))
     rule.save()
     cal = Calendar(name="MyCal")
     cal.save()
     data = {
         'start': datetime.datetime(2008, 1, 5, 8, 0, tzinfo=timezone.utc),
         'end': datetime.datetime(2008, 1, 5, 9, 0, tzinfo=timezone.utc),
         'rule': rule,
         'calendar': cal
     }
     self.recurring_event = Event(**data)
     self.recurring_event.save()
示例#13
0
    def test_prevent_TypeError_when_comparing_dates_when_tz_off(self):
        cal = Calendar(name="MyCal")
        cal.save()
        rule = Rule(frequency="WEEKLY",
                    end_recurring_period=datetime.datetime(2008, 5, 5, 0, 0))
        rule.save()

        event = self.__create_recurring_event(
            datetime.datetime(2008, 1, 5, 8, 0),
            datetime.datetime(2008, 1, 5, 9, 0),
            rule,
            cal,
        )
        naive_date = datetime.datetime(2008, 1, 20, 0, 0)
        self.assertIsNone(event.get_occurrence(naive_date, True))
示例#14
0
    def test_recurring_event_slug_value(self):
        cal = Calendar(name="MyCal")
        cal.save()
        rule = Rule(frequency="WEEKLY",
                    end_recurring_period=datetime.datetime(
                        2008, 5, 5, 0, 0, tzinfo=timezone.utc))
        rule.save()

        event = self.__create_recurring_event(
            datetime.datetime(2008, 1, 5, 8, 0, tzinfo=timezone.utc),
            datetime.datetime(2008, 1, 5, 9, 0, tzinfo=timezone.utc),
            rule,
            cal,
        )
        self.assertEqual(event.slug, None)
        event.save()
        self.assertEqual(event.slug, '1-2008-01-05-08-00+0000')
 def test_get_calendars_for_object_without_calendars(self):
     rule = Rule()
     rule.save()
     calendar = Calendar.objects.get_or_create_calendar_for_object(
         rule, name='My Cal', distinction='owner')
     rule = Rule()
     rule.save()
     calendars = list(
         Calendar.objects.get_calendars_for_object(rule,
                                                   distinction='owner'))
     self.assertEqual(len(calendars), 0)
示例#16
0
 def test_occurrence_pool_w_wrong_group(self):
     occ = self.period.events[0].get_occurrences(
         start=datetime.datetime(2008, 1, 4, 7, 0, tzinfo=timezone.utc),
         end=datetime.datetime(2008, 1, 21, 7, 0, tzinfo=timezone.utc))
     occ[0].rule = Rule(frequency="YEARLY")
     occ.append(self.period.events[1].get_occurrence(
         datetime.datetime(2008, 1, 4, 7, 0, tzinfo=timezone.utc)))
     self.period.occurrence_pool = occ
     occurrences = self.period.occurrences
     self.assertEqual(len(occurrences), 3)
示例#17
0
    def test_recurring_event_get_occurrences_after(self):

        cal = Calendar(name="MyCal")
        cal.save()
        rule = Rule(frequency="WEEKLY",
                    end_recurring_period=datetime.datetime(
                        2008, 5, 5, 0, 0, tzinfo=timezone.utc))
        rule.save()
        recurring_event = self.__create_recurring_event(
            datetime.datetime(2008, 1, 5, 8, 0, tzinfo=timezone.utc),
            datetime.datetime(2008, 1, 5, 9, 0, tzinfo=timezone.utc),
            rule,
            cal,
        )

        recurring_event.save()
        occurrences = recurring_event.get_occurrences(
            start=datetime.datetime(2008, 1, 5, tzinfo=timezone.utc),
            end=datetime.datetime(2008, 1, 6, tzinfo=timezone.utc))
        occurrence = occurrences[0]
        occurrence2 = next(
            recurring_event.occurrences_after(
                datetime.datetime(2008, 1, 5, tzinfo=timezone.utc)))
        self.assertEqual(occurrence, occurrence2)
示例#18
0
    def test_recurring_event_get_occurrences_2(self):
        cal = Calendar(name="MyCal")
        cal.save()
        rule = Rule(frequency="WEEKLY",
                    end_recurring_period=datetime.datetime(
                        2013, 5, 5, 0, 0, tzinfo=timezone.utc))
        rule.save()
        rule2 = Rule(frequency="WEEKLY",
                     end_recurring_period=datetime.datetime(
                         2013, 5, 5, 0, 0, tzinfo=timezone.utc))
        rule2.save()

        recurring_partly = self.__create_recurring_event(
            datetime.datetime(2012, 12, 29, 11, 0, tzinfo=timezone.utc),
            datetime.datetime(2012, 12, 29, 13, 0, tzinfo=timezone.utc),
            rule,
            cal,
        )
        recurring_outside = self.__create_recurring_event(
            datetime.datetime(2012, 12, 29, 13, 0, tzinfo=timezone.utc),
            datetime.datetime(2012, 12, 29, 14, 0, tzinfo=timezone.utc),
            rule2,
            cal,
        )

        recurring_outside.save()
        recurring_partly.save()

        test_window = [
            datetime.datetime(2013, 1, 5, 9, 0, tzinfo=timezone.utc),
            datetime.datetime(2013, 1, 5, 12, 0, tzinfo=timezone.utc)
        ]

        recurrences_partly = recurring_partly.get_occurrences(*test_window)
        self.assertEqual(1, len(recurrences_partly))

        recurrences_outside = recurring_outside.get_occurrences(*test_window)
        self.assertEqual(0, len(recurrences_outside))
 def test_get_calendar_for_object_without_calendars(self):
     with self.assertRaises(Calendar.DoesNotExist):
         rule = Rule()
         rule.save()
         Calendar.objects.get_calendar_for_object(rule)
示例#20
0
 def test_get_params(self):
     rule = Rule(params="count:1;bysecond:1;byminute:1,2,4,5")
     expected = {'count': 1, 'byminute': [1, 2, 4, 5], 'bysecond': 1}
     self.assertEqual(rule.get_params(), expected)