[CalendarServer-changes] [6365] CalendarServer/branches/users/glyph/more-deferreds-6/txdav

source_changes at macosforge.org source_changes at macosforge.org
Thu Sep 23 19:27:44 PDT 2010


Revision: 6365
          http://trac.macosforge.org/projects/calendarserver/changeset/6365
Author:   glyph at apple.com
Date:     2010-09-23 19:27:43 -0700 (Thu, 23 Sep 2010)
Log Message:
-----------
every calendarHomeWithUID I could find in txdav

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/more-deferreds-6/txdav/caldav/datastore/scheduling.py
    CalendarServer/branches/users/glyph/more-deferreds-6/txdav/caldav/datastore/test/common.py
    CalendarServer/branches/users/glyph/more-deferreds-6/txdav/caldav/datastore/test/test_file.py
    CalendarServer/branches/users/glyph/more-deferreds-6/txdav/caldav/icalendarstore.py
    CalendarServer/branches/users/glyph/more-deferreds-6/txdav/common/datastore/test/test_util.py

Modified: CalendarServer/branches/users/glyph/more-deferreds-6/txdav/caldav/datastore/scheduling.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-6/txdav/caldav/datastore/scheduling.py	2010-09-24 02:07:32 UTC (rev 6364)
+++ CalendarServer/branches/users/glyph/more-deferreds-6/txdav/caldav/datastore/scheduling.py	2010-09-24 02:27:43 UTC (rev 6365)
@@ -40,16 +40,17 @@
         self._transaction = transaction
 
 
+    @inlineCallbacks
     def calendarHomeWithUID(self, uid, create=False):
         # FIXME: 'create' flag
-        newHome = super(ImplicitTransaction, self
+        newHome = yield super(ImplicitTransaction, self
             ).calendarHomeWithUID(uid, create)
 #        return ImplicitCalendarHome(newHome, self)
         if newHome is None:
-            return None
+            returnValue(None)
         else:
             # FIXME: relay transaction
-            return ImplicitCalendarHome(newHome, None)
+            returnValue(ImplicitCalendarHome(newHome, None))
 
 
 

Modified: CalendarServer/branches/users/glyph/more-deferreds-6/txdav/caldav/datastore/test/common.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-6/txdav/caldav/datastore/test/common.py	2010-09-24 02:07:32 UTC (rev 6364)
+++ CalendarServer/branches/users/glyph/more-deferreds-6/txdav/caldav/datastore/test/common.py	2010-09-24 02:27:43 UTC (rev 6365)
@@ -332,13 +332,14 @@
         self.assertProvides(ICalendarHome, calendarHome)
 
 
+    @inlineCallbacks
     def test_calendarHomeWithUID_absent(self):
         """
         L{ICommonStoreTransaction.calendarHomeWithUID} should return C{None}
         when asked for a non-existent calendar home.
         """
         txn = self.transactionUnderTest()
-        self.assertEquals(txn.calendarHomeWithUID("xyzzy"), None)
+        self.assertEquals((yield txn.calendarHomeWithUID("xyzzy")), None)
 
 
     @inlineCallbacks
@@ -1214,7 +1215,9 @@
         additionalUIDs = set('alpha-uid home2 home3 beta-uid'.split())
         txn = self.transactionUnderTest()
         for name in additionalUIDs:
-            txn.calendarHomeWithUID(name, create=True)
+            # maybe it's not actually necessary to yield (i.e. wait) for each
+            # one?  commit() should wait for all of them.
+            yield txn.calendarHomeWithUID(name, create=True)
         yield self.commit()
         foundUIDs = set([])
         lastTxn = None

Modified: CalendarServer/branches/users/glyph/more-deferreds-6/txdav/caldav/datastore/test/test_file.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-6/txdav/caldav/datastore/test/test_file.py	2010-09-24 02:07:32 UTC (rev 6364)
+++ CalendarServer/branches/users/glyph/more-deferreds-6/txdav/caldav/datastore/test/test_file.py	2010-09-24 02:27:43 UTC (rev 6365)
@@ -70,16 +70,17 @@
 
 
 
+ at inlineCallbacks
 def setUpHome1(test):
     setUpCalendarStore(test)
-    test.home1 = test.txn.calendarHomeWithUID("home1")
+    test.home1 = yield test.txn.calendarHomeWithUID("home1")
     assert test.home1 is not None, "No calendar home?"
 
 
-
+ at inlineCallbacks
 def setUpCalendar1(test):
-    setUpHome1(test)
-    test.calendar1 = test.home1.calendarWithName("calendar_1")
+    yield setUpHome1(test)
+    test.calendar1 = yield test.home1.calendarWithName("calendar_1")
     assert test.calendar1 is not None, "No calendar?"
 
 
@@ -111,7 +112,7 @@
 
     notifierFactory = None
     def setUp(self):
-        setUpHome1(self)
+        return setUpHome1(self)
 
 
     def test_init(self):
@@ -169,7 +170,7 @@
     notifierFactory = None
 
     def setUp(self):
-        setUpCalendar1(self)
+        return setUpCalendar1(self)
 
 
     def test_init(self):
@@ -187,27 +188,28 @@
         )
 
 
+    @inlineCallbacks
     def test_useIndexImmediately(self):
         """
         L{Calendar._index} is usable in the same transaction it is created, with
         a temporary filename.
         """
         self.home1.createCalendarWithName("calendar2")
-        calendar = self.home1.calendarWithName("calendar2")
+        calendar = yield self.home1.calendarWithName("calendar2")
         index = calendar._index
-        self.assertEquals(set(index.calendarObjects()),
-                          set(calendar.calendarObjects()))
-        self.txn.commit()
+        yield self.assertEquals(set(index.calendarObjects()),
+                                set(calendar.calendarObjects()))
+        yield self.txn.commit()
         self.txn = self.calendarStore.newTransaction()
-        self.home1 = self.txn.calendarHomeWithUID("home1")
-        calendar = self.home1.calendarWithName("calendar2")
+        self.home1 = yield self.txn.calendarHomeWithUID("home1")
+        calendar = yield self.home1.calendarWithName("calendar2")
         # FIXME: we should be curating our own index here, but in order to fix
         # that the code in the old implicit scheduler needs to change.  This
         # test would be more effective if there were actually some objects in
         # this list.
         index = calendar._index
-        self.assertEquals(set(index.calendarObjects()),
-                          set(calendar.calendarObjects()))
+        self.assertEquals(set((yield index.calendarObjects())),
+                          set((yield calendar.calendarObjects())))
 
 
     def test_calendarObjectWithName_dot(self):
@@ -266,6 +268,7 @@
         )
 
 
+    @inlineCallbacks
     def test_removeCalendarObject_delayedEffect(self):
         """
         Removing a calendar object should not immediately remove the underlying
@@ -273,7 +276,7 @@
         """
         self.calendar1.removeCalendarObjectWithName("2.ics")
         self.failUnless(self.calendar1._path.child("2.ics").exists())
-        self.txn.commit()
+        yield self.txn.commit()
         self.failIf(self.calendar1._path.child("2.ics").exists())
 
 
@@ -292,6 +295,7 @@
 
 
     counter = 0
+    @inlineCallbacks
     def _refresh(self):
         """
         Re-read the (committed) home1 and calendar1 objects in a new
@@ -301,10 +305,11 @@
         self.txn = self.calendarStore.newTransaction(
             self.id() + " (old #" + str(self.counter) + ")"
         )
-        self.home1 = self.txn.calendarHomeWithUID("home1")
-        self.calendar1 = self.home1.calendarWithName("calendar_1")
+        self.home1 = yield self.txn.calendarHomeWithUID("home1")
+        self.calendar1 = yield self.home1.calendarWithName("calendar_1")
 
 
+    @inlineCallbacks
     def test_undoCreateCalendarObject(self):
         """
         If a calendar object is created as part of a transaction, it will be
@@ -312,21 +317,22 @@
         """
         # Make sure that the calendar home is actually committed; rolling back
         # calendar home creation will remove the whole directory.
-        self.txn.commit()
-        self._refresh()
+        yield self.txn.commit()
+        yield self._refresh()
         self.calendar1.createCalendarObjectWithName(
             "sample.ics",
             VComponent.fromString(event4_text)
         )
-        self.txn.abort()
-        self._refresh()
+        yield self.txn.abort()
+        yield self._refresh()
         self.assertIdentical(
-            self.calendar1.calendarObjectWithName("sample.ics"),
+            (yield self.calendar1.calendarObjectWithName("sample.ics")),
             None
         )
-        self.txn.commit()
+        yield self.txn.commit()
 
 
+    @inlineCallbacks
     def doThenUndo(self):
         """
         Commit the current transaction, but add an operation that will cause it
@@ -338,31 +344,33 @@
             raise RuntimeError("oops")
         self.txn.addOperation(fail, "dummy failing operation")
         self.assertRaises(RuntimeError, self.txn.commit)
-        self._refresh()
+        yield self._refresh()
 
 
+    @inlineCallbacks
     def test_undoModifyCalendarObject(self):
         """
         If an existing calendar object is modified as part of a transaction, it
         should be restored to its previous status if the transaction aborts.
         """
-        originalComponent = self.calendar1.calendarObjectWithName(
+        originalComponent = yield self.calendar1.calendarObjectWithName(
             "1.ics").component()
-        self.calendar1.calendarObjectWithName("1.ics").setComponent(
+        (yield self.calendar1.calendarObjectWithName("1.ics")).setComponent(
             VComponent.fromString(event1modified_text)
         )
         # Sanity check.
         self.assertEquals(
-            self.calendar1.calendarObjectWithName("1.ics").component(),
+            (yield self.calendar1.calendarObjectWithName("1.ics")).component(),
             VComponent.fromString(event1modified_text)
         )
-        self.doThenUndo()
+        yield self.doThenUndo()
         self.assertEquals(
-            self.calendar1.calendarObjectWithName("1.ics").component(),
+            (yield self.calendar1.calendarObjectWithName("1.ics")).component(),
             originalComponent
         )
 
 
+    @inlineCallbacks
     def test_modifyCalendarObjectCaches(self):
         """
         Modifying a calendar object should cache the modified component in
@@ -375,7 +383,7 @@
         )
         self.assertIdentical(
             modifiedComponent,
-            self.calendar1.calendarObjectWithName("1.ics").component()
+            (yield self.calendar1.calendarObjectWithName("1.ics")).component()
         )
 
 
@@ -419,9 +427,10 @@
 class CalendarObjectTest(unittest.TestCase):
     notifierFactory = None
 
+    @inlineCallbacks
     def setUp(self):
-        setUpCalendar1(self)
-        self.object1 = self.calendar1.calendarObjectWithName("1.ics")
+        yield setUpCalendar1(self)
+        self.object1 = yield self.calendar1.calendarObjectWithName("1.ics")
 
 
     def test_init(self):

Modified: CalendarServer/branches/users/glyph/more-deferreds-6/txdav/caldav/icalendarstore.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-6/txdav/caldav/icalendarstore.py	2010-09-24 02:07:32 UTC (rev 6364)
+++ CalendarServer/branches/users/glyph/more-deferreds-6/txdav/caldav/icalendarstore.py	2010-09-24 02:27:43 UTC (rev 6365)
@@ -57,8 +57,8 @@
         If C{create} is C{True}, create the calendar home if it doesn't
         already exist.
 
-        @return: an L{ICalendarHome} or C{None} if no such calendar
-            home exists.
+        @return: a L{Deferred} which fires with L{ICalendarHome} or C{None} if
+            no such calendar home exists.
         """
 
 

Modified: CalendarServer/branches/users/glyph/more-deferreds-6/txdav/common/datastore/test/test_util.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-6/txdav/common/datastore/test/test_util.py	2010-09-24 02:07:32 UTC (rev 6364)
+++ CalendarServer/branches/users/glyph/more-deferreds-6/txdav/common/datastore/test/test_util.py	2010-09-24 02:27:43 UTC (rev 6365)
@@ -82,7 +82,7 @@
         self.addCleanup(txn.commit)
         for uid in CommonTests.requirements:
             if CommonTests.requirements[uid] is not None:
-                self.assertNotIdentical(None, txn.calendarHomeWithUID(uid))
+                self.assertNotIdentical(None, (yield txn.calendarHomeWithUID(uid)))
         # Un-migrated data should be preserved.
         self.assertEquals(self.filesPath.child("calendars-migrated").child(
             "__uids__").child("ho").child("me").child("home1").child(
@@ -98,13 +98,13 @@
         homes.
         """
         startTxn = self.sqlStore.newTransaction("populate empty sample")
-        startTxn.calendarHomeWithUID("home1", create=True)
+        yield startTxn.calendarHomeWithUID("home1", create=True)
         yield startTxn.commit()
         self.topService.startService()
         yield self.subStarted
         vrfyTxn = self.sqlStore.newTransaction("verify sample still empty")
         self.addCleanup(vrfyTxn.commit)
-        home = vrfyTxn.calendarHomeWithUID("home1")
+        home = yield vrfyTxn.calendarHomeWithUID("home1")
         # The default calendar is still there.
         self.assertNotIdentical(None, (yield home.calendarWithName("calendar")))
         # The migrated calendar isn't.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100923/6c5b532b/attachment-0001.html>


More information about the calendarserver-changes mailing list