[CalendarServer-changes] [15009] CalendarServer/trunk/txdav/common/datastore

source_changes at macosforge.org source_changes at macosforge.org
Mon Jul 27 18:16:55 PDT 2015


Revision: 15009
          http://trac.calendarserver.org//changeset/15009
Author:   sagen at apple.com
Date:     2015-07-27 18:16:55 -0700 (Mon, 27 Jul 2015)
Log Message:
-----------
Use Record API for the imip token upgrade test

Modified Paths:
--------------
    CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_56_to_57.sql
    CalendarServer/trunk/txdav/common/datastore/upgrade/sql/test/test_upgrade_with_data.py

Modified: CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_56_to_57.sql
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_56_to_57.sql	2015-07-28 01:01:05 UTC (rev 15008)
+++ CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_56_to_57.sql	2015-07-28 01:16:55 UTC (rev 15009)
@@ -18,7 +18,10 @@
 -- Upgrade database schema from VERSION 56 to 57 --
 ---------------------------------------------------
 
+-- pre-delete any that would conflict during the update
 delete from IMIP_TOKENS where (ORGANIZER, ATTENDEE, ICALUID) in (select concat('urn:uuid:', substr(ORGANIZER, 11)), ATTENDEE, ICALUID from IMIP_TOKENS where substr(ORGANIZER, 1, 10) = 'urn:x-uid:');
+
+-- convert the old-style urn:uuid: CUAs to new style urn:x-uid:
 update IMIP_TOKENS set ORGANIZER = concat('urn:x-uid:', substr(ORGANIZER, 10)) where substr(ORGANIZER, 1, 9) = 'urn:uuid:';
 
 -- update the version

Modified: CalendarServer/trunk/txdav/common/datastore/upgrade/sql/test/test_upgrade_with_data.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/upgrade/sql/test/test_upgrade_with_data.py	2015-07-28 01:01:05 UTC (rev 15008)
+++ CalendarServer/trunk/txdav/common/datastore/upgrade/sql/test/test_upgrade_with_data.py	2015-07-28 01:16:55 UTC (rev 15009)
@@ -25,6 +25,7 @@
 from twisted.internet.defer import inlineCallbacks, returnValue
 from twisted.trial.unittest import TestCase
 
+from txdav.caldav.datastore.scheduling.imip.token import iMIPTokenRecord
 from txdav.caldav.datastore.scheduling.work import ScheduleReplyWork, \
     ScheduleWork
 from txdav.common.datastore.sql_tables import _populateSchema
@@ -305,38 +306,37 @@
         """
         Old-style canonical CUAs (urn:uuid:) are converted to new style (urn:x-uid:)
         """
-        schema = yield self._loadOldSchema(self.upgradePath.child("v56.sql"))
 
-        txn = self.store.newTransaction("loadData")
+        # Load old schema and populate with data
+        yield self._loadOldSchema(self.upgradePath.child("v56.sql"))
 
         # Add two tokens records crafted to simulate conflicting old-style and
         # new style CUAs -- the result should be only the new-style copy.
-        yield Insert(
-            {
-                schema.IMIP_TOKENS.TOKEN: "123",
-                schema.IMIP_TOKENS.ORGANIZER: "urn:uuid:PLUGH",
-                schema.IMIP_TOKENS.ATTENDEE: "mailto:user at example.com",
-                schema.IMIP_TOKENS.ICALUID: "XYZZY",
-            }
-        ).on(txn)
-        yield Insert(
-            {
-                schema.IMIP_TOKENS.TOKEN: "456",
-                schema.IMIP_TOKENS.ORGANIZER: "urn:x-uid:PLUGH",
-                schema.IMIP_TOKENS.ATTENDEE: "mailto:user at example.com",
-                schema.IMIP_TOKENS.ICALUID: "XYZZY",
-            }
-        ).on(txn)
+        txn = self.store.newTransaction("loadData")
+        yield iMIPTokenRecord.create(
+            txn,
+            token="123",
+            organizer="urn:uuid:PLUGH",
+            attendee="mailto:user at example.com",
+            icaluid="XYZZY"
+        )
+        yield iMIPTokenRecord.create(
+            txn,
+            token="456",
+            organizer="urn:x-uid:PLUGH",
+            attendee="mailto:user at example.com",
+            icaluid="XYZZY"
+        )
+        yield txn.commit()
 
-        yield txn.commit()
         upgrader = UpgradeDatabaseSchemaStep(self.store)
         yield upgrader.databaseUpgrade()
 
         txn = self.store.newTransaction("loadData")
-        tokens = yield Select(
-            From=schema.IMIP_TOKENS,
-        ).on(txn)
+        tokens = yield iMIPTokenRecord.all(txn)
 
         self.assertEqual(len(tokens), 1)
-        self.assertEqual(list(tokens[0])[1], "urn:x-uid:PLUGH")
+        token = list(tokens)[0]
+        self.assertEqual(token.token, "456")
+        self.assertEqual(token.organizer, "urn:x-uid:PLUGH")
         yield txn.commit()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150727/e53980a1/attachment.html>


More information about the calendarserver-changes mailing list