[CalendarServer-changes] [9914] CalendarServer/branches/release/CalendarServer-4.2-dev/txdav/caldav/ datastore
source_changes at macosforge.org
source_changes at macosforge.org
Tue Oct 9 14:33:10 PDT 2012
Revision: 9914
http://trac.calendarserver.org//changeset/9914
Author: cdaboo at apple.com
Date: 2012-10-09 14:33:10 -0700 (Tue, 09 Oct 2012)
Log Message:
-----------
Fix upgrade split of shared calendars.
Modified Paths:
--------------
CalendarServer/branches/release/CalendarServer-4.2-dev/txdav/caldav/datastore/sql.py
CalendarServer/branches/release/CalendarServer-4.2-dev/txdav/caldav/datastore/test/test_sql.py
Modified: CalendarServer/branches/release/CalendarServer-4.2-dev/txdav/caldav/datastore/sql.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-4.2-dev/txdav/caldav/datastore/sql.py 2012-10-09 20:22:58 UTC (rev 9913)
+++ CalendarServer/branches/release/CalendarServer-4.2-dev/txdav/caldav/datastore/sql.py 2012-10-09 21:33:10 UTC (rev 9914)
@@ -641,15 +641,20 @@
"""
cb = self._bindSchema
- columns = [ColumnSyntax(item) for item in self._bindSchema.model.columns]
- _bindQuery = Select(
+ inv = schema.INVITE
+ bindcolumns = [ColumnSyntax(item) for item in cb.model.columns]
+ invitecolumns = [ColumnSyntax(item) for item in inv.model.columns]
+ columns = bindcolumns + invitecolumns
+ _bindInviteQuery = Select(
columns,
- From=cb,
+ From=cb.join(inv),
Where=(cb.CALENDAR_RESOURCE_ID == Parameter('calID')).And(
- cb.CALENDAR_HOME_RESOURCE_ID != Parameter('homeID'))
+ cb.CALENDAR_HOME_RESOURCE_ID != Parameter('homeID')).And(
+ cb.CALENDAR_RESOURCE_ID == inv.RESOURCE_ID).And(
+ cb.CALENDAR_HOME_RESOURCE_ID == inv.HOME_RESOURCE_ID)
)
- rows = yield _bindQuery.on(
+ rows = yield _bindInviteQuery.on(
self._txn,
calID=self._resourceID,
homeID=self._home._resourceID,
@@ -659,11 +664,16 @@
returnValue(None)
for row in rows:
- columnMap = dict(zip(columns, row))
+ columnMap = dict(zip(bindcolumns, row[:len(bindcolumns)]))
columnMap[cb.CALENDAR_RESOURCE_ID] = newcalendar._resourceID
columnMap[cb.CALENDAR_RESOURCE_NAME] = "%s-%s" % (columnMap[cb.CALENDAR_RESOURCE_NAME], component.lower(),)
yield Insert(columnMap).on(self._txn)
+ columnMap = dict(zip(invitecolumns, row[len(bindcolumns):]))
+ columnMap[inv.INVITE_UID] = "%s-%s" % (columnMap[inv.INVITE_UID], component.lower(),)
+ columnMap[inv.RESOURCE_ID] = newcalendar._resourceID
+ yield Insert(columnMap).on(self._txn)
+
@inlineCallbacks
def _transferCalendarObjects(self, newcalendar, component):
"""
Modified: CalendarServer/branches/release/CalendarServer-4.2-dev/txdav/caldav/datastore/test/test_sql.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-4.2-dev/txdav/caldav/datastore/test/test_sql.py 2012-10-09 20:22:58 UTC (rev 9913)
+++ CalendarServer/branches/release/CalendarServer-4.2-dev/txdav/caldav/datastore/test/test_sql.py 2012-10-09 21:33:10 UTC (rev 9914)
@@ -30,14 +30,15 @@
from txdav.xml.rfc2518 import GETContentLanguage, ResourceType
from txdav.base.propertystore.base import PropertyName
-from txdav.caldav.datastore.test.common import CommonTests as CalendarCommonTests,\
+from txdav.caldav.datastore.test.common import CommonTests as CalendarCommonTests, \
test_event_text
from txdav.caldav.datastore.test.test_file import setUpCalendarStore
from txdav.caldav.datastore.util import _migrateCalendar, migrateHome
from txdav.common.datastore.sql import ECALENDARTYPE, CommonObjectResource
-from txdav.common.datastore.sql_legacy import PostgresLegacyIndexEmulator
-from txdav.common.datastore.sql_tables import schema, _BIND_MODE_DIRECT,\
- _BIND_STATUS_ACCEPTED
+from txdav.common.datastore.sql_legacy import PostgresLegacyIndexEmulator, \
+ SQLLegacyCalendarInvites
+from txdav.common.datastore.sql_tables import schema, \
+ _BIND_STATUS_ACCEPTED, _BIND_MODE_WRITE
from txdav.common.datastore.test.util import buildStore, populateCalendarsFrom
from txdav.common.icommondatastore import NoSuchObjectResourceError
@@ -50,6 +51,7 @@
from twistedcaldav.sharing import SharedCollectionRecord
import datetime
+import uuid
from pycalendar.datetime import PyCalendarDateTime
from pycalendar.timezone import PyCalendarTimezone
@@ -186,7 +188,7 @@
backed calendar. We need to test what happens when there is "bad" calendar data
present in the file-backed calendar with a broken recurrence-id that we can fix.
"""
-
+
self.storeUnderTest().setMigrating(True)
fromCalendar = yield (yield self.fileTransaction().calendarHomeWithUID(
"home_bad")).calendarWithName("calendar_fix_recurrence")
@@ -307,7 +309,7 @@
END:VEVENT
END:VCALENDAR
""".replace("\n", "\r\n") % self.nowYear)
-
+
toResource = yield toCalendar.calendarObjectWithName("3.ics")
caldata = yield toResource.component()
self.assertEqual(str(caldata), """BEGIN:VCALENDAR
@@ -354,7 +356,7 @@
END:VEVENT
END:VCALENDAR
""".replace("\n", "\r\n") % self.nowYear)
-
+
@inlineCallbacks
def test_migrateDuplicateAttachmentsCalendarFromFile(self):
"""
@@ -386,10 +388,10 @@
yield _migrateCalendar(fromCalendar, toCalendar,
lambda x: x.component())
- filter = caldavxml.Filter(
+ filter = caldavxml.Filter(
caldavxml.ComponentFilter(
caldavxml.ComponentFilter(
- caldavxml.TimeRange(start="%(now)s0201T000000Z" % self.nowYear, end="%(now)s0202T000000Z" % self.nowYear),
+ caldavxml.TimeRange(start="%(now)s0201T000000Z" % self.nowYear, end="%(now)s0202T000000Z" % self.nowYear),
name=("VEVENT", "VFREEBUSY", "VAVAILABILITY"),
),
name="VCALENDAR",
@@ -411,7 +413,7 @@
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)
@@ -468,7 +470,7 @@
continue
result = yield calendar.getSupportedComponents()
supported_components.add(result)
-
+
self.assertEqual(supported_components, set(("VEVENT", "VTODO",)))
@inlineCallbacks
@@ -495,7 +497,7 @@
continue
result = yield calendar.getSupportedComponents()
supported_components.add(result)
-
+
self.assertEqual(supported_components, set(("VEVENT", "VTODO",)))
def test_calendarHomeVersion(self):
@@ -503,23 +505,23 @@
The DATAVERSION column for new calendar homes must match the
CALENDAR-DATAVERSION value.
"""
-
+
home = yield self.transactionUnderTest().calendarHomeWithUID("home_version")
self.assertTrue(home is not None)
yield self.transactionUnderTest().commit
-
+
txn = yield self.transactionUnderTest()
version = yield txn.calendarserverValue("CALENDAR-DATAVERSION")[0][0]
ch = schema.CALENDAR_HOME
homeVersion = yield Select(
- [ch.DATAVERSION,],
+ [ch.DATAVERSION, ],
From=ch,
Where=ch.OWNER_UID == "home_version",
).on(txn)[0][0]
self.assertEqual(int(homeVersion, version))
-
-
+
+
def test_eachCalendarHome(self):
"""
L{ICalendarStore.eachCalendarHome} is currently stubbed out by
@@ -780,7 +782,7 @@
calendar = yield home.createCalendarWithName(name)
resourceID = calendar._resourceID
calendarProperties = calendar.properties()
-
+
prop = caldavxml.CalendarDescription.fromString("Calendar to be removed")
calendarProperties[PropertyName.fromElement(prop)] = prop
yield self.commit()
@@ -863,7 +865,7 @@
# Create calendar object and add a property
home = yield self.homeUnderTest()
inbox = yield home.createCalendarWithName("inbox")
-
+
name = "test.ics"
component = VComponent.fromString(test_event_text)
metadata = {
@@ -959,25 +961,36 @@
"""
Test Calendar._transferSharingDetails to make sure sharing details are transferred.
"""
-
+
shareeHome = yield self.transactionUnderTest().calendarHomeWithUID("home_splits_shared")
calendar = yield (yield self.transactionUnderTest().calendarHomeWithUID(
"home_splits")).calendarWithName("calendar_1")
-
+
# Fake a shared binding on the original calendar
bind = calendar._bindSchema
_bindCreate = Insert({
bind.HOME_RESOURCE_ID: shareeHome._resourceID,
- bind.RESOURCE_ID: calendar._resourceID,
+ bind.RESOURCE_ID: calendar._resourceID,
bind.RESOURCE_NAME: "shared_1",
bind.MESSAGE: "Shared to you",
- bind.BIND_MODE: _BIND_MODE_DIRECT,
+ bind.BIND_MODE: _BIND_MODE_WRITE,
bind.BIND_STATUS: _BIND_STATUS_ACCEPTED,
bind.SEEN_BY_OWNER: True,
bind.SEEN_BY_SHAREE: True,
})
yield _bindCreate.on(self.transactionUnderTest())
+
+ inv = schema.INVITE
+ _inviteCreate = Insert({
+ inv.INVITE_UID: str(uuid.uuid4()),
+ inv.NAME: "Invite",
+ inv.RECIPIENT_ADDRESS: "sharee at example.com",
+ inv.HOME_RESOURCE_ID: shareeHome._resourceID,
+ inv.RESOURCE_ID: calendar._resourceID,
+ })
+ yield _inviteCreate.on(self.transactionUnderTest())
+
sharedCalendar = yield shareeHome.sharedChildWithName("shared_1")
self.assertTrue(sharedCalendar is not None)
sharedCalendar = yield shareeHome.sharedChildWithName("shared_1_vtodo")
@@ -996,24 +1009,28 @@
self.assertTrue(sharedCalendar is not None)
self.assertEqual(sharedCalendar._resourceID, newcalendar._resourceID)
+ invites = SQLLegacyCalendarInvites(newcalendar)
+ records = (yield invites.allRecords())
+ self.assertEqual(len(records), 1)
+
@inlineCallbacks
def test_moveCalendarObjectResource(self):
"""
Test Calendar._transferSharingDetails to make sure sharing details are transferred.
"""
-
+
calendar1 = yield (yield self.transactionUnderTest().calendarHomeWithUID(
"home_splits")).calendarWithName("calendar_1")
calendar2 = yield (yield self.transactionUnderTest().calendarHomeWithUID(
"home_splits")).calendarWithName("calendar_2")
-
+
child = yield calendar2.calendarObjectWithName("5.ics")
-
+
yield calendar2.moveObjectResource(child, calendar1)
-
+
child = yield calendar2.calendarObjectWithName("5.ics")
self.assertTrue(child is None)
-
+
child = yield calendar1.calendarObjectWithName("5.ics")
self.assertTrue(child is not None)
@@ -1023,7 +1040,7 @@
Test Calendar.splitCollectionByComponentTypes to make sure components are split out,
sync information is updated.
"""
-
+
# calendar_2 add a dead property to make sure it gets copied over
home = yield self.transactionUnderTest().calendarHomeWithUID("home_splits")
calendar2 = yield home.calendarWithName("calendar_2")
@@ -1043,7 +1060,7 @@
child = yield home.calendarWithName("calendar_1-vtodo")
self.assertTrue(child is None)
- calendar1 = yield home.calendarWithName("calendar_1")
+ calendar1 = yield home.calendarWithName("calendar_1")
children = yield calendar1.listCalendarObjects()
self.assertEqual(len(children), 3)
new_sync_token1 = yield calendar1.syncToken()
@@ -1055,7 +1072,7 @@
# calendar_2 does split
home = yield self.transactionUnderTest().calendarHomeWithUID("home_splits")
- calendar2 = yield home.calendarWithName("calendar_2")
+ calendar2 = yield home.calendarWithName("calendar_2")
original_sync_token2 = yield calendar2.syncToken()
yield calendar2.splitCollectionByComponentTypes()
yield self.commit()
@@ -1074,7 +1091,7 @@
self.assertTrue(pkey in calendar2_vtodo.properties())
self.assertEqual(str(calendar2_vtodo.properties()[pkey]), "A birthday calendar")
- calendar2 = yield home.calendarWithName("calendar_2")
+ calendar2 = yield home.calendarWithName("calendar_2")
children = yield calendar2.listCalendarObjects()
self.assertEqual(len(children), 3)
new_sync_token2 = yield calendar2.syncToken()
@@ -1093,7 +1110,7 @@
Test CalendarHome.splitCalendars to make sure we end up with at least two collections
with different supported components.
"""
-
+
# Do split
home = yield self.transactionUnderTest().calendarHomeWithUID("home_no_splits")
calendars = yield home.calendars()
@@ -1110,7 +1127,7 @@
continue
result = yield calendar.getSupportedComponents()
supported_components.add(result)
-
+
self.assertEqual(supported_components, set(("VEVENT", "VTODO",)))
@inlineCallbacks
@@ -1119,14 +1136,14 @@
Test CommonObjectResource.lock to make sure it locks, raises on missing resource,
and raises when locked and wait=False used.
"""
-
+
# Valid object
resource = yield self.calendarObjectUnderTest()
-
+
# Valid lock
yield resource.lock()
self.assertTrue(resource._locked)
-
+
# Setup a new transaction to verify the lock and also verify wait behavior
newTxn = self._sqlCalendarStore.newTransaction()
newResource = yield self.calendarObjectUnderTest(txn=newTxn)
@@ -1141,19 +1158,19 @@
# Commit existing transaction and verify we can get the lock using
yield self.commit()
-
+
resource = yield self.calendarObjectUnderTest()
yield resource.lock()
self.assertTrue(resource._locked)
-
+
# Setup a new transaction to verify the lock but pass in an alternative txn directly
newTxn = self._sqlCalendarStore.newTransaction()
-
+
# FIXME: not sure why, but without this statement here, this portion of the test fails in a funny way.
# Basically the query in the try block seems to execute twice, failing each time, one of which is caught,
# and the other not - causing the test to fail. Seems like some state on newTxn is not being initialized?
yield self.calendarObjectUnderTest("2.ics", txn=newTxn)
-
+
try:
yield resource.lock(wait=False, useTxn=newTxn)
except:
@@ -1181,10 +1198,10 @@
"""
Test CalendarObjectResource.recurrenceMinMax to make sure it handles a None value.
"""
-
+
# Valid object
resource = yield self.calendarObjectUnderTest()
-
+
# Valid lock
rMin, rMax = yield resource.recurrenceMinMax()
self.assertEqual(rMin, None)
@@ -1196,14 +1213,14 @@
Test PostgresLegacyIndexEmulator.notExpandedWithin to make sure it returns the correct
result based on the ranges passed in.
"""
-
+
self.patch(config, "FreeBusyIndexDelayedExpand", False)
# Create the index on a new calendar
home = yield self.homeUnderTest()
newcalendar = yield home.createCalendarWithName("index_testing")
index = PostgresLegacyIndexEmulator(newcalendar)
-
+
# Create the calendar object to use for testing
nowYear = self.nowYear["now"]
caldata = """BEGIN:VCALENDAR
@@ -1299,15 +1316,15 @@
instances = yield calendarObject.instances()
self.assertNotEqual(len(instances), 0)
yield self.commit()
-
+
# Re-add event with re-indexing
calendar = yield self.calendarUnderTest()
calendarObject = yield self.calendarObjectUnderTest("indexing.ics")
yield calendarObject.setComponent(component)
instances2 = yield calendarObject.instances()
self.assertNotEqual(
- sorted(instances, key=lambda x:x[0])[0],
- sorted(instances2, key=lambda x:x[0])[0],
+ sorted(instances, key=lambda x:x[0])[0],
+ sorted(instances2, key=lambda x:x[0])[0],
)
yield self.commit()
@@ -1318,10 +1335,10 @@
yield calendarObject.setComponent(component)
instances3 = yield calendarObject.instances()
self.assertEqual(
- sorted(instances2, key=lambda x:x[0])[0],
- sorted(instances3, key=lambda x:x[0])[0],
+ sorted(instances2, key=lambda x:x[0])[0],
+ sorted(instances3, key=lambda x:x[0])[0],
)
-
+
yield calendar.removeCalendarObjectWithName("indexing.ics")
yield self.commit()
@@ -1336,19 +1353,19 @@
def _tests(cal):
resources = yield cal.objectResourcesWithNames(("1.ics",))
self.assertEqual(set([resource.name() for resource in resources]), set(("1.ics",)))
-
+
resources = yield cal.objectResourcesWithNames(("1.ics", "2.ics",))
self.assertEqual(set([resource.name() for resource in resources]), set(("1.ics", "2.ics",)))
-
+
resources = yield cal.objectResourcesWithNames(("1.ics", "2.ics", "3.ics",))
self.assertEqual(set([resource.name() for resource in resources]), set(("1.ics", "2.ics", "3.ics",)))
-
+
resources = yield cal.objectResourcesWithNames(("1.ics", "2.ics", "3.ics", "4.ics",))
self.assertEqual(set([resource.name() for resource in resources]), set(("1.ics", "2.ics", "3.ics", "4.ics",)))
-
+
resources = yield cal.objectResourcesWithNames(("bogus1.ics",))
self.assertEqual(set([resource.name() for resource in resources]), set())
-
+
resources = yield cal.objectResourcesWithNames(("bogus1.ics", "2.ics",))
self.assertEqual(set([resource.name() for resource in resources]), set(("2.ics",)))
@@ -1359,7 +1376,7 @@
# Adjust batch size and try again
self.patch(CommonObjectResource, "BATCH_LOAD_SIZE", 2)
yield _tests(cal)
-
+
yield self.commit()
# Tests on inbox - resources with properties
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20121009/304b5369/attachment-0001.html>
More information about the calendarserver-changes
mailing list