[CalendarServer-changes] [15088] CalendarServer/branches/release/CalendarServer-5.4-dev/ calendarserver/tools

source_changes at macosforge.org source_changes at macosforge.org
Wed Sep 2 10:08:13 PDT 2015


Revision: 15088
          http://trac.calendarserver.org//changeset/15088
Author:   cdaboo at apple.com
Date:     2015-09-02 10:08:13 -0700 (Wed, 02 Sep 2015)
Log Message:
-----------
Latest missing location fix logic.

Modified Paths:
--------------
    CalendarServer/branches/release/CalendarServer-5.4-dev/calendarserver/tools/calverify.py
    CalendarServer/branches/release/CalendarServer-5.4-dev/calendarserver/tools/test/calverify/resources.xml
    CalendarServer/branches/release/CalendarServer-5.4-dev/calendarserver/tools/test/test_calverify.py

Modified: CalendarServer/branches/release/CalendarServer-5.4-dev/calendarserver/tools/calverify.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-5.4-dev/calendarserver/tools/calverify.py	2015-09-02 17:06:55 UTC (rev 15087)
+++ CalendarServer/branches/release/CalendarServer-5.4-dev/calendarserver/tools/calverify.py	2015-09-02 17:08:13 UTC (rev 15088)
@@ -2830,6 +2830,7 @@
         details = []
         fixed = 0
         rjust = 10
+        cuaddr = "urn:uuid:{}".format(uuid)
         for resid in rows:
             resid = resid[1]
             caldata = yield self.getCalendar(resid, self.fix)
@@ -2847,18 +2848,26 @@
                 for comp in cal.subcomponents():
                     if comp.name() != "VEVENT":
                         continue
+
+                    # Look for matching location property
                     location = comp.propertyValue("LOCATION")
-                    if location is None:
+                    if location is not None:
+                        items = location.split(";")
+                        has_location = rname in items
+                    else:
+                        has_location = False
+
+                    # Look for matching attendee property
+                    has_attendee = cuaddr in comp.getAttendees()
+
+                    if not has_location and has_attendee:
                         fail = True
                         break
-                    else:
-                        # Test the actual location value matches this location name?
-                        pass
 
             if fail:
                 details.append(Details(resid, uid,))
                 if self.fix:
-                    yield self.fixCalendarData(cal, rname, resid)
+                    yield self.fixCalendarData(cal, rname, cuaddr, resid)
                     fixed += 1
 
             if self.options["verbose"] and not self.options["summary"]:
@@ -2907,7 +2916,7 @@
 
 
     @inlineCallbacks
-    def fixCalendarData(self, cal, rname, location_resid):
+    def fixCalendarData(self, cal, rname, cuaddr, location_resid):
         """
         Fix problems in calendar data using store APIs.
         """
@@ -2935,14 +2944,20 @@
         except InternalDataStoreError:
             returnValue((False, "Failed parse: "))
 
-        # Add missing location to all components (need to dup component when modifying)
+        # Fix each component (need to dup component when modifying)
         component = component.duplicate()
         for comp in component.subcomponents():
             if comp.name() != "VEVENT":
                 continue
             location = comp.propertyValue("LOCATION")
             if location is None:
+                # Just add the location name back in
                 comp.addProperty(Property("LOCATION", rname))
+            else:
+                # Remove the matching ATTENDEE property
+                attendee = comp.getAttendeeProperty((cuaddr,))
+                if attendee is not None:
+                    comp.removeProperty(attendee)
 
         # Write out fix, commit and get a new transaction
         try:

Modified: CalendarServer/branches/release/CalendarServer-5.4-dev/calendarserver/tools/test/calverify/resources.xml
===================================================================
--- CalendarServer/branches/release/CalendarServer-5.4-dev/calendarserver/tools/test/calverify/resources.xml	2015-09-02 17:06:55 UTC (rev 15087)
+++ CalendarServer/branches/release/CalendarServer-5.4-dev/calendarserver/tools/test/calverify/resources.xml	2015-09-02 17:08:13 UTC (rev 15088)
@@ -7,4 +7,10 @@
     <password>location01</password>
     <name>Room 01</name>
   </location>
+  <location>
+    <uid>location02</uid>
+    <guid>CDAF464F-9C77-4F56-A7A6-98E4ED9903D6</guid>
+    <password>location02</password>
+    <name>Room 02</name>
+  </location>
 </accounts>

Modified: CalendarServer/branches/release/CalendarServer-5.4-dev/calendarserver/tools/test/test_calverify.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-5.4-dev/calendarserver/tools/test/test_calverify.py	2015-09-02 17:06:55 UTC (rev 15087)
+++ CalendarServer/branches/release/CalendarServer-5.4-dev/calendarserver/tools/test/test_calverify.py	2015-09-02 17:08:13 UTC (rev 15088)
@@ -943,6 +943,7 @@
     uuid2 = "47B16BB4-DB5F-4BF6-85FE-A7DA54230F92"
     uuid3 = "AC478592-7783-44D1-B2AE-52359B4E8415"
     uuidl1 = "75EA36BE-F71B-40F9-81F9-CF59BF40CA8F"
+    uuidl2 = "CDAF464F-9C77-4F56-A7A6-98E4ED9903D6"
 
     def configure(self):
         super(CalVerifyMismatchTestsBase, self).configure()
@@ -3142,6 +3143,7 @@
         "uuid2": CalVerifyMismatchTestsBase.uuid2,
         "uuid3": CalVerifyMismatchTestsBase.uuid3,
         "uuidl1": CalVerifyMismatchTestsBase.uuidl1,
+        "uuidl2": CalVerifyMismatchTestsBase.uuidl2,
     }
 
     # Valid event
@@ -3162,11 +3164,35 @@
 ATTENDEE:urn:uuid:%(uuid1)s
 ATTENDEE:urn:uuid:%(uuid2)s
 ATTENDEE:urn:uuid:%(uuidl1)s
-LOCATION:Location 1
+LOCATION:Room 01
 END:VEVENT
 END:VCALENDAR
 """.replace("\n", "\r\n") % subs
 
+    # Valid event
+    VALID_MULTI_ICS = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//iCal 4.0.1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+CREATED:20100303T181216Z
+UID:VALID_MULTI_ICS
+TRANSP:OPAQUE
+SUMMARY:VALID_MULTI_ICS
+DTSTART:%(year)s%(month)02d08T100000Z
+DURATION:PT1H
+DTSTAMP:20100303T181220Z
+SEQUENCE:2
+ORGANIZER:urn:uuid:%(uuid1)s
+ATTENDEE:urn:uuid:%(uuid1)s
+ATTENDEE:urn:uuid:%(uuid2)s
+ATTENDEE:urn:uuid:%(uuidl1)s
+ATTENDEE:urn:uuid:%(uuidl2)s
+LOCATION:Room 01\\;Room 02
+END:VEVENT
+END:VCALENDAR
+""".replace("\n", "\r\n") % subs
+
     # Invalid event
     INVALID_ICS = """BEGIN:VCALENDAR
 VERSION:2.0
@@ -3189,6 +3215,30 @@
 END:VCALENDAR
 """.replace("\n", "\r\n") % subs
 
+    # Invalid event
+    INVALID_MULTI_ICS = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//iCal 4.0.1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+CREATED:20100303T181216Z
+UID:INVALID_MULTI_ICS
+TRANSP:OPAQUE
+SUMMARY:INVALID_MULTI_ICS
+DTSTART:%(year)s%(month)02d08T120000Z
+DURATION:PT1H
+DTSTAMP:20100303T181220Z
+SEQUENCE:2
+ORGANIZER:urn:uuid:%(uuid1)s
+ATTENDEE:urn:uuid:%(uuid1)s
+ATTENDEE:urn:uuid:%(uuid2)s
+ATTENDEE:urn:uuid:%(uuidl1)s
+ATTENDEE:urn:uuid:%(uuidl2)s
+LOCATION:Room 02
+END:VEVENT
+END:VCALENDAR
+""".replace("\n", "\r\n") % subs
+
     # Room as organizer event
     ROOM_ORGANIZER_ICS = """BEGIN:VCALENDAR
 VERSION:2.0
@@ -3252,14 +3302,22 @@
     allEvents = {
         "invite1.ics"      : (VALID_ICS, CalVerifyMismatchTestsBase.metadata,),
         "invite2.ics"      : (INVALID_ICS, CalVerifyMismatchTestsBase.metadata,),
+        "invite3.ics"      : (VALID_MULTI_ICS, CalVerifyMismatchTestsBase.metadata,),
+        "invite4.ics"      : (INVALID_MULTI_ICS, CalVerifyMismatchTestsBase.metadata,),
     }
-    allEvents_Room = {
+    allEvents_Room1 = {
         "invite1.ics"      : (VALID_ICS, CalVerifyMismatchTestsBase.metadata,),
         "invite2.ics"      : (INVALID_ICS, CalVerifyMismatchTestsBase.metadata,),
-        "invite3.ics"      : (ROOM_ORGANIZER_ICS, CalVerifyMismatchTestsBase.metadata,),
-        "invite4.ics"      : (ROOM_NO_ORGANIZER_ICS, CalVerifyMismatchTestsBase.metadata,),
-        "invite5.ics"      : (ROOM_MISSING_ORGANIZER_ICS, CalVerifyMismatchTestsBase.metadata,),
+        "invite3.ics"      : (VALID_MULTI_ICS, CalVerifyMismatchTestsBase.metadata,),
+        "invite4.ics"      : (INVALID_MULTI_ICS, CalVerifyMismatchTestsBase.metadata,),
+        "invite5.ics"      : (ROOM_ORGANIZER_ICS, CalVerifyMismatchTestsBase.metadata,),
+        "invite6.ics"      : (ROOM_NO_ORGANIZER_ICS, CalVerifyMismatchTestsBase.metadata,),
+        "invite7.ics"      : (ROOM_MISSING_ORGANIZER_ICS, CalVerifyMismatchTestsBase.metadata,),
     }
+    allEvents_Room2 = {
+        "invite3.ics"      : (VALID_MULTI_ICS, CalVerifyMismatchTestsBase.metadata,),
+        "invite4.ics"      : (INVALID_MULTI_ICS, CalVerifyMismatchTestsBase.metadata,),
+    }
 
     requirements = {
         CalVerifyMismatchTestsBase.uuid1 : {
@@ -3275,11 +3333,17 @@
             "inbox" : {},
         },
         CalVerifyMismatchTestsBase.uuidl1 : {
-            "calendar" : allEvents_Room,
+            "calendar" : allEvents_Room1,
             "inbox" : {},
         },
+        CalVerifyMismatchTestsBase.uuidl2 : {
+            "calendar" : allEvents_Room2,
+            "inbox" : {},
+        },
     }
 
+    badEvents = set(("INVALID_ICS", "INVALID_MULTI_ICS", "ROOM_MISSING_ORGANIZER_ICS", "ROOM_ORGANIZER_ICS",))
+
     @inlineCallbacks
     def test_scanMissingLocations(self):
         """
@@ -3317,10 +3381,10 @@
 
         self.assertEqual(calverify.results["Number of events to process"], len(self.requirements[CalVerifyMismatchTestsBase.uuidl1]["calendar"]))
         self.assertEqual(
-            sorted([i.uid for i in calverify.results["Bad Events"]]),
-            ["INVALID_ICS", "ROOM_MISSING_ORGANIZER_ICS", "ROOM_ORGANIZER_ICS", ]
+            set([i.uid for i in calverify.results["Bad Events"]]),
+            self.badEvents,
         )
-        self.assertEqual(calverify.results["Number of bad events"], 3)
+        self.assertEqual(calverify.results["Number of bad events"], len(self.badEvents))
         self.assertTrue("Fix bad events" not in calverify.results)
 
         sync_token_newl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, name="calendar")).syncToken())
@@ -3373,11 +3437,11 @@
 
         self.assertEqual(calverify.results["Number of events to process"], len(self.requirements[CalVerifyMismatchTestsBase.uuidl1]["calendar"]))
         self.assertEqual(
-            sorted([i.uid for i in calverify.results["Bad Events"]]),
-            ["INVALID_ICS", "ROOM_MISSING_ORGANIZER_ICS", "ROOM_ORGANIZER_ICS", ]
+            set([i.uid for i in calverify.results["Bad Events"]]),
+            self.badEvents,
         )
-        self.assertEqual(calverify.results["Number of bad events"], 3)
-        self.assertEqual(calverify.results["Fix bad events"], 3)
+        self.assertEqual(calverify.results["Number of bad events"], len(self.badEvents))
+        self.assertEqual(calverify.results["Fix bad events"], len(self.badEvents))
 
         sync_token_newl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, name="calendar")).syncToken())
         self.assertNotEqual(sync_token_oldl1, sync_token_newl1)
@@ -3399,7 +3463,7 @@
         calverify = MissingLocationService(self._sqlCalendarStore, options, output, reactor, config)
         yield calverify.doAction()
 
-        self.assertEqual(calverify.results["Number of events to process"], len(self.requirements[CalVerifyMismatchTestsBase.uuidl1]["calendar"]) - 1)
+        self.assertEqual(calverify.results["Number of events to process"], len(self.requirements[CalVerifyMismatchTestsBase.uuidl1]["calendar"]) - 2)
         self.assertEqual(len(calverify.results["Bad Events"]), 0)
         self.assertTrue("Fix bad events" not in calverify.results)
 
@@ -3409,15 +3473,27 @@
             caldata = yield calobj.componentForUser()
             self.assertTrue("LOCATION:" in str(caldata))
 
-        calobj = yield self.calendarObjectUnderTest(home=uid, calendar_name="calendar", name="invite3.ics")
+        calobj = yield self.calendarObjectUnderTest(home=self.uuidl1, calendar_name="calendar", name="invite3.ics")
+        self.assertTrue(calobj is not None)
+
+        calobj = yield self.calendarObjectUnderTest(home=self.uuidl2, calendar_name="calendar", name="invite3.ics")
+        self.assertTrue(calobj is not None)
+
+        calobj = yield self.calendarObjectUnderTest(home=self.uuidl1, calendar_name="calendar", name="invite4.ics")
+        self.assertTrue(calobj is None)
+
+        calobj = yield self.calendarObjectUnderTest(home=self.uuidl2, calendar_name="calendar", name="invite4.ics")
+        self.assertTrue(calobj is not None)
+
+        calobj = yield self.calendarObjectUnderTest(home=self.uuidl1, calendar_name="calendar", name="invite5.ics")
         caldata = yield calobj.componentForUser()
         self.assertTrue("LOCATION:" in str(caldata))
 
-        calobj = yield self.calendarObjectUnderTest(home=uid, calendar_name="calendar", name="invite4.ics")
+        calobj = yield self.calendarObjectUnderTest(home=self.uuidl1, calendar_name="calendar", name="invite6.ics")
         caldata = yield calobj.componentForUser()
         self.assertTrue("LOCATION:" not in str(caldata))
 
-        calobj = yield self.calendarObjectUnderTest(home=uid, calendar_name="calendar", name="invite5.ics")
+        calobj = yield self.calendarObjectUnderTest(home=self.uuidl1, calendar_name="calendar", name="invite7.ics")
         self.assertTrue(calobj is None)
 
         yield self.commit()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150902/4e14ea5a/attachment-0001.html>


More information about the calendarserver-changes mailing list