[CalendarServer-changes] [8669] CalendarServer/trunk/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Mon Feb 13 17:22:55 PST 2012


Revision: 8669
          http://trac.macosforge.org/projects/calendarserver/changeset/8669
Author:   sagen at apple.com
Date:     2012-02-13 17:22:55 -0800 (Mon, 13 Feb 2012)
Log Message:
-----------
validCalendarData( ) can now remove EXDATEs that occur earlier than the master.

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/ical.py
    CalendarServer/trunk/twistedcaldav/test/test_icalendar.py

Modified: CalendarServer/trunk/twistedcaldav/ical.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/ical.py	2012-02-14 01:19:18 UTC (rev 8668)
+++ CalendarServer/trunk/twistedcaldav/ical.py	2012-02-14 01:22:55 UTC (rev 8669)
@@ -1343,6 +1343,18 @@
                 for property in master.properties("RDATE"):
                     rdates.extend([_rdate.getValue() for _rdate in property.value()])
                 valid_rids.update(set(rdates))
+
+                # Remove EXDATEs predating master
+                dtstart = master.propertyValue("DTSTART")
+                if dtstart is not None:
+                    for property in list(master.properties("EXDATE")):
+                        for exdate in [_exdate.getValue() for _exdate in property.value()]:
+                            if exdate < dtstart:
+                                if doFix:
+                                    master.removeProperty(property)
+                                    fixed.append("Removed earlier EXDATE: %s" % (exdate,))
+                                else:
+                                    unfixed.append("EXDATE earlier than master: %s" % (exdate,))
             else:
                 valid_rids = set()
 

Modified: CalendarServer/trunk/twistedcaldav/test/test_icalendar.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/test/test_icalendar.py	2012-02-14 01:19:18 UTC (rev 8668)
+++ CalendarServer/trunk/twistedcaldav/test/test_icalendar.py	2012-02-14 01:22:55 UTC (rev 8669)
@@ -451,6 +451,83 @@
         calendar.validCalendarData(doFix=False, validateRecurrences=True)
 
 
+        # Test EXDATEs *prior* to master (as the result of client splitting a
+        # a recurring event and copying *all* EXDATEs to new event):
+        data = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//iCal 5.0.1//EN
+CALSCALE:GREGORIAN
+BEGIN:VTIMEZONE
+TZID:US/Pacific
+BEGIN:DAYLIGHT
+TZOFFSETFROM:-0800
+RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU
+DTSTART:20070311T020000
+TZNAME:PDT
+TZOFFSETTO:-0700
+END:DAYLIGHT
+BEGIN:STANDARD
+TZOFFSETFROM:-0700
+RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU
+DTSTART:20071104T020000
+TZNAME:PST
+TZOFFSETTO:-0800
+END:STANDARD
+END:VTIMEZONE
+BEGIN:VEVENT
+CREATED:20120213T224430Z
+UID:BD84E32F-15A4-4354-9A72-EA240657734B
+DTEND;TZID=US/Pacific:20120218T160000
+RRULE:FREQ=DAILY;COUNT=396
+TRANSP:OPAQUE
+SUMMARY:RECUR
+DTSTART;TZID=US/Pacific:20120218T140000
+EXDATE;TZID=US/Pacific:20120215T113000
+EXDATE;TZID=US/Pacific:20120216T113000
+EXDATE;TZID=US/Pacific:20120220T113000
+DTSTAMP:20120213T224523Z
+SEQUENCE:3
+END:VEVENT
+BEGIN:VEVENT
+CREATED:20120213T224430Z
+UID:BD84E32F-15A4-4354-9A72-EA240657734B
+DTEND;TZID=US/Pacific:20120221T134500
+TRANSP:OPAQUE
+SUMMARY:RECUR
+DTSTART;TZID=US/Pacific:20120221T114500
+DTSTAMP:20120214T000440Z
+SEQUENCE:4
+RECURRENCE-ID;TZID=US/Pacific:20120221T140000
+END:VEVENT
+END:VCALENDAR
+"""
+        # Ensure it starts off invalid
+        calendar = Component.fromString(data)
+        try:
+            calendar.validCalendarData(doFix=False, validateRecurrences=True)
+        except InvalidICalendarDataError:
+            pass
+        else:
+            self.fail("Shouldn't validate for CalDAV")
+
+        # Fix it
+        fixed, unfixed = calendar.validCalendarData(doFix=True,
+            validateRecurrences=True)
+        self.assertEquals(fixed,
+            ["Removed earlier EXDATE: 20120215T113000",
+            "Removed earlier EXDATE: 20120216T113000"]
+        )
+        self.assertEquals(unfixed, [])
+        # These two old EXDATES are removed
+        self.assertTrue("EXDATE;TZID=US/Pacific:20120215T113000\r\n" not in str(calendar))
+        self.assertTrue("EXDATE;TZID=US/Pacific:20120216T113000\r\n" not in str(calendar))
+        # This EXDATE remains
+        self.assertTrue("EXDATE;TZID=US/Pacific:20120220T113000\r\n" in str(calendar))
+
+        # Now it should pass without fixing
+        calendar.validCalendarData(doFix=False, validateRecurrences=True)
+
+
     def test_component_timeranges(self):
         """
         Component time range query.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120213/576cfab6/attachment.html>


More information about the calendarserver-changes mailing list