Ejemplo n.º 1
0
 def setUp(self):
     rule = Rule(frequency="WEEKLY")
     rule.save()
     cal = Calendar(name="MyCal")
     cal.save()
     self.recurring_data = {
         'title':
         'Recent Event',
         'start':
         datetime.datetime(2008, 1, 5, 8, 0, tzinfo=pytz.utc),
         'end':
         datetime.datetime(2008, 1, 5, 9, 0, tzinfo=pytz.utc),
         'end_recurring_period':
         datetime.datetime(2008, 5, 5, 0, 0, tzinfo=pytz.utc),
         'rule':
         rule,
         'calendar':
         cal
     }
     self.data = {
         'title':
         'Recent Event',
         'start':
         datetime.datetime(2008, 1, 5, 8, 0, tzinfo=pytz.utc),
         'end':
         datetime.datetime(2008, 1, 5, 9, 0, tzinfo=pytz.utc),
         'end_recurring_period':
         datetime.datetime(2008, 5, 5, 0, 0, tzinfo=pytz.utc),
         'calendar':
         cal
     }
     self.recurring_event = Event.objects.create(**self.recurring_data)
     self.start = datetime.datetime(2008, 1, 12, 0, 0, tzinfo=pytz.utc)
     self.end = datetime.datetime(2008, 1, 27, 0, 0, tzinfo=pytz.utc)
Ejemplo n.º 2
0
    def test_recurring_event_with_moved_get_occurrences_after(self):

        cal = Calendar(name="MyCal")
        cal.save()
        rule = Rule(frequency="WEEKLY")
        rule.save()
        recurring_event = self.__create_recurring_event(
            'Recurrent event test get_occurrence',
            datetime.datetime(2008, 1, 5, 8, 0, tzinfo=pytz.utc),
            datetime.datetime(2008, 1, 5, 9, 0, tzinfo=pytz.utc),
            datetime.datetime(2008, 5, 5, 0, 0, tzinfo=pytz.utc),
            rule,
            cal,
        )

        recurring_event.save()
        occurrence = recurring_event.get_occurrence(
            datetime.datetime(2008, 1, 12, 8, 0, tzinfo=pytz.utc))
        occurrence.move(datetime.datetime(2008, 1, 15, 8, 0, tzinfo=pytz.utc),
                        datetime.datetime(2008, 1, 15, 9, 0, tzinfo=pytz.utc))
        gen = recurring_event.occurrences_after(
            datetime.datetime(2008, 1, 14, 8, 0, tzinfo=pytz.utc))
        occurrence2 = next(gen)
        #    end = datetime.datetime(2008, 1, 6, tzinfo=pytz.utc))
        #occurrence = occurrences[0]
        #occurrence2 = recurring_event.occurrences_after(datetime.datetime(2008, 1, 5, tzinfo=pytz.utc)).next()
        self.assertEqual(occurrence, occurrence2)
Ejemplo n.º 3
0
 def setUp(self):
     rule = Rule(frequency="WEEKLY")
     rule.save()
     cal = Calendar(name="MyCal")
     cal.save()
     self.recurring_data = {
         'title': 'Recent Event',
         'start': datetime.datetime(2008, 1, 5, 8, 0, tzinfo=pytz.utc),
         'end': datetime.datetime(2008, 1, 5, 9, 0, tzinfo=pytz.utc),
         'end_recurring_period': datetime.datetime(2008, 5, 5, 0, 0, tzinfo=pytz.utc),
         'rule': rule,
         'calendar': cal
     }
     self.data = {
         'title': 'Recent Event',
         'start': datetime.datetime(2008, 1, 5, 8, 0, tzinfo=pytz.utc),
         'end': datetime.datetime(2008, 1, 5, 9, 0, tzinfo=pytz.utc),
         'end_recurring_period': datetime.datetime(2008, 5, 5, 0, 0, tzinfo=pytz.utc),
         'calendar': cal
     }
     self.near_periodend_recurring_data = {
         'title': 'Special Event',
         'start': datetime.datetime(2014, 5, 1, 8, 0, tzinfo=pytz.utc),
         'end': datetime.datetime(2014, 5, 1, 9, 0, tzinfo=pytz.utc),
         'end_recurring_period': datetime.datetime(2014, 5, 8, 9, 0, tzinfo=pytz.utc),
         'rule': rule,
         'calendar': cal
     }
     self.recurring_event = Event.objects.create(**self.recurring_data)
     self.start = datetime.datetime(2008, 1, 12, 0, 0, tzinfo=pytz.utc)
     self.end = datetime.datetime(2008, 1, 27, 0, 0, tzinfo=pytz.utc)
Ejemplo n.º 4
0
    def test_get_occurrences_is_sorted(self):
        rule = Rule(frequency="DAILY")
        rule.save()
        cal = Calendar(name="MyCal")
        cal.save()
        recurring_data = {
            'title':
            'Recent Event',
            'start':
            datetime.datetime(2016, 1, 5, 8, 0, tzinfo=pytz.utc),
            'end':
            datetime.datetime(2016, 1, 5, 9, 0, tzinfo=pytz.utc),
            'end_recurring_period':
            datetime.datetime(2016, 8, 5, 0, 0, tzinfo=pytz.utc),
            'rule':
            rule,
            'calendar':
            cal
        }
        recurring_event = Event.objects.create(**recurring_data)

        start = datetime.datetime(2016, 1, 12, 0, 0, tzinfo=pytz.utc)
        end = datetime.datetime(2016, 1, 27, 0, 0, tzinfo=pytz.utc)
        occurrences = recurring_event.get_occurrences(start=start, end=end)

        sorted_occurrences = sorted(occurrences, key=lambda occ: occ.start)

        self.assertEqual(occurrences, sorted_occurrences)
Ejemplo n.º 5
0
    def test_get_occurrences_timespan_partially_inside_occurrence(self):
        '''
        Test whether occurrences are correctly obtained if selected timespan start
        outside of timepan but ends inside occurrence.
        '''
        cal = Calendar(name="MyCal")
        rule = Rule(frequency="WEEKLY")
        rule.save()

        recurring_event = self.__create_recurring_event(
            'Recurring event test', datetime.datetime(2008, 1, 5, 8, 0),
            datetime.datetime(2008, 1, 5, 9, 0),
            datetime.datetime(2008, 5, 5, 0, 0), rule, cal)

        occs1 = recurring_event.get_occurrences(
            start=datetime.datetime(2006, 1, 1, 0, 0),
            end=datetime.datetime(2008, 1, 19, 8, 30))

        self.assertEqual(["%s to %s" % (o.start, o.end) for o in occs1], [
            '2008-01-05 08:00:00 to 2008-01-05 09:00:00',
            '2008-01-12 08:00:00 to 2008-01-12 09:00:00',
            '2008-01-19 08:00:00 to 2008-01-19 09:00:00',
        ])

        occs2 = recurring_event.get_occurrences(
            start=datetime.datetime(2006, 1, 1, 0, 0),
            end=datetime.datetime(2008, 1, 19, 10, 0))

        self.assertEqual(["%s to %s" % (o.start, o.end) for o in occs2], [
            '2008-01-05 08:00:00 to 2008-01-05 09:00:00',
            '2008-01-12 08:00:00 to 2008-01-12 09:00:00',
            '2008-01-19 08:00:00 to 2008-01-19 09:00:00',
        ])
Ejemplo n.º 6
0
    def test_recurring_event_get_occurrence_in_timezone(self):
        cal = Calendar(name="MyCal")
        cal.save()
        rule = Rule(frequency = "WEEKLY")
        rule.save()

        # Event start and end are UTC because that is what is coming
        # from the database
        event = self.__create_recurring_event(
                    'Recurrent event test get_occurrence',
                    datetime.datetime(2014, 3, 21, 6, 0, tzinfo=pytz.utc),
                    datetime.datetime(2014, 3, 21, 8, 0, tzinfo=pytz.utc),
                    datetime.datetime(2014, 4, 11, 0, 0, tzinfo=pytz.utc),
                    rule,
                    cal,
                    )
        event.save()
        tzinfo = pytz.timezone('Europe/Helsinki')
        start = tzinfo.localize(datetime.datetime(2014, 3, 28, 8, 0)) # +2
        occurrence = event.get_occurrence(start)
        self.assertEqual(occurrence.start, start)
        occurrence.save()
        # DST change on March 30th from +2 to +3
        start = tzinfo.localize(datetime.datetime(2014, 4, 4, 8, 0)) # +3
        occurrence = event.get_occurrence(start)
        self.assertEqual(occurrence.start, start)
Ejemplo n.º 7
0
    def test_recurring_event_get_occurrence_in_timezone(self):
        cal = Calendar(name="MyCal")
        cal.save()
        rule = Rule(frequency="WEEKLY")
        rule.save()

        # Event start and end are UTC because that is what is coming
        # from the database
        event = self.__create_recurring_event(
            'Recurrent event test get_occurrence',
            datetime.datetime(2014, 3, 21, 6, 0, tzinfo=pytz.utc),
            datetime.datetime(2014, 3, 21, 8, 0, tzinfo=pytz.utc),
            datetime.datetime(2014, 4, 11, 0, 0, tzinfo=pytz.utc),
            rule,
            cal,
        )
        event.save()
        tzinfo = pytz.timezone('Europe/Helsinki')
        start = tzinfo.localize(datetime.datetime(2014, 3, 28, 8, 0))  # +2
        occurrence = event.get_occurrence(start)
        self.assertEqual(occurrence.start, start)
        occurrence.save()
        # DST change on March 30th from +2 to +3
        start = tzinfo.localize(datetime.datetime(2014, 4, 4, 8, 0))  # +3
        occurrence = event.get_occurrence(start)
        self.assertEqual(occurrence.start, start)
    def setUp(self):
        self.day = Day(events=Event.objects.all(),
                       date=datetime.datetime(datetime.datetime.now().year, 2, 7, 0, 0, tzinfo=pytz.utc))
        self.day_out_of_limit = Day(events=Event.objects.all(),
                       date=datetime.datetime(datetime.datetime.now().year + 3, 2, 7, 0, 0, tzinfo=pytz.utc))
        self.day_out_of_limit_lower = Day(events=Event.objects.all(),
                       date=datetime.datetime(datetime.datetime.now().year - 3, 2, 7, 0, 0, tzinfo=pytz.utc))

        rule = Rule(frequency='WEEKLY')
        rule.save()
        self.cal = Calendar(name='MyCal', slug='MyCalSlug')
        self.cal.save()

        data = {
            'title': 'Recent Event',
            'start': datetime.datetime(datetime.datetime.now().year, 1, 5, 8, 0, tzinfo=pytz.utc),
            'end': datetime.datetime(datetime.datetime.now().year, 1, 5, 9, 0, tzinfo=pytz.utc),
            'end_recurring_period': datetime.datetime(datetime.datetime.now().year, 5, 5, 0, 0, tzinfo=pytz.utc),
            'rule': rule,
            'calendar': self.cal,
        }
        recurring_event = Event(**data)
        recurring_event.save()
        self.period = Period(events=Event.objects.all(),
                             start=datetime.datetime(datetime.datetime.now().year, 1, 4, 7, 0, tzinfo=pytz.utc),
                             end=datetime.datetime(datetime.datetime.now().year, 1, 21, 7, 0, tzinfo=pytz.utc))
Ejemplo n.º 9
0
def add_task(request, flat_id=None):
    name = request.data.get('name', None)
    user_ids = request.data.get('users', None)
    frequency = request.data.get('frequency', None)

    if name is None or user_ids is None or frequency is None:
        return Response(data={'message': 'Wrong parameters'}, status=400)

    if frequency not in ['DAILY', 'WEEKLY', 'MONTHLY']:
        return Response(
            data={'message': 'Frequency can be: DAILY, WEEKLY, MONTHLY'},
            status=400)

    try:
        flat = Flat.objects.get(id=flat_id)
    except ObjectDoesNotExist:
        return Response(
            data={'message': 'The flat {0} does not exist.'.format(flat_id)},
            status=400)

    user_list = []
    for user_id in user_ids.split(','):
        try:
            user = User.objects.get(id=user_id)
            if user not in flat.users.all():
                return Response(data={
                    'message':
                    '{0} is not a member of the flat.'.format(user.username)
                },
                                status=400)

            user_list.append(user)
        except ObjectDoesNotExist:
            return Response(data={
                'message':
                'The user id {0} does not exist.'.format(user_id)
            },
                            status=400)

    rule = Rule(frequency=frequency, name='{0}_{1}'.format(frequency, name))
    rule.save()

    event = Event(rule=rule,
                  start=datetime.now(),
                  end=datetime.now() + timedelta(days=60),
                  calendar=Calendar.objects.get_calendar_for_object(flat))
    event.save()

    task = Task(flat=flat, name=name, event=event)
    task.save()

    for u in user_list:
        task.users.add(u)
    task.refresh_from_db()

    return Response(data={
        'message': 'Your task has been created.',
        'task': TaskSerializer(task).data,
    },
                    status=200)
Ejemplo n.º 10
0
    def test_recurring_event_with_moved_get_occurrences_after(self):

        cal = Calendar(name="MyCal")
        cal.save()
        rule = Rule(frequency="WEEKLY")
        rule.save()
        recurring_event= self.__create_recurring_event(
                    'Recurrent event test get_occurrence',
                    datetime.datetime(2008, 1, 5, 8, 0, tzinfo=pytz.utc),
                    datetime.datetime(2008, 1, 5, 9, 0, tzinfo=pytz.utc),
                    datetime.datetime(2008, 5, 5, 0, 0, tzinfo=pytz.utc),
                    rule,
                    cal,
                    )

        recurring_event.save()
        occurrence = recurring_event.get_occurrence(datetime.datetime(2008, 1, 12, 8, 0, tzinfo=pytz.utc))
        occurrence.move(
          datetime.datetime(2008, 1, 15, 8, 0, tzinfo=pytz.utc),
          datetime.datetime(2008, 1, 15, 9, 0, tzinfo=pytz.utc))
        gen = recurring_event.occurrences_after(
          datetime.datetime(2008, 1, 14, 8, 0, tzinfo=pytz.utc))
        occurrence2 = next(gen)
        #    end = datetime.datetime(2008, 1, 6, tzinfo=pytz.utc))
        #occurrence = occurrences[0]
        #occurrence2 = recurring_event.occurrences_after(datetime.datetime(2008, 1, 5, tzinfo=pytz.utc)).next()
        self.assertEqual(occurrence, occurrence2)
Ejemplo n.º 11
0
 def setUp(self):
     rule = Rule(frequency="WEEKLY")
     rule.save()
     cal = Calendar(name="MyCal")
     cal.save()
     data = {
         'title':
         'Recent Event',
         'start':
         datetime.datetime(2008, 1, 5, 8, 0, tzinfo=pytz.utc),
         'end':
         datetime.datetime(2008, 1, 5, 9, 0, tzinfo=pytz.utc),
         'end_recurring_period':
         datetime.datetime(2008, 5, 5, 0, 0, tzinfo=pytz.utc),
         'rule':
         rule,
         'calendar':
         cal
     }
     recurring_event = Event(**data)
     recurring_event.save()
     self.month = Month(events=Event.objects.all(),
                        date=datetime.datetime(2008,
                                               2,
                                               7,
                                               9,
                                               0,
                                               tzinfo=pytz.utc))
Ejemplo n.º 12
0
    def test_get_occurrences_rule_weekday_param(self):
        '''
        Test whether occurrence list get method behaves correctly while using
        complex rule parameters
        '''
        cal = Calendar(name="MyCal")
        # Last Fridays of each month
        rule = Rule(frequency="MONTHLY", params='BYWEEKDAY:FR;BYSETPOS:-1')
        rule.save()

        recurring_event = self.__create_recurring_event(
            'Last Friday of each month', datetime.datetime(2016, 11, 1),
            datetime.datetime(2016, 11, 1), datetime.datetime(2030, 1, 1),
            rule, cal)

        occs = recurring_event.get_occurrences(
            start=datetime.datetime(2016, 11, 1),
            end=datetime.datetime(2017, 12, 31))

        self.assertEqual(["%s to %s" % (o.start, o.end) for o in occs], [
            '2016-11-25 00:00:00 to 2016-11-25 00:00:00',
            '2016-12-30 00:00:00 to 2016-12-30 00:00:00',
            '2017-01-27 00:00:00 to 2017-01-27 00:00:00',
            '2017-02-24 00:00:00 to 2017-02-24 00:00:00',
            '2017-03-31 00:00:00 to 2017-03-31 00:00:00',
            '2017-04-28 00:00:00 to 2017-04-28 00:00:00',
            '2017-05-26 00:00:00 to 2017-05-26 00:00:00',
            '2017-06-30 00:00:00 to 2017-06-30 00:00:00',
            '2017-07-28 00:00:00 to 2017-07-28 00:00:00',
            '2017-08-25 00:00:00 to 2017-08-25 00:00:00',
            '2017-09-29 00:00:00 to 2017-09-29 00:00:00',
            '2017-10-27 00:00:00 to 2017-10-27 00:00:00',
            '2017-11-24 00:00:00 to 2017-11-24 00:00:00',
            '2017-12-29 00:00:00 to 2017-12-29 00:00:00',
        ])
Ejemplo n.º 13
0
    def test_get_occurrences_timespan_edge_cases(self):
        '''
        Test whether occurrence list get method behave when requesting them on
        timespan limits
        '''
        cal = Calendar(name="MyCal")
        rule = Rule(frequency="WEEKLY")
        rule.save()

        recurring_event = self.__create_recurring_event(
            'Recurring event test', datetime.datetime(2008, 1, 5, 8, 0),
            datetime.datetime(2008, 1, 5, 9, 0),
            datetime.datetime(2008, 5, 5, 0, 0), rule, cal)

        occs1 = recurring_event.get_occurrences(
            start=datetime.datetime(2008, 1, 5, 8, 0),
            end=datetime.datetime(2008, 1, 5, 8, 30))

        self.assertEqual(["%s to %s" % (o.start, o.end) for o in occs1],
                         ['2008-01-05 08:00:00 to 2008-01-05 09:00:00'])

        occs2 = recurring_event.get_occurrences(
            start=datetime.datetime(2008, 1, 5, 7, 0),
            end=datetime.datetime(2008, 1, 5, 8, 0))

        self.assertEqual(["%s to %s" % (o.start, o.end) for o in occs2], [])
Ejemplo n.º 14
0
 def test_event_can_be_recurring(self):
     rule = Rule(
         name=random_string(),
         description=random_string(),
         frequency='WEEKLY',
     )
     rule.save()
     try:
         url = reverse(
             'openduty.events.create_or_edit_event',
             kwargs = {
                 'calendar_slug': self.cal.slug,
                 'event_id': str(self.event.id),
             },
         )
         response = self.client.post(
             path = url,
             data = {
                 "start_0": self.event.start.strftime('%Y-%m-%d'),
                 "start_1": "09:00",
                 "end_0": self.event.end.strftime('%Y-%m-%d'),
                 "end_1": "23:00",
                 "description": "desc",
                 "rule": str(rule.id),
                 "oncall": "foo",
                 "fallback": "bar",
             },
         )
         self.assertEqual(302, response.status_code)
         e = Event.objects.get(id=self.event.id)
         self.assertEqual(rule, e.rule)
     finally:
         rule.delete()
Ejemplo n.º 15
0
 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')
Ejemplo n.º 16
0
 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)
Ejemplo n.º 17
0
 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)
Ejemplo n.º 18
0
 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)
Ejemplo n.º 19
0
    def test_calendar_absolute_and_event_url(self):
        """
            this test seems to not make too much send, just added since an
            url was with wrong reverse name.

        """
        rule = Rule()
        rule.save()
        calendar = Calendar.objects.get_or_create_calendar_for_object(rule, name='My Cal', distinction='owner')
        abs_url = calendar.get_absolute_url()
        calendar.add_event_url()
        relation = CalendarRelation.objects.create_relation(calendar, rule)
Ejemplo n.º 20
0
 def test_get_params(self):
     rule = Rule(
         params=
         "count:1;bysecond:1;byminute:1,2,4,5;byweekday:FR;bysetpos:-1")
     expected = {
         'count': 1,
         'byminute': [1, 2, 4, 5],
         'bysecond': 1,
         'byweekday': FR,
         'bysetpos': -1
     }
     self.assertEqual(rule.get_params(), expected)
Ejemplo n.º 21
0
 def test_get_params(self):
     rule = Rule(
         params="count:1;bysecond:1;byminute:1,2,4,5;byweekday:FR;bysetpos:-1"
     )
     expected = {
         "count": 1,
         "byminute": [1, 2, 4, 5],
         "bysecond": 1,
         "byweekday": FR,
         "bysetpos": -1,
     }
     self.assertEqual(rule.get_params(), expected)
Ejemplo n.º 22
0
 def test_get_absolute(self):
     cal = Calendar(name='MyCal')
     cal.save()
     rule = Rule(frequency="DAILY")
     rule.save()
     start = timezone.now() + datetime.timedelta(days=1)
     event = self.__create_recurring_event(
         'Non recurring event test get_occurrence', start,
         start + datetime.timedelta(hours=1),
         start + datetime.timedelta(days=10), rule, cal)
     event.save()
     url = event.get_absolute_url()
     self.assertEqual(reverse('event', kwargs={'event_id': event.id}), url)
Ejemplo n.º 23
0
    def setUp(self):
        weekly = Rule(frequency = "WEEKLY")
        weekly.save()
        daily = Rule(frequency = "DAILY")
        daily.save()
        cal = Calendar(name="MyCal")
        cal.save()

        self.event1 = Event(**{
                'title': 'Weekly Event',
                'start': datetime.datetime(2009, 4, 1, 8, 0),
                'end': datetime.datetime(2009, 4, 1, 9, 0),
                'end_recurring_period' : datetime.datetime(2009, 10, 5, 0, 0),
                'rule': weekly,
                'calendar': cal
               })
        self.event1.save()
        self.event2 = Event(**{
                'title': 'Recent Event',
                'start': datetime.datetime(2008, 1, 5, 9, 0),
                'end': datetime.datetime(2008, 1, 5, 10, 0),
                'end_recurring_period' : datetime.datetime(2009, 5, 5, 0, 0),
                'rule': daily,
                'calendar': cal
               })
        self.event2.save()
Ejemplo n.º 24
0
    def test_occurences_with_recurrent_event_end_recurring_period_edge_case(
            self):

        cal = Calendar(name='MyCal')

        rule = Rule(frequency="DAILY")
        rule.save()
        start = timezone.now() + datetime.timedelta(days=1)
        event = self.__create_recurring_event(
            'Non recurring event test get_occurrence', start,
            start + datetime.timedelta(hours=1),
            start + datetime.timedelta(days=10), rule, cal)
        occurrences = list(event.occurrences_after())
        self.assertEquals(len(occurrences), 11)
Ejemplo n.º 25
0
    def setUp(self):
        weekly = Rule(frequency="WEEKLY")
        weekly.save()
        daily = Rule(frequency="DAILY")
        daily.save()
        cal = Room(name="MyCal")
        cal.save()

        self.reservation1 = Reservation(
            **{
                'title': 'Weekly Reservation',
                'start': datetime.datetime(2009, 4, 1, 8, 0),
                'end': datetime.datetime(2009, 4, 1, 9, 0),
                'end_recurring_period': datetime.datetime(2009, 10, 5, 0, 0),
                'rule': weekly,
                'room': cal
            })
        self.reservation1.save()
        self.reservation2 = Reservation(
            **{
                'title': 'Recent Reservation',
                'start': datetime.datetime(2008, 1, 5, 9, 0),
                'end': datetime.datetime(2008, 1, 5, 10, 0),
                'end_recurring_period': datetime.datetime(2009, 5, 5, 0, 0),
                'rule': daily,
                'room': cal
            })
        self.reservation2.save()
Ejemplo n.º 26
0
 def setUp(self):
     rule = Rule(frequency="WEEKLY")
     rule.save()
     data = {
         'title': 'Recent Event',
         'start': datetime.datetime(2008, 1, 5, 8, 0),
         'end': datetime.datetime(2008, 1, 5, 9, 0),
         'end_recurring_period': datetime.datetime(2008, 5, 5, 0, 0),
         'rule': rule,
     }
     recurring_event = Event(**data)
     recurring_event.save()
     self.month = Month(events=Event.objects.all(),
                        date=datetime.datetime(2008, 2, 7, 9, 0))
Ejemplo n.º 27
0
 def setUp(self):
     rule = Rule(frequency = "WEEKLY")
     rule.save()
     data = {
             'title': 'Recent Event',
             'start': datetime.datetime(2008, 1, 5, 8, 0),
             'end': datetime.datetime(2008, 1, 5, 9, 0),
             'end_recurring_period' : datetime.datetime(2008, 5, 5, 0, 0),
             'rule': rule,
            }
     recurring_event = Event(**data)
     recurring_event.save()
     self.month = Month(events=Event.objects.all(),
                        date=datetime.datetime(2008, 2, 7, 9, 0))
Ejemplo n.º 28
0
 def setUp(self):
     rule = Rule(frequency="WEEKLY")
     rule.save()
     cal = Calendar(name="MyCal")
     cal.save()
     data = {
         "title": "Recent Event",
         "start": datetime.datetime(2008, 1, 5, 8, 0, tzinfo=pytz.utc),
         "end": datetime.datetime(2008, 1, 5, 9, 0, tzinfo=pytz.utc),
         "end_recurring_period": datetime.datetime(2008, 5, 5, 0, 0, tzinfo=pytz.utc),
         "rule": rule,
         "calendar": cal,
     }
     self.recurring_event = Event(**data)
     self.recurring_event.save()
Ejemplo n.º 29
0
 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)
Ejemplo n.º 30
0
 def setUp(self):
     rule = Rule(frequency = "WEEKLY")
     rule.save()
     cal = Calendar(name="MyCal")
     cal.save()
     data = {
             'title': 'Recent Event',
             'start': datetime.datetime(2008, 1, 5, 8, 0, tzinfo=pytz.utc),
             'end': datetime.datetime(2008, 1, 5, 9, 0, tzinfo=pytz.utc),
             'end_recurring_period' : datetime.datetime(2008, 5, 5, 0, 0, tzinfo=pytz.utc),
             'rule': rule,
             'calendar': cal
            }
     self.recurring_event = Event(**data)
     self.recurring_event.save()
Ejemplo n.º 31
0
 def setUp(self):
     rule = Rule(frequency="WEEKLY")
     rule.save()
     cal = Room(name="MyCal")
     cal.save()
     data = {
         "title": "Recent Reservation",
         "start": datetime.datetime(2008, 1, 5, 8, 0),
         "end": datetime.datetime(2008, 1, 5, 9, 0),
         "end_recurring_period": datetime.datetime(2008, 5, 5, 0, 0),
         "rule": rule,
         "room": cal,
     }
     self.recurring_reservation = Reservation(**data)
     self.recurring_reservation.save()
Ejemplo n.º 32
0
 def setUp(self):
     rule = Rule(frequency="WEEKLY")
     rule.save()
     cal = Room(name="MyCal")
     cal.save()
     data = {
         'title': 'Recent Reservation',
         'start': datetime.datetime(2008, 1, 5, 8, 0),
         'end': datetime.datetime(2008, 1, 5, 9, 0),
         'end_recurring_period': datetime.datetime(2008, 5, 5, 0, 0),
         'rule': rule,
         'room': cal
     }
     self.recurring_reservation = Reservation(**data)
     self.recurring_reservation.save()
Ejemplo n.º 33
0
 def setUp(self):
     rule = Rule(frequency="WEEKLY")
     rule.save()
     cal = Calendar(name="MyCal")
     cal.save()
     data = {
         'title': 'Recent Event',
         'start': datetime.datetime(2008, 1, 5, 8, 0),
         'end': datetime.datetime(2008, 1, 5, 9, 0),
         'end_recurring_period': datetime.datetime(2008, 5, 5, 0, 0),
         'rule': rule,
         'calendar': cal
     }
     self.recurring_event = Event(**data)
     self.recurring_event.save()
Ejemplo n.º 34
0
 def setUp(self):
     rule = Rule(frequency="WEEKLY")
     rule.save()
     cal = Calendar(name="MyCal")
     cal.save()
     data = {
         "title": "Recent Event",
         "start": datetime.datetime(2008, 1, 5, 8, 0),
         "end": datetime.datetime(2008, 1, 5, 9, 0),
         "end_recurring_period": datetime.datetime(2008, 5, 5, 0, 0),
         "rule": rule,
         "calendar": cal,
     }
     recurring_event = Event(**data)
     recurring_event.save()
     self.month = Month(events=Event.objects.all(), date=datetime.datetime(2008, 2, 7, 9, 0))
Ejemplo n.º 35
0
    def test_occurences_with_recurrent_event_end_recurring_period_edge_case(self):

        cal = Calendar(name='MyCal')

        rule = Rule(frequency = "DAILY")
        rule.save()
        start = timezone.now() + datetime.timedelta(days=1)
        event = self.__create_recurring_event(
                            'Non recurring event test get_occurrence',
                            start,
                            start + datetime.timedelta(hours=1),
                            start + datetime.timedelta(days=10),
                            rule,
                            cal)
        occurrences = list(event.occurrences_after())
        self.assertEqual(len(occurrences), 11)
Ejemplo n.º 36
0
    def test_prevent_type_error_when_comparing_dates_when_tz_off(self):
        cal = Calendar(name="MyCal")
        cal.save()
        rule = Rule(frequency = "WEEKLY")
        rule.save()

        event = self.__create_recurring_event(
                    'Recurrent event test get_occurrence',
                    datetime.datetime(2008, 1, 5, 8, 0),
                    datetime.datetime(2008, 1, 5, 9, 0),
                    datetime.datetime(2008, 5, 5, 0, 0),
                    rule,
                    cal,
                    )
        naive_date = datetime.datetime(2008, 1, 20, 0, 0)
        self.assertIsNone(event.get_occurrence(naive_date))
Ejemplo n.º 37
0
    def test_recurring_event_get_occurrences_after(self):

        cal = Calendar(name="MyCal")
        cal.save()
        rule = Rule(frequency = "WEEKLY")
        rule.save()
        recurring_event= self.__create_recurring_event(
                    'Recurrent event test get_occurrence',
                    datetime.datetime(2008, 1, 5, 8, 0, tzinfo=pytz.utc),
                    datetime.datetime(2008, 1, 5, 9, 0, tzinfo=pytz.utc),
                    datetime.datetime(2008, 5, 5, 0, 0, tzinfo=pytz.utc),
                    rule,
                    cal,
                    )

        recurring_event.save()
Ejemplo n.º 38
0
 def clean_params(self):
     params = self.cleaned_data["params"]
     try:
         Rule(params=params).get_params()
     except (ValueError, SyntaxError):
         raise forms.ValidationError(_("Params format looks invalid"))
     return self.cleaned_data["params"]
Ejemplo n.º 39
0
 def setUp(self):
     rule = Rule(frequency = "WEEKLY")
     rule.save()
     self.recurring_data = {
             'title': 'Recent Event',
             'start': datetime.datetime(2008, 1, 5, 8, 0),
             'end': datetime.datetime(2008, 1, 5, 9, 0),
             'end_recurring_period' : datetime.datetime(2008, 5, 5, 0, 0),
             'rule': rule,
            }
     self.data = {
             'title': 'Recent Event',
             'start': datetime.datetime(2008, 1, 5, 8, 0),
             'end': datetime.datetime(2008, 1, 5, 9, 0),
             'end_recurring_period' : datetime.datetime(2008, 5, 5, 0, 0),
            }
Ejemplo n.º 40
0
 def test_get_absolute(self):
     cal = Calendar(name='MyCal')
     cal.save()
     rule = Rule(frequency="DAILY")
     rule.save()
     start = timezone.now() + datetime.timedelta(days=1)
     event = self.__create_recurring_event(
                         'Non recurring event test get_occurrence',
                         start,
                         start + datetime.timedelta(hours=1),
                         start + datetime.timedelta(days=10),
                         rule,
                         cal)
     event.save()
     url = event.get_absolute_url()
     self.assertEqual(reverse('event', kwargs={'event_id': event.id}), url)
Ejemplo n.º 41
0
 def test_get_occurrences_non_intersection_returns_empty_occ(self):
     rule = Rule(frequency="DAILY")
     rule.save()
     cal = Calendar(name="MyCal")
     cal.save()
     recurring_data = {
         'title': 'Recent Event',
         'start': datetime.datetime(2016, 1, 5, 8, 0, tzinfo=pytz.utc),
         'end': datetime.datetime(2016, 1, 5, 9, 0, tzinfo=pytz.utc),
         'end_recurring_period': datetime.datetime(2016, 8, 5, 0, 0, tzinfo=pytz.utc),
         'rule': rule,
         'calendar': cal
     }
     recurring_event = Event.objects.create(**recurring_data)
     occurrences = recurring_event.get_occurrences(start=self.start, end=self.end)
     self.assertEqual(occurrences, [])
Ejemplo n.º 42
0
    def test_prevent_type_error_when_comparing_dates_when_tz_off(self):
        cal = Calendar(name="MyCal")
        cal.save()
        rule = Rule(frequency="WEEKLY")
        rule.save()

        event = self.__create_recurring_event(
                    'Recurrent event test get_occurrence',
                    datetime.datetime(2008, 1, 5, 8, 0),
                    datetime.datetime(2008, 1, 5, 9, 0),
                    datetime.datetime(2008, 5, 5, 0, 0),
                    rule,
                    cal,
                    )
        naive_date = datetime.datetime(2008, 1, 20, 0, 0)
        self.assertIsNone(event.get_occurrence(naive_date))
Ejemplo n.º 43
0
    def test_recurring_event_get_occurrences_after(self):

        cal = Calendar(name="MyCal")
        cal.save()
        rule = Rule(frequency="WEEKLY")
        rule.save()
        recurring_event= self.__create_recurring_event(
                    'Recurrent event test get_occurrence',
                    datetime.datetime(2008, 1, 5, 8, 0, tzinfo=pytz.utc),
                    datetime.datetime(2008, 1, 5, 9, 0, tzinfo=pytz.utc),
                    datetime.datetime(2008, 5, 5, 0, 0, tzinfo=pytz.utc),
                    rule,
                    cal,
                    )

        recurring_event.save()
Ejemplo n.º 44
0
 def setUp(self):
     rule = Rule(frequency="WEEKLY")
     rule.save()
     self.recurring_data = {
         'title': 'Recent Event',
         'start': datetime.datetime(2008, 1, 5, 8, 0),
         'end': datetime.datetime(2008, 1, 5, 9, 0),
         'end_recurring_period': datetime.datetime(2008, 5, 5, 0, 0),
         'rule': rule,
     }
     self.data = {
         'title': 'Recent Event',
         'start': datetime.datetime(2008, 1, 5, 8, 0),
         'end': datetime.datetime(2008, 1, 5, 9, 0),
         'end_recurring_period': datetime.datetime(2008, 5, 5, 0, 0),
     }
Ejemplo n.º 45
0
    def test_prevent_type_error_when_comparing_naive_and_aware_dates(self):
        # this only test if the TypeError is raised
        cal = Calendar(name="MyCal")
        cal.save()
        rule = Rule(frequency="WEEKLY")
        rule.save()

        event = self.__create_recurring_event(
                    'Recurrent event test get_occurrence',
                    datetime.datetime(2008, 1, 5, 8, 0, tzinfo=pytz.utc),
                    datetime.datetime(2008, 1, 5, 9, 0, tzinfo=pytz.utc),
                    datetime.datetime(2008, 5, 5, 0, 0, tzinfo=pytz.utc),
                    rule,
                    cal,
                    )
        naive_date = datetime.datetime(2008, 1, 20, 0, 0)
        self.assertIsNone(event.get_occurrence(naive_date))
Ejemplo n.º 46
0
    def test_prevent_type_error_when_comparing_naive_and_aware_dates(self):
        # this only test if the TypeError is raised
        cal = Calendar(name="MyCal")
        cal.save()
        rule = Rule(frequency = "WEEKLY")
        rule.save()

        event = self.__create_recurring_event(
                    'Recurrent event test get_occurrence',
                    datetime.datetime(2008, 1, 5, 8, 0, tzinfo=pytz.utc),
                    datetime.datetime(2008, 1, 5, 9, 0, tzinfo=pytz.utc),
                    datetime.datetime(2008, 5, 5, 0, 0, tzinfo=pytz.utc),
                    rule,
                    cal,
                    )
        naive_date = datetime.datetime(2008, 1, 20, 0, 0)
        self.assertIsNone(event.get_occurrence(naive_date))
Ejemplo n.º 47
0
 def test_get_escalation_empty_when_recurrance_is_not_now(self):
     rule = Rule(
         name=random_string(),
         description=random_string(),
         frequency='WEEKLY',
     )
     rule.save()
     # Active yesterday, and 1 week from now, but not today
     event = Event(
         start = timezone.now() - timedelta(days=2),
         end = timezone.now() - timedelta(days=1),
         title = '{username},{username}'.format(username=self.username),
         calendar = self.cal,
         rule = rule,
     )
     event.save()
     events = get_escalation_for_service(self.service)
     self.assertEqual(0, len(events))
Ejemplo n.º 48
0
 def setUp(self):
     rule = Rule(frequency = "WEEKLY")
     rule.save()
     cal = Calendar(name="MyCal")
     cal.save()
     data = {
             'title': 'Recent Event',
             'start': datetime.datetime(2008, 1, 5, 8, 0, tzinfo=pytz.utc),
             'end': datetime.datetime(2008, 1, 5, 9, 0, tzinfo=pytz.utc),
             'end_recurring_period' : datetime.datetime(2008, 5, 5, 0, 0, tzinfo=pytz.utc),
             'rule': rule,
             'calendar': cal
            }
     recurring_event = Event(**data)
     recurring_event.save()
     self.period = Period(events=Event.objects.all(),
                         start = datetime.datetime(2008, 1, 4, 7, 0, tzinfo=pytz.utc),
                         end = datetime.datetime(2008, 1, 21, 7, 0, tzinfo=pytz.utc))
Ejemplo n.º 49
0
 def test_get_escalation_works_when_recurrance_is_now(self):
     rule = Rule(
         name=random_string(),
         description=random_string(),
         frequency='WEEKLY',
     )
     rule.save()
     # Active last week at this time, recurring now
     event = Event(
         start = timezone.now() - timedelta(days=7, hours=5),
         end = timezone.now() + timedelta(hours=4) - timedelta(days=7),
         title = '{username},{username}'.format(username=self.username),
         calendar = self.cal,
         rule = rule,
     )
     event.save()
     events = get_escalation_for_service(self.service)
     self.assertEqual(2, len(events))
Ejemplo n.º 50
0
    def test_recurring_event_get_occurrences(self):
        cal = Calendar(name="MyCal")
        rule = Rule(frequency = "WEEKLY")
        rule.save()

        recurring_event = self.__create_recurring_event(
                                    'Recurring event test',
                                    datetime.datetime(2008, 1, 5, 8, 0, tzinfo=pytz.utc),
                                    datetime.datetime(2008, 1, 5, 9, 0, tzinfo=pytz.utc),
                                    datetime.datetime(2008, 5, 5, 0, 0, tzinfo=pytz.utc),
                                    rule,
                                    cal
                )
        occurrences = recurring_event.get_occurrences(
                                    start=datetime.datetime(2008, 1, 12, 0, 0, tzinfo=pytz.utc),
                                    end=datetime.datetime(2008, 1, 20, 0, 0, tzinfo=pytz.utc))

        self.assertEquals(["%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'])
Ejemplo n.º 51
0
 def setUp(self):
     rule = Rule(frequency="WEEKLY")
     rule.save()
     cal = Calendar(name="MyCal")
     cal.save()
     data = {
         "title": "Recent Event",
         "start": datetime.datetime(2008, 1, 5, 8, 0, tzinfo=pytz.utc),
         "end": datetime.datetime(2008, 1, 5, 9, 0, tzinfo=pytz.utc),
         "end_recurring_period": datetime.datetime(2008, 5, 5, 0, 0, tzinfo=pytz.utc),
         "rule": rule,
         "calendar": cal,
     }
     recurring_event = Event(**data)
     recurring_event.save()
     self.period = Period(
         events=Event.objects.all(),
         start=datetime.datetime(2008, 1, 4, 7, 0, tzinfo=pytz.utc),
         end=datetime.datetime(2008, 1, 21, 7, 0, tzinfo=pytz.utc),
     )
Ejemplo n.º 52
0
 def setUp(self):
     rule = Rule(frequency = "WEEKLY")
     rule.save()
     cal = Room(name="MyCal")
     cal.save()
     self.recurring_data = {
             'title': 'Recent Reservation',
             'start': datetime.datetime(2008, 1, 5, 8, 0),
             'end': datetime.datetime(2008, 1, 5, 9, 0),
             'end_recurring_period' : datetime.datetime(2008, 5, 5, 0, 0),
             'rule': rule,
             'room': cal
            }
     self.data = {
             'title': 'Recent Reservation',
             'start': datetime.datetime(2008, 1, 5, 8, 0),
             'end': datetime.datetime(2008, 1, 5, 9, 0),
             'end_recurring_period' : datetime.datetime(2008, 5, 5, 0, 0),
             'room': cal
            }
Ejemplo n.º 53
0
 def setUp(self):
     rule = Rule(frequency="WEEKLY")
     rule.save()
     cal = Room(name="MyCal")
     cal.save()
     data = {
         "title": "Recent Reservation",
         "start": datetime.datetime(2008, 1, 5, 8, 0),
         "end": datetime.datetime(2008, 1, 5, 9, 0),
         "end_recurring_period": datetime.datetime(2008, 5, 5, 0, 0),
         "rule": rule,
         "room": cal,
     }
     recurring_reservation = Reservation(**data)
     recurring_reservation.save()
     self.period = Period(
         reservations=Reservation.objects.all(),
         start=datetime.datetime(2008, 1, 4, 7, 0),
         end=datetime.datetime(2008, 1, 21, 7, 0),
     )
Ejemplo n.º 54
0
    def test_recurring_event_get_occurrence(self):

        cal = Calendar(name="MyCal")
        cal.save()
        rule = Rule(frequency="WEEKLY")
        rule.save()

        event = self.__create_recurring_event(
                    'Recurrent event test get_occurrence',
                    datetime.datetime(2008, 1, 5, 8, 0, tzinfo=pytz.utc),
                    datetime.datetime(2008, 1, 5, 9, 0, tzinfo=pytz.utc),
                    datetime.datetime(2008, 5, 5, 0, 0, tzinfo=pytz.utc),
                    rule,
                    cal,
                    )
        event.save()
        occurrence = event.get_occurrence(datetime.datetime(2008, 1, 5, 8, 0, tzinfo=pytz.utc))
        self.assertEqual(occurrence.start, datetime.datetime(2008, 1, 5, 8, tzinfo=pytz.utc))
        occurrence.save()
        occurrence = event.get_occurrence(datetime.datetime(2008, 1, 5, 8, 0, tzinfo=pytz.utc))
        self.assertTrue(occurrence.pk is not None)
Ejemplo n.º 55
0
    def test_event_get_occurrences_after(self):

        cal = Calendar(name="MyCal")
        cal.save()
        rule = Rule(frequency="WEEKLY")
        rule.save()

        self.__create_recurring_event(
                    'Recurrent event test get_occurrence',
                    datetime.datetime(2008, 1, 5, 8, 0, tzinfo=pytz.utc),
                    datetime.datetime(2008, 1, 5, 9, 0, tzinfo=pytz.utc),
                    datetime.datetime(2008, 5, 5, 0, 0, tzinfo=pytz.utc),
                    rule,
                    cal,
                    )
        event_one = self.__create_event(
                'Edge case event test one',
                datetime.datetime(2013, 1, 5, 8, 0, tzinfo=pytz.utc),
                datetime.datetime(2013, 1, 5, 9, 0, tzinfo=pytz.utc),
                cal
        )
        event_two = self.__create_event(
                'Edge case event test two',
                datetime.datetime(2013, 1, 5, 9, 0, tzinfo=pytz.utc),
                datetime.datetime(2013, 1, 5, 12, 0, tzinfo=pytz.utc),
                cal
        )
        event_one.save()
        event_two.save()
        occurrences_two = event_two.get_occurrences(
                                    datetime.datetime(2013, 1, 5, 9, 0, tzinfo=pytz.utc),
                                    datetime.datetime(2013, 1, 5, 12, 0, tzinfo=pytz.utc))

        self.assertEqual(1, len(occurrences_two))

        occurrences_one = event_one.get_occurrences(
                                    datetime.datetime(2013, 1, 5, 9, 0, tzinfo=pytz.utc),
                                    datetime.datetime(2013, 1, 5, 12, 0, tzinfo=pytz.utc))

        self.assertEqual(0, len(occurrences_one))