Пример #1
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)
Пример #2
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))
Пример #3
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)
Пример #4
0
def create(request, form_class=TribeForm, template_name="tribes/create.html"):
    if request.user.is_authenticated() and request.method == "POST":
        if request.POST["action"] == "create":
            tribe_form = form_class(request.POST)
            if tribe_form.is_valid():
                tribe = tribe_form.save(commit=False)
                tribe.creator = request.user
                tribe.save()
                tribe.members.add(request.user)
                tribe.save()
                # @@@ this is just temporary to give tribes a single calendar -- will revisit during whole
                # tribe/project merge effort
                calendar = Calendar(name = "%s Calendar" % tribe.name)
                calendar.save()
                CalendarRelation.objects.create_relation(calendar, tribe, distinction="default", inheritable=True)
                if notification:
                    # @@@ might be worth having a shortcut for sending to all users
                    notification.send(User.objects.all(), "tribes_new_tribe", {"tribe": tribe}, queue=True)
                    if friends: # @@@ might be worth having a shortcut for sending to all friends
                        notification.send((x['friend'] for x in Friendship.objects.friends_for_user(tribe.creator)), "tribes_friend_tribe", {"tribe": tribe})
                #return render_to_response("base.html", {
                #}, context_instance=RequestContext(request))
                return HttpResponseRedirect(tribe.get_absolute_url())
        else:
            tribe_form = form_class()
    else:
        tribe_form = form_class()
    
    return render_to_response(template_name, {
        "tribe_form": tribe_form,
    }, context_instance=RequestContext(request))
Пример #5
0
    def test_edge_case_events(self):
        cal = Calendar(name="MyCal")
        cal.save()
        data_1 = {
            'title': 'Edge case event test one',
            'start': datetime.datetime(2013, 1, 5, 8, 0, tzinfo=pytz.utc),
            'end': datetime.datetime(2013, 1, 5, 9, 0, tzinfo=pytz.utc),
            'calendar': cal
        }
        data_2 = {
            'title': 'Edge case event test two',
            'start': datetime.datetime(2013, 1, 5, 9, 0, tzinfo=pytz.utc),
            'end': datetime.datetime(2013, 1, 5, 12, 0, tzinfo=pytz.utc),
            'calendar': cal
        }
        event_one = Event(**data_1)
        event_two = Event(**data_2)
        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))
    def test_all_day_event_cook_slots(self):
        cal = Calendar(name='MyCal', slug='MyCalSlug')
        cal.save()
        start = datetime.datetime(datetime.datetime.now().year,
                                  1,
                                  5,
                                  0,
                                  0,
                                  tzinfo=pytz.utc)
        end = datetime.datetime(datetime.datetime.now().year,
                                1,
                                6,
                                0,
                                0,
                                tzinfo=pytz.utc)
        data = {
            'title': 'All Day Event',
            'start': start,
            'end': end,
            'calendar': self.cal,
        }
        event = Event(**data)
        event.save()
        period = Day([event], start, end)

        slots = _cook_slots(period, 60)
        self.assertEqual(len(slots), 24)
Пример #7
0
 def save(self, force_insert=False, force_update=False):
     new_task = True
     super(PostEater, self).save(force_insert, force_update)
     end = self.startDateTime + timedelta(minutes=1)
     color = '#A41515'
     description = "http://127.0.0.1:8000/posts/" + str(
         self.submit_time.strftime("%Y/%b/%d"))
     user_short = self.user.profile.housename
     if new_task:
         event = Event(start=self.startDateTime,
                       end=end,
                       title=user_short,
                       description=description,
                       calendar_id=1)
         event.save()
         rel = EventRelation.objects.create_relation(event, self)
         rel.save()
         try:
             cal = Calendar.objects.get(name="hooggeacht")
         except Calendar.DoesNotExist:
             cal = Calendar(name="bla")
             cal.save()
         cal.events.add(event)
     else:
         event = Event.objects.get_for_object(self)[0]
         event.start = self.startDateTime
         event.end = end
         event.title = title
         event.description = self.description
         event.eventColor = self.color
         event.save()
Пример #8
0
 def setUp(self):
     super(TestSchedulesViews, self).setUp()
     self.cal = Calendar(
         name=random_string(),
         slug=random_string(),
     )
     self.cal.save()
Пример #9
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)
Пример #10
0
class TestSchedulesViews(LoggedInTestCase):
    def setUp(self):
        super(TestSchedulesViews, self).setUp()
        self.cal = Calendar(
            name=random_string(),
            slug=random_string(),
        )
        self.cal.save()

    def tearDown(self):
        super(TestSchedulesViews, self).tearDown()
        try:
            self.cal.delete()
        except Exception:
            pass

    @pytest.mark.skip(reason="TO Be Fixed")
    def test_schedule_detail_view_works_with_query_args(self):
        assert self.cal.id
        response = self.client.get(
            reverse('calendar_details', args=[self.cal.slug]),
            {
                'month': '11',
                'year': '2014'
            },
        )
        self.assertEqual(response.status_code, 200)
Пример #11
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)
Пример #12
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)
Пример #13
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)
Пример #14
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()
Пример #15
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)
Пример #16
0
    def test_edge_case_events(self):
        cal = Calendar(name="MyCal")
        cal.save()
        data_1 = {
            'title': 'Edge case event test one',
            'start': datetime.datetime(2013, 1, 5, 8, 0, tzinfo=pytz.utc),
            'end': datetime.datetime(2013, 1, 5, 9, 0, tzinfo=pytz.utc),
            'calendar': cal
        }
        data_2 = {
            'title': 'Edge case event test two',
            'start': datetime.datetime(2013, 1, 5, 9, 0, tzinfo=pytz.utc),
            'end': datetime.datetime(2013, 1, 5, 12, 0, tzinfo=pytz.utc),
            'calendar': cal
        }
        event_one = Event(**data_1)
        event_two = Event(**data_2)
        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))
Пример #17
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()
Пример #18
0
    def setUp(self):
        doctor = Doctors(name = 'Victor', registration= '112020122',CPF='1637615253',status =True, category='1231233212')
        doctor.save()
        calendar = Calendar(name = 'Test Calendar')
        calendar.save()
        subtitle = Subtitles(1)
        self.event_attr = {
            'id':1,
            'subtitle': subtitle,
            'start': datetime.datetime(2013, 1, 5, 8, 0, tzinfo=pytz.utc),
            'end': datetime.datetime(2013, 1, 5, 9, 0, tzinfo=pytz.utc),
            'doctor': doctor,
            'calendar': calendar
        }

        self.serializer_data = {
            'id':0,
            'subtitle':subtitle,
            'start': datetime.datetime(2013, 1, 5, 8, 0, tzinfo=pytz.utc),
            'end': datetime.datetime(2013, 1, 5, 9, 0, tzinfo=pytz.utc),
            'doctor':doctor,
            'calendar': calendar
        }
        self.event = Event.objects.create(**self.event_attr)
        self.serializer = EventSerializer(instance=self.event)
Пример #19
0
class TestSchedulesViews(LoggedInTestCase):
    def setUp(self):
        super(TestSchedulesViews, self).setUp()
        self.cal = Calendar(
            name=random_string(),
            slug=random_string(),
        )
        self.cal.save()

    def tearDown(self):
        super(TestSchedulesViews, self).tearDown()
        try:
            self.cal.delete()
        except:
            pass

    def test_schedule_detail_view_works_with_query_args(self):
        response = self.client.get(
            reverse('openduty.schedules.details', args=[self.cal.id]),
            {
                'month': '11',
                'year': '2014'
            },
        )
        self.assertEqual(response.status_code, 200)
 def test_create_calendar_relation(self):
     user = User.objects.create(username='******',
                                password='******')
     user.save()
     calendar = Calendar(name='Test Calendar')
     calendar.save()
     relation = calendar.create_relation(user)
     self.assertEqual(relation, None)
Пример #21
0
 def save(self, force_insert=False, force_update=False):
     super(CircleEvent, self).save(force_insert, force_update)
     try:
         cal = Calendar.objects.get(pk=1)
     except Calendar.DoesNotExist:
         cal = Calendar(name="Community Calendar")
         cal.save()
     cal.events.add(self)
Пример #22
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')
Пример #23
0
 def save(self, force_insert=False, force_update=False):
     super(CircleEvent, self).save(force_insert, force_update)
     try:
         cal = Calendar.objects.get(pk=1)
     except Calendar.DoesNotExist:
         cal = Calendar(name="Community Calendar")
         cal.save()
     cal.events.add(self)
Пример #24
0
class TestEventViews(LoggedInTestCase):

    def setUp(self):
        super(TestEventViews, self).setUp()
        self.cal = Calendar(
            name=random_string(),
            slug=random_string(),
        )
        self.cal.save()
        self.event = Event(
            start=timezone.now(),
            end=timezone.now() + timedelta(weeks=6),
            title=random_string(),
            calendar=self.cal,
        )
        self.event.save()

    def tearDown(self):
        super(TestEventViews, self).tearDown()
        try:
            self.cal.delete()
            self.event.delete()
        except:
            pass

    def test_event_can_be_recurring(self):
        rule = Rule(
            name=random_string(),
            description=random_string(),
            frequency='WEEKLY',
        )
        rule.save()
        try:
            url = reverse(
                '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()
Пример #25
0
class TestEventViews(LoggedInTestCase):

    def setUp(self):
        super(TestEventViews, self).setUp()
        self.cal = Calendar(
            name=random_string(),
            slug=random_string(),
        )
        self.cal.save()
        self.event = Event(
            start=timezone.now(),
            end=timezone.now() + timedelta(weeks=6),
            title=random_string(),
            calendar=self.cal,
        )
        self.event.save()

    def tearDown(self):
        super(TestEventViews, self).tearDown()
        try:
            self.cal.delete()
            self.event.delete()
        except:
            pass

    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()
Пример #26
0
 def save(self, *args, **kwargs):
     if not self.pk:
         if not hasattr(self, 'calendar'):
             if not self.slug:
                 self.slug = slugify(self.name)
             calendar = Calendar(name=self.name, slug=self.slug)
             calendar.save()
             setattr(self, 'calendar', calendar)
     super(Way, self).save(*args, **kwargs)
Пример #27
0
 def test_occurrences_after_with_events_before_returns_empty(self):
     calendar = Calendar()
     calendar.save()
     start_after = timezone.now() + datetime.timedelta(days=-1)
     end_after = start_after + datetime.timedelta(hours=1)
     event = self.__create_event(start_after, end_after)
     calendar.events.add(event)
     occurrences = list(calendar.occurrences_after(timezone.now()))
     self.assertEqual(occurrences, [])
Пример #28
0
 def test_event_get_ocurrence(self):
     cal = Calendar(name='MyCal')
     cal.save()
     start = timezone.now() + datetime.timedelta(days=1)
     event = self.__create_event('Non recurring event test get_occurrence',
                                 start, start + datetime.timedelta(hours=1),
                                 cal)
     event.save()
     occurrence = event.get_occurrence(start)
     self.assertEqual(occurrence.start, start)
Пример #29
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)
Пример #30
0
 def test_occurrences_after_with_events_after_returns_events(self):
     calendar = Calendar()
     calendar.save()
     start_after = timezone.now() + datetime.timedelta(days=1)
     end_after = start_after + datetime.timedelta(hours=1)
     event = self.__create_event(start_after, end_after)
     calendar.events.add(event)
     occurrences = list(calendar.occurrences_after(timezone.now()))
     self.assertEquals(len(occurrences), 1)
     self.assertEquals(occurrences[0].start, start_after)
     self.assertEquals(occurrences[0].end, end_after)
Пример #31
0
 def test_occurrences_after_with_events_after_returns_events(self):
     calendar = Calendar()
     calendar.save()
     start_after = timezone.now() + datetime.timedelta(days=1)
     end_after = start_after + datetime.timedelta(hours=1)
     event = self.__create_event(start_after, end_after)
     calendar.events.add(event)
     occurrences = list(calendar.occurrences_after(timezone.now()))
     self.assertEquals(len(occurrences), 1)
     self.assertEquals(occurrences[0].start, start_after)
     self.assertEquals(occurrences[0].end, end_after)
Пример #32
0
    def post(self, request, *args, **kwargs):
        form = self.form_class(request.POST)
        if form.is_valid():
            self.user = form.save(commit=True)

            # create the calendar
            cal = Calendar(name='Nutriton Calendar ' + self.user.name,
                           slug='nutrition' + self.user.name.lower() +
                           str(self.user.pk))
            cal.save()
            # create events from prototypes
            b_event = Event.objects.get(pk=9)
            b_event.pk = None
            b_event.save()
            b_event.calendar = cal
            b_event.save()
            l_event = Event.objects.get(pk=12)
            l_event.pk = None
            l_event.save()
            l_event.calendar = cal
            l_event.save()
            d_event = Event.objects.get(pk=11)
            d_event.pk = None
            d_event.save()
            d_event.calendar = cal
            d_event.save()
            s1_event = Event.objects.get(pk=10)
            s1_event.pk = None
            s1_event.save()
            s1_event.calendar = cal
            s1_event.save()
            s2_event = Event.objects.get(pk=13)
            s2_event.pk = None
            s2_event.save()
            s2_event.calendar = cal
            s2_event.save()

            self.user.calendar = cal
            self.user.save()

            today = datetime.date.today()
            start = today - datetime.timedelta(days=today.weekday())
            start = datetime.datetime.combine(start, datetime.time(0, 0))
            end = start + datetime.timedelta(days=6)
            end = datetime.datetime.combine(end, datetime.time(23, 59))
            plan = self.user.create_meals_for_week(start=start, end=end)
            #self.user.plan = json.dumps(plan, default=dumper, indent=2)
            self.user.save()

            return HttpResponseRedirect(
                reverse('mealplan', kwargs={'pk': self.user.id}))
        else:
            return render(request, self.template_name, {'form': form})
Пример #33
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)
Пример #34
0
    def test_event_get_ocurrence(self):

        cal = Calendar(name='MyCal')
        cal.save()
        start = timezone.now() + datetime.timedelta(days=1)
        event = self.__create_event(
                            'Non recurring event test get_occurrence',
                            start,
                            start + datetime.timedelta(hours=1),
                            cal)
        event.save()
        occurrence = event.get_occurrence(start)
        self.assertEqual(occurrence.start, start)
Пример #35
0
    def save_model(self, request, obj, form, change):
        if not hasattr(obj, 'host') and request.user.hosts.count() == 1:
            obj.host = request.user.hosts.all()[0]

        try:
            calendar = Calendar.objects.get(slug=obj.host.slug)
        except Calendar.DoesNotExist:
            calendar = Calendar(name=obj.host.name, slug=obj.host.slug)
            calendar.save()
        obj.calendar = calendar
        if not obj.creator:
            obj.creator = request.user
        super().save_model(request, obj, form, change)
Пример #36
0
 def test_occurences_after_with_no_params(self):
     cal = Calendar(name='MyCal')
     cal.save()
     start = timezone.now() + datetime.timedelta(days=1)
     event = self.__create_event('Non recurring event test get_occurrence',
                                 start, start + datetime.timedelta(hours=1),
                                 cal)
     event.save()
     occurrences = list(event.occurrences_after())
     self.assertEqual(len(occurrences), 1)
     self.assertEqual(occurrences[0].start, start)
     self.assertEqual(occurrences[0].end,
                      start + datetime.timedelta(hours=1))
Пример #37
0
 def setUp(self):
     super(TestEventViews, self).setUp()
     self.cal = Calendar(
         name=random_string(),
         slug=random_string(),
     )
     self.cal.save()
     self.event = Event(
         start=timezone.now(),
         end=timezone.now() + timedelta(weeks=6),
         title=random_string(),
         calendar=self.cal,
     )
     self.event.save()
Пример #38
0
def optionnal_calendar_new(sender, **kwargs):
    event = kwargs.pop('instance')

    if not isinstance(event, Event):
        return True
    if not event.calendar:
        try:
            calendar = Calendar._default_manager.get(name='defaulter')
        except Calendar.DoesNotExist:
            calendar = Calendar(name='defaulter', slug='defaulter')
            calendar.save()

        event.calendar = calendar
    return True
Пример #39
0
def optionnal_calendar(sender, **kwargs):
    event = kwargs.pop('instance')

    if not isinstance(event, Event):
        return True
    if not event.calendar:
        try:
            calendar = Calendar._default_manager.get(name='default')
        except Calendar.DoesNotExist:
            calendar = Calendar(name='default', slug='default')
            calendar.save()

        event.calendar = calendar
    return True
Пример #40
0
 def test_occurences_with_recurrent_event_no_end_recurring_period_max_loop(
         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(hours=10), rule, cal)
     event.save()
     occurrences = list(event.occurrences_after(max_occurrences=1))
     self.assertEqual(len(occurrences), 1)
Пример #41
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()
Пример #42
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()
Пример #43
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()
Пример #44
0
    def test_occurences_after_with_no_params(self):

        cal = Calendar(name='MyCal')
        cal.save()
        start = timezone.now() + datetime.timedelta(days=1)
        event = self.__create_event(
                            'Non recurring event test get_occurrence',
                            start,
                            start + datetime.timedelta(hours=1),
                            cal)
        event.save()
        occurrences = list(event.occurrences_after())
        self.assertEqual(len(occurrences), 1)
        self.assertEqual(occurrences[0].start, start)
        self.assertEqual(occurrences[0].end, start + datetime.timedelta(hours=1))
Пример #45
0
class TestTemplateTags(TestCase):
    def setUp(self):
        self.day = Day(events=Event.objects.all(),
                       date=datetime.datetime(2008, 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(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': self.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))

    def test_querystring_for_datetime(self):
        date = datetime.datetime(2008, 1, 1, 0, 0, 0)
        query_string = querystring_for_date(date, autoescape=True)
        self.assertEqual(escape("?year=2008&month=1&day=1&hour=0&minute=0&second=0"),
            query_string)

    def test_prev_url(self):
        query_string = prev_url("month_calendar", 'MyCalSlug', self.day)
        expected = ("/calendar/month/MyCalSlug/?year=2008&month=2&day=6&hour=0"
                    "&minute=0&second=0")
        self.assertEqual(query_string, escape(expected))

    def test_next_url(self):
        query_string = next_url("month_calendar", 'MyCalSlug', self.day)
        expected = ("/calendar/month/MyCalSlug/?year=2008&month=2&day=8&hour=0"
                    "&minute=0&second=0")
        self.assertEqual(query_string, escape(expected))

    def test_create_event_url(self):
        context = {}
        slot = self.period.get_time_slot(datetime.datetime(2010, 1, 4, 7, 0, tzinfo=pytz.utc),
                                         datetime.datetime(2008, 1, 4, 7, 12, tzinfo=pytz.utc))
        query_string = create_event_url(context, self.cal, slot.start)
        expected = ("/event/create/MyCalSlug/?year=2010&month=1&day=4&hour=7"
                    "&minute=0&second=0")
        self.assertEqual(query_string['create_event_url'], escape(expected))
Пример #46
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)
Пример #47
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))
Пример #48
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))
Пример #49
0
 def setUp(self):
     super(TestSchedulesViews, self).setUp()
     self.cal = Calendar(
         name=random_string(),
         slug=random_string(),
     )
     self.cal.save()
Пример #50
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))
Пример #51
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()
    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))
Пример #53
0
class TestTemplateTags(TestCase):
    def setUp(self):
        self.day = Day(events=Event.objects.all(), date=datetime.datetime(2008, 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(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": self.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),
        )

    def test_querystring_for_datetime(self):
        date = datetime.datetime(2008, 1, 1, 0, 0, 0)
        query_string = querystring_for_date(date, autoescape=True)
        self.assertEqual(escape("?year=2008&month=1&day=1&hour=0&minute=0&second=0"), query_string)

    def test_prev_url(self):
        query_string = prev_url("month_calendar", "MyCalSlug", self.day)
        expected = "/calendar/month/MyCalSlug/?year=2008&month=2&day=6&hour=0" "&minute=0&second=0"
        self.assertEqual(query_string, escape(expected))

    def test_next_url(self):
        query_string = next_url("month_calendar", "MyCalSlug", self.day)
        expected = "/calendar/month/MyCalSlug/?year=2008&month=2&day=8&hour=0" "&minute=0&second=0"
        self.assertEqual(query_string, escape(expected))

    def test_create_event_url(self):
        context = {}
        slot = self.period.get_time_slot(
            datetime.datetime(2010, 1, 4, 7, 0, tzinfo=pytz.utc), datetime.datetime(2008, 1, 4, 7, 12, tzinfo=pytz.utc)
        )
        query_string = create_event_url(context, self.cal, slot.start)
        expected = "/event/create/MyCalSlug/?year=2010&month=1&day=4&hour=7" "&minute=0&second=0"
        self.assertEqual(query_string["create_event_url"], escape(expected))
Пример #54
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))
Пример #55
0
def create_club(request, template_name="schedule_tests/clubs/new.html"):
    if request.method == 'POST':
        form = ClubForm(request.POST)
        if form.is_valid():
            club = form.save(commit=False)
            club.save()
            calendar = Calendar(name = "%s Calendar" % club.name, slug = unicode(uuid.uuid1()))
            calendar.save()
            CalendarRelation.objects.create_relation(calendar, club, distinction="default", inheritable=True)
            
            return HttpResponseRedirect(reverse('show_club', args=(club.id,)))
        # if invalid, it gets displayed below
    else:
        form = ClubForm()
 
    return render_to_response(template_name, {'form': form,},
                              context_instance=RequestContext(request))
Пример #56
0
def save(request):
    try:
        sched = Calendar.objects.get(id = request.POST['id'])
    except Calendar.DoesNotExist:
        sched = Calendar()

    sched.name = request.POST['name']
    sched.slug = request.POST['slug']
    try:
        sched.save()
        return HttpResponseRedirect('/schedules/');
    except IntegrityError:
        messages.error(request, 'Schedule already exists')
        if int(request.POST['id']) > 0:
            return HttpResponseRedirect(reverse('openduty.schedules.edit', None, [str(request.POST['id'])]))
        else:
            return HttpResponseRedirect(reverse('openduty.schedules.new'))
Пример #57
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))
Пример #58
0
    def test_occurences_with_recurrent_event_end_recurring_period_edge_case(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()
        occurrences = list(event.occurrences_after())
        self.assertEqual(len(occurrences), 11)
Пример #59
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))