[CalendarServer-changes] [8416] CalendarServer/trunk/txdav/caldav/datastore

source_changes at macosforge.org source_changes at macosforge.org
Thu Dec 8 07:48:47 PST 2011


Revision: 8416
          http://trac.macosforge.org/projects/calendarserver/changeset/8416
Author:   cdaboo at apple.com
Date:     2011-12-08 07:48:47 -0800 (Thu, 08 Dec 2011)
Log Message:
-----------
Make sure calendars get split when migrating.

Modified Paths:
--------------
    CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py
    CalendarServer/trunk/txdav/caldav/datastore/util.py

Modified: CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py	2011-12-08 04:08:38 UTC (rev 8415)
+++ CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py	2011-12-08 15:48:47 UTC (rev 8416)
@@ -40,7 +40,7 @@
 from txdav.common.datastore.test.util import buildStore, populateCalendarsFrom
 
 from twistedcaldav import caldavxml
-
+from twistedcaldav.config import config
 from twistedcaldav.dateops import datetimeMktime
 from twistedcaldav.query import calendarqueryfilter
 from twistedcaldav.sharing import SharedCollectionRecord
@@ -228,6 +228,10 @@
         backend to another; in this specific case, from the file-based backend
         to the SQL-based backend.
         """
+        
+        # Need to turn of split calendar behavior just for this test
+        self.patch(config, "RestrictCalendarsToOneComponentType", False)
+
         fromHome = yield self.fileTransaction().calendarHomeWithUID("home1")
 
         builtinProperties = [PropertyName.fromElement(ResourceType)]
@@ -257,6 +261,60 @@
         self.assertPropertiesSimilar(fromHome, toHome, builtinProperties)
 
 
+    @inlineCallbacks
+    def test_migrateHomeSplits(self):
+        """
+        Make sure L{migrateHome} also splits calendars by component type.
+        """
+        fromHome = yield self.fileTransaction().calendarHomeWithUID("home_splits")
+        toHome = yield self.transactionUnderTest().calendarHomeWithUID(
+            "new-home", create=True
+        )
+        yield migrateHome(fromHome, toHome, lambda x: x.component())
+        toCalendars = yield toHome.calendars()
+        fromCalendars = yield fromHome.calendars()
+        for c in fromCalendars:
+            self.assertTrue(
+                (yield toHome.calendarWithName(c.name())) is not None
+            )
+
+        supported_components = set()
+        self.assertEqual(len(toCalendars), 3)
+        for calendar in toCalendars:
+            if calendar.name() == "inbox":
+                continue
+            result = yield calendar.getSupportedComponents()
+            supported_components.add(result)
+            
+        self.assertEqual(supported_components, set(("VEVENT", "VTODO",)))
+
+    @inlineCallbacks
+    def test_migrateHomeNoSplits(self):
+        """
+        Make sure L{migrateHome} also splits calendars by component type.
+        """
+        fromHome = yield self.fileTransaction().calendarHomeWithUID("home_no_splits")
+        toHome = yield self.transactionUnderTest().calendarHomeWithUID(
+            "new-home", create=True
+        )
+        yield migrateHome(fromHome, toHome, lambda x: x.component())
+        toCalendars = yield toHome.calendars()
+        fromCalendars = yield fromHome.calendars()
+        for c in fromCalendars:
+            self.assertTrue(
+                (yield toHome.calendarWithName(c.name())) is not None
+            )
+
+        supported_components = set()
+        self.assertEqual(len(toCalendars), 2)
+        for calendar in toCalendars:
+            if calendar.name() == "inbox":
+                continue
+            result = yield calendar.getSupportedComponents()
+            supported_components.add(result)
+            
+        self.assertEqual(supported_components, set(("VEVENT", "VTODO",)))
+
     def test_calendarHomeVersion(self):
         """
         The DATAVERSION column for new calendar homes must match the

Modified: CalendarServer/trunk/txdav/caldav/datastore/util.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/util.py	2011-12-08 04:08:38 UTC (rev 8415)
+++ CalendarServer/trunk/txdav/caldav/datastore/util.py	2011-12-08 15:48:47 UTC (rev 8416)
@@ -297,6 +297,9 @@
     # No migration for notifications, since they weren't present in earlier
     # released versions of CalendarServer.
 
+    # May need to split calendars by component type
+    if config.RestrictCalendarsToOneComponentType:
+        yield outHome.splitCalendars()
 
 class CalendarObjectBase(object):
     """
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20111208/c4b7add5/attachment.html>


More information about the calendarserver-changes mailing list