[CalendarServer-changes] [6368] CalendarServer/branches/users/glyph/more-deferreds-6/txdav
source_changes at macosforge.org
source_changes at macosforge.org
Thu Sep 23 20:01:16 PDT 2010
Revision: 6368
http://trac.macosforge.org/projects/calendarserver/changeset/6368
Author: glyph at apple.com
Date: 2010-09-23 20:01:13 -0700 (Thu, 23 Sep 2010)
Log Message:
-----------
everything that calls addressbookHomeWithUID, I think.
Modified Paths:
--------------
CalendarServer/branches/users/glyph/more-deferreds-6/txdav/carddav/datastore/test/common.py
CalendarServer/branches/users/glyph/more-deferreds-6/txdav/carddav/datastore/test/test_file.py
CalendarServer/branches/users/glyph/more-deferreds-6/txdav/carddav/datastore/test/test_sql.py
CalendarServer/branches/users/glyph/more-deferreds-6/txdav/carddav/iaddressbookstore.py
CalendarServer/branches/users/glyph/more-deferreds-6/txdav/common/datastore/util.py
Modified: CalendarServer/branches/users/glyph/more-deferreds-6/txdav/carddav/datastore/test/common.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-6/txdav/carddav/datastore/test/common.py 2010-09-24 02:29:35 UTC (rev 6367)
+++ CalendarServer/branches/users/glyph/more-deferreds-6/txdav/carddav/datastore/test/common.py 2010-09-24 03:01:13 UTC (rev 6368)
@@ -214,25 +214,27 @@
self.assertEquals(addressbook.notifierID(label="collection"), "CardDAV|home1/addressbook_1")
+ @inlineCallbacks
def test_addressbookHomeWithUID_exists(self):
"""
Finding an existing addressbook home by UID results in an object that
provides L{IAddressBookHome} and has a C{uid()} method that returns the
same value that was passed in.
"""
- addressbookHome = (self.transactionUnderTest()
- .addressbookHomeWithUID("home1"))
+ addressbookHome = (yield self.transactionUnderTest()
+ .addressbookHomeWithUID("home1"))
self.assertEquals(addressbookHome.uid(), "home1")
self.assertProvides(IAddressBookHome, addressbookHome)
+ @inlineCallbacks
def test_addressbookHomeWithUID_absent(self):
"""
L{IAddressBookStoreTransaction.addressbookHomeWithUID} should return C{None}
when asked for a non-existent addressbook home.
"""
txn = self.transactionUnderTest()
- self.assertEquals(txn.addressbookHomeWithUID("xyzzy"), None)
+ self.assertEquals((yield txn.addressbookHomeWithUID("xyzzy")), None)
@inlineCallbacks
@@ -705,20 +707,21 @@
"""
txn = self.transactionUnderTest()
noHomeUID = "xyzzy"
- addressbookHome = txn.addressbookHomeWithUID(
+ addressbookHome = yield txn.addressbookHomeWithUID(
noHomeUID,
create=True
)
+ @inlineCallbacks
def readOtherTxn():
otherTxn = self.savedStore.newTransaction()
self.addCleanup(otherTxn.commit)
- return otherTxn.addressbookHomeWithUID(noHomeUID)
+ returnValue((yield otherTxn.addressbookHomeWithUID(noHomeUID)))
self.assertProvides(IAddressBookHome, addressbookHome)
- # A concurrent transaction shouldn't be able to read it yet:
- self.assertIdentical(readOtherTxn(), None)
+ # A concurrent tnransaction shouldn't be able to read it yet:
+ self.assertIdentical((yield readOtherTxn()), None)
yield self.commit()
# But once it's committed, other transactions should see it.
- self.assertProvides(IAddressBookHome, readOtherTxn())
+ self.assertProvides(IAddressBookHome, (yield readOtherTxn()))
@inlineCallbacks
@@ -847,18 +850,20 @@
Addressbooks in one user's addressbook home should not show up in another
user's addressbook home.
"""
- home2 = self.transactionUnderTest().addressbookHomeWithUID(
- "home2", create=True)
+ home2 = yield self.transactionUnderTest().addressbookHomeWithUID(
+ "home2", create=True
+ )
self.assertIdentical((yield home2.addressbookWithName("addressbook_1")), None)
+ @inlineCallbacks
def test_dontLeakObjects(self):
"""
Addressbook objects in one user's addressbook should not show up in another
user's via uid or name queries.
"""
home1 = self.homeUnderTest()
- home2 = self.transactionUnderTest().addressbookHomeWithUID(
+ home2 = yield self.transactionUnderTest().addressbookHomeWithUID(
"home2", create=True)
addressbook1 = yield home1.addressbookWithName("addressbook_1")
addressbook2 = yield home2.addressbookWithName("addressbook")
@@ -882,7 +887,7 @@
additionalUIDs = set('alpha-uid home2 home3 beta-uid'.split())
txn = self.transactionUnderTest()
for name in additionalUIDs:
- txn.addressbookHomeWithUID(name, create=True)
+ yield txn.addressbookHomeWithUID(name, create=True)
yield self.commit()
foundUIDs = set([])
lastTxn = None
Modified: CalendarServer/branches/users/glyph/more-deferreds-6/txdav/carddav/datastore/test/test_file.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-6/txdav/carddav/datastore/test/test_file.py 2010-09-24 02:29:35 UTC (rev 6367)
+++ CalendarServer/branches/users/glyph/more-deferreds-6/txdav/carddav/datastore/test/test_file.py 2010-09-24 03:01:13 UTC (rev 6368)
@@ -18,9 +18,11 @@
File addressbook store tests.
"""
-from twext.python.filepath import CachingFilePath as FilePath
+from twisted.internet.defer import inlineCallbacks
from twisted.trial import unittest
+from twext.python.filepath import CachingFilePath as FilePath
+
from twistedcaldav.vcard import Component as VComponent
from txdav.common.icommondatastore import HomeChildNameNotAllowedError
@@ -66,16 +68,18 @@
+ at inlineCallbacks
def setUpHome1(test):
setUpAddressBookStore(test)
- test.home1 = test.txn.addressbookHomeWithUID("home1")
+ test.home1 = yield test.txn.addressbookHomeWithUID("home1")
assert test.home1 is not None, "No addressbook home?"
+ at inlineCallbacks
def setUpAddressBook1(test):
- setUpHome1(test)
- test.addressbook1 = test.home1.addressbookWithName("addressbook_1")
+ yield setUpHome1(test)
+ test.addressbook1 = yield test.home1.addressbookWithName("addressbook_1")
assert test.addressbook1 is not None, "No addressbook?"
@@ -89,14 +93,15 @@
setUpAddressBookStore(self)
+ @inlineCallbacks
def test_addressbookHomeWithUID_dot(self):
"""
Filenames starting with "." are reserved by this
implementation, so no UIDs may start with ".".
"""
self.assertEquals(
- self.addressbookStore.newTransaction(self.id()
- ).addressbookHomeWithUID("xyzzy"),
+ (yield self.addressbookStore.newTransaction(self.id()
+ ).addressbookHomeWithUID(".xyzzy")),
None
)
@@ -105,7 +110,7 @@
class AddressBookHomeTest(unittest.TestCase):
def setUp(self):
- setUpHome1(self)
+ return setUpHome1(self)
def test_init(self):
@@ -179,6 +184,7 @@
)
+ @inlineCallbacks
def test_useIndexImmediately(self):
"""
L{AddressBook._index} is usable in the same transaction it is created, with
@@ -189,10 +195,10 @@
index = addressbook._index
self.assertEquals(set(index.addressbookObjects()),
set(addressbook.addressbookObjects()))
- self.txn.commit()
+ yield self.txn.commit()
self.txn = self.addressbookStore.newTransaction(self.id())
- self.home1 = self.txn.addressbookHomeWithUID("home1")
- addressbook = self.home1.addressbookWithName("addressbook2")
+ self.home1 = yield self.txn.addressbookHomeWithUID("home1")
+ addressbook = yield self.home1.addressbookWithName("addressbook2")
# 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
@@ -283,16 +289,18 @@
)
+ @inlineCallbacks
def _refresh(self):
"""
Re-read the (committed) home1 and addressbook1 objects in a new
transaction.
"""
self.txn = self.addressbookStore.newTransaction(self.id())
- self.home1 = self.txn.addressbookHomeWithUID("home1")
- self.addressbook1 = self.home1.addressbookWithName("addressbook_1")
+ self.home1 = yield self.txn.addressbookHomeWithUID("home1")
+ self.addressbook1 = yield self.home1.addressbookWithName("addressbook_1")
+ @inlineCallbacks
def test_undoCreateAddressBookObject(self):
"""
If a addressbook object is created as part of a transaction, it will be
@@ -300,20 +308,21 @@
"""
# Make sure that the addressbook home is actually committed; rolling back
# addressbook home creation will remove the whole directory.
- self.txn.commit()
- self._refresh()
+ yield self.txn.commit()
+ yield self._refresh()
self.addressbook1.createAddressBookObjectWithName(
"sample.vcf",
VComponent.fromString(vcard4_text)
)
- self.txn.abort()
- self._refresh()
+ yield self.txn.abort()
+ yield self._refresh()
self.assertIdentical(
- self.addressbook1.addressbookObjectWithName("sample.vcf"),
+ (yield self.addressbook1.addressbookObjectWithName("sample.vcf")),
None
)
+ @inlineCallbacks
def doThenUndo(self):
"""
Commit the current transaction, but add an operation that will cause it
@@ -325,17 +334,18 @@
raise RuntimeError("oops")
self.txn.addOperation(fail, "dummy failing operation")
self.assertRaises(RuntimeError, self.txn.commit)
- self._refresh()
+ yield self._refresh()
+ @inlineCallbacks
def test_undoModifyAddressBookObject(self):
"""
If an existing addressbook object is modified as part of a transaction, it
should be restored to its previous status if the transaction aborts.
"""
- originalComponent = self.addressbook1.addressbookObjectWithName(
+ originalComponent = yield self.addressbook1.addressbookObjectWithName(
"1.vcf").component()
- self.addressbook1.addressbookObjectWithName("1.vcf").setComponent(
+ (yield self.addressbook1.addressbookObjectWithName("1.vcf")).setComponent(
VComponent.fromString(vcard1modified_text)
)
# Sanity check.
@@ -343,7 +353,7 @@
self.addressbook1.addressbookObjectWithName("1.vcf").component(),
VComponent.fromString(vcard1modified_text)
)
- self.doThenUndo()
+ yield self.doThenUndo()
self.assertEquals(
self.addressbook1.addressbookObjectWithName("1.vcf").component(),
originalComponent
@@ -452,7 +462,8 @@
def test_addressbookObjectsWithDotFile(self):
"""
- Adding a dotfile to the addressbook home should not increase
+ Adding a dotfile to the addressbook home should not create a new
+ addressbook object.
"""
self.homeUnderTest()._path.child(".foo").createDirectory()
self.test_addressbookObjects()
Modified: CalendarServer/branches/users/glyph/more-deferreds-6/txdav/carddav/datastore/test/test_sql.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-6/txdav/carddav/datastore/test/test_sql.py 2010-09-24 02:29:35 UTC (rev 6367)
+++ CalendarServer/branches/users/glyph/more-deferreds-6/txdav/carddav/datastore/test/test_sql.py 2010-09-24 03:01:13 UTC (rev 6368)
@@ -53,7 +53,7 @@
for homeUID in self.requirements:
addressbooks = self.requirements[homeUID]
if addressbooks is not None:
- home = populateTxn.addressbookHomeWithUID(homeUID, True)
+ home = yield populateTxn.addressbookHomeWithUID(homeUID, True)
# We don't want the default addressbook to appear unless it's
# explicitly listed.
home.removeAddressBookWithName("addressbook")
@@ -122,14 +122,15 @@
return txn
+ @inlineCallbacks
def test_migrateAddressbookFromFile(self):
"""
C{_migrateAddressbook()} can migrate a file-backed addressbook to a
database- backed addressbook.
"""
- fromAddressbook = self.fileTransaction().addressbookHomeWithUID(
+ fromAddressbook = yield self.fileTransaction().addressbookHomeWithUID(
"home1").addressbookWithName("addressbook_1")
- toHome = self.transactionUnderTest().addressbookHomeWithUID(
+ toHome = yield self.transactionUnderTest().addressbookHomeWithUID(
"new-home", create=True)
toAddressbook = toHome.addressbookWithName("addressbook")
_migrateAddressbook(fromAddressbook, toAddressbook,
@@ -137,13 +138,14 @@
self.assertAddressbooksSimilar(fromAddressbook, toAddressbook)
+ @inlineCallbacks
def test_migrateHomeFromFile(self):
"""
L{migrateHome} will migrate an L{IAddressbookHome} provider from one
backend to another; in this specific case, from the file-based backend
to the SQL-based backend.
"""
- fromHome = self.fileTransaction().addressbookHomeWithUID("home1")
+ fromHome = yield self.fileTransaction().addressbookHomeWithUID("home1")
builtinProperties = [PropertyName.fromElement(ResourceType)]
@@ -152,10 +154,11 @@
key = PropertyName.fromElement(GETContentLanguage)
fromHome.properties()[key] = GETContentLanguage("C")
- fromHome.addressbookWithName("addressbook_1").properties()[key] = (
+ (yield fromHome.addressbookWithName("addressbook_1")).properties()[
+ key] = (
GETContentLanguage("pig-latin")
)
- toHome = self.transactionUnderTest().addressbookHomeWithUID(
+ toHome = yield self.transactionUnderTest().addressbookHomeWithUID(
"new-home", create=True
)
migrateHome(fromHome, toHome, lambda x: x.component())
Modified: CalendarServer/branches/users/glyph/more-deferreds-6/txdav/carddav/iaddressbookstore.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-6/txdav/carddav/iaddressbookstore.py 2010-09-24 02:29:35 UTC (rev 6367)
+++ CalendarServer/branches/users/glyph/more-deferreds-6/txdav/carddav/iaddressbookstore.py 2010-09-24 03:01:13 UTC (rev 6368)
@@ -44,8 +44,8 @@
If C{create} is C{True}, create the addressbook home if it doesn't
already exist.
- @return: an L{IAddressBookHome} or C{None} if no such addressbook
- home exists.
+ @return: a L{Deferred} which fires with an L{IAddressBookHome} or
+ C{None} if no such addressbook home exists.
"""
Modified: CalendarServer/branches/users/glyph/more-deferreds-6/txdav/common/datastore/util.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-6/txdav/common/datastore/util.py 2010-09-24 02:29:35 UTC (rev 6367)
+++ CalendarServer/branches/users/glyph/more-deferreds-6/txdav/common/datastore/util.py 2010-09-24 03:01:13 UTC (rev 6368)
@@ -107,7 +107,7 @@
yield sqlTxn.abort()
yield fileTxn.commit()
continue
- sqlHome = homeGetter(uid, create=True)
+ sqlHome = yield homeGetter(uid, create=True)
yield migrateFunc(fileHome, sqlHome)
yield fileTxn.commit()
yield sqlTxn.commit()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100923/629496c2/attachment-0001.html>
More information about the calendarserver-changes
mailing list