[CalendarServer-changes] [10863] CalendarServer/branches/users/gaya/sharedgroups
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 6 17:59:44 PST 2013
Revision: 10863
http://trac.calendarserver.org//changeset/10863
Author: gaya at apple.com
Date: 2013-03-06 17:59:44 -0800 (Wed, 06 Mar 2013)
Log Message:
-----------
Fix more test cases. Fix owned addressbook.
Modified Paths:
--------------
CalendarServer/branches/users/gaya/sharedgroups/twistedcaldav/test/test_wrapping.py
CalendarServer/branches/users/gaya/sharedgroups/txdav/carddav/datastore/sql.py
CalendarServer/branches/users/gaya/sharedgroups/txdav/carddav/datastore/test/common.py
CalendarServer/branches/users/gaya/sharedgroups/txdav/carddav/datastore/test/test_file.py
CalendarServer/branches/users/gaya/sharedgroups/txdav/carddav/datastore/test/test_sql.py
CalendarServer/branches/users/gaya/sharedgroups/txdav/common/datastore/sql.py
Modified: CalendarServer/branches/users/gaya/sharedgroups/twistedcaldav/test/test_wrapping.py
===================================================================
--- CalendarServer/branches/users/gaya/sharedgroups/twistedcaldav/test/test_wrapping.py 2013-03-06 02:45:48 UTC (rev 10862)
+++ CalendarServer/branches/users/gaya/sharedgroups/twistedcaldav/test/test_wrapping.py 2013-03-07 01:59:44 UTC (rev 10863)
@@ -495,27 +495,7 @@
yield self.commit()
self.checkPrincipalCollections(calDavFile)
- @inlineCallbacks
- @rewriteOrRemove
- def test_lookupNewAddressBook(self):
-
- """
- When a L{CalDAVResource} which represents a not-yet-created addressbook
- collection is looked up in a L{AddressBookHomeFile} representing a addressbook
- home, it will initially have a new storage backend set to C{None}, but
- when the addressbook is created via a protocol action, the backend will be
- initialized to match.
- """
- calDavFile = yield self.getResource("addressbooks/users/wsanchez/frobozz")
- self.assertIsInstance(calDavFile, AddressBookCollectionResource)
- self.assertFalse(calDavFile.exists())
- yield calDavFile.createAddressBookCollection()
- self.assertTrue(calDavFile.exists())
- yield self.commit()
- self.checkPrincipalCollections(calDavFile)
-
-
@inlineCallbacks
def test_lookupAddressBookObject(self):
"""
Modified: CalendarServer/branches/users/gaya/sharedgroups/txdav/carddav/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/gaya/sharedgroups/txdav/carddav/datastore/sql.py 2013-03-06 02:45:48 UTC (rev 10862)
+++ CalendarServer/branches/users/gaya/sharedgroups/txdav/carddav/datastore/sql.py 2013-03-07 01:59:44 UTC (rev 10863)
@@ -144,7 +144,7 @@
self.uid(),
self.uid(),
self._txn,
- self._homeResourceID,
+ self._homeResourceID, # not ._resourceID as in CommonHome._loadPropertyStore()
notifyCallback=self.notifyChanged
)
self._propertyStore = props
@@ -184,7 +184,9 @@
def createdHome(self):
# initialize address book properties, synctoken
child = yield self.addressbook()
- yield child._loadPropertyStore()
+ #FIXME: define as same property
+ child._created = self._created
+ child._modified = self._modified
yield child._initSyncToken()
@@ -205,16 +207,23 @@
).on(self._txn, **kwds)
- @classmethod
- def addressbookName(cls):
- return "addressbook"
-
-
@inlineCallbacks
def addressbook(self):
- returnValue((yield self.addressbookWithName(self.addressbookName())))
+ if not hasattr(self, "_addressbook"):
+ child = AddressBook(
+ home=self,
+ name="addressbook", resourceID=self._resourceID,
+ mode=_BIND_MODE_OWN, status=_BIND_STATUS_ACCEPTED,
+ )
+ yield child._loadPropertyStore()
+ child.properties()[
+ PropertyName.fromElement(ResourceType)
+ ] = child.resourceType()
+ self._addressbook = child
+ returnValue(self._addressbook)
+
def shareeAddressBookName(self):
return self.uid()
@@ -317,17 +326,15 @@
def contentType(self):
"""
- The content type of Addresbook objects is text/vcard.
+ The content type of addressbook objects is text/vcard.
"""
return MimeType.fromString("text/vcard; charset=utf-8")
@classmethod
- @inlineCallbacks
def create(cls, home, name):
- if name == home.addressbookName():
+ if name == (yield home.addressbook()).name():
#raise HomeChildNameAlreadyExistsError
- yield None
pass
else:
raise HomeChildNameNotAllowedError
@@ -337,29 +344,19 @@
def remove(self):
if self._resourceID == self._home._resourceID:
-
# allow remove, as a way to reset the address book to an empty state
for abo in (yield self.objectResources()):
- yield abo.remove()
-
+ yield self.removeObjectResource(abo)
+ self.unshare()
self.properties()._removeResource()
-
- # Set to non-existent state
- self._resourceID = None
- self._created = None
- self._modified = None
- self._objects = {}
-
- yield self.notifyChanged()
-
- # Make sure home collection modified is changed - not that we do not use _home.notifiedChanged() here
- # since we are sending the notification on the previously existing child collection object
- yield self._home.bumpModified()
+ self._loadPropertyStore()
+ self.properties()[
+ PropertyName.fromElement(ResourceType)
+ ] = self.resourceType()
else:
returnValue((yield super(AddressBook, self).remove()))
- @inlineCallbacks
def rename(self, name):
# better error?
#raise HomeChildNameNotAllowedError
@@ -630,14 +627,10 @@
@return: an L{CommonHomeChild} or C{None} if no such child
exists.
"""
- if name == home.addressbookName():
- child = cls(
- home=home,
- name=name, resourceID=home._resourceID,
- mode=_BIND_MODE_OWN, status=_BIND_STATUS_ACCEPTED,
- )
- yield child.initFromStore()
- returnValue(child)
+ if accepted:
+ addressbook = yield home.addressbook()
+ if name == addressbook.name():
+ returnValue(addressbook)
#all shared address books now
rows = None
@@ -844,7 +837,7 @@
@return: an iterable of C{str}s.
"""
- names = set([home.addressbookName()])
+ names = set([(yield home.addressbook()).name()])
rows = yield cls._acceptedBindForHomeID.on(
home._txn, homeID=home._resourceID
@@ -1182,7 +1175,7 @@
sharedAddressBook._deletedSyncToken(sharedRemoval=True)
shareeHome._children.pop(self.shareeAddressBookName(), None)
elif not sharedAddressBook.fullyShared():
- #TODO: Just remove objects for this group only
+ #FIXME: remove objects for this group only using self.removeObjectResource
self._objectNames = None
# Must send notification to ensure cache invalidation occurs
Modified: CalendarServer/branches/users/gaya/sharedgroups/txdav/carddav/datastore/test/common.py
===================================================================
--- CalendarServer/branches/users/gaya/sharedgroups/txdav/carddav/datastore/test/common.py 2013-03-06 02:45:48 UTC (rev 10862)
+++ CalendarServer/branches/users/gaya/sharedgroups/txdav/carddav/datastore/test/common.py 2013-03-07 01:59:44 UTC (rev 10863)
@@ -17,12 +17,17 @@
"""
Tests for common addressbook store API functions.
"""
+from twext.python.filepath import CachingFilePath as FilePath
+from twext.web2.http import HTTPError
+from twext.web2.responsecode import FORBIDDEN
+
from twisted.internet.defer import inlineCallbacks, returnValue, maybeDeferred
from twisted.python import hashlib
+from twistedcaldav.vcard import Component as VComponent
+
from txdav.idav import IPropertyStore, IDataStore
from txdav.base.propertystore.base import PropertyName
-
from txdav.common.icommondatastore import (
HomeChildNameAlreadyExistsError, ICommonTransaction
)
@@ -30,26 +35,13 @@
from txdav.common.icommondatastore import NoSuchHomeChildError
from txdav.common.icommondatastore import NoSuchObjectResourceError
from txdav.common.icommondatastore import ObjectResourceNameAlreadyExistsError
-
from txdav.carddav.iaddressbookstore import (
IAddressBookObject, IAddressBookHome,
IAddressBook, IAddressBookTransaction
)
-
from txdav.common.datastore.test.util import CommonCommonTests
-
-from twistedcaldav.vcard import Component as VComponent
-
-from twext.python.filepath import CachingFilePath as FilePath
from txdav.xml.element import WebDAVUnknownElement, ResourceType
-
-def _todo(f, why):
- f.todo = why
- return f
-rewriteOrRemove = lambda f: _todo(f, "Rewrite or remove")
-fixFile = lambda f: _todo(f, "fix file implementation")
-
storePath = FilePath(__file__).parent().child("addressbook_store")
homeRoot = storePath.child("ho").child("me").child("home1")
@@ -270,28 +262,18 @@
self.assertProvides(IAddressBook, addressbook)
self.assertEquals(addressbook.name(), name)
+
@inlineCallbacks
- @rewriteOrRemove
def test_addressbookRename(self):
"""
L{IAddressBook.rename} changes the name of the L{IAddressBook}.
"""
home = yield self.homeUnderTest()
addressbook = yield home.addressbookWithName("addressbook")
- yield addressbook.rename("some_other_name")
- @inlineCallbacks
- def positiveAssertions():
- self.assertEquals(addressbook.name(), "some_other_name")
- self.assertEquals(addressbook, (yield home.addressbookWithName("some_other_name")))
- self.assertEquals(None, (yield home.addressbookWithName("addressbook")))
- yield positiveAssertions()
- yield self.commit()
- home = yield self.homeUnderTest()
- addressbook = yield home.addressbookWithName("some_other_name")
- yield positiveAssertions()
- # FIXME: revert
- # FIXME: test for multiple renames
- # FIXME: test for conflicting renames (a->b, c->a in the same txn)
+ try:
+ yield addressbook.rename("some-other-name")
+ except HTTPError, e:
+ self.assertEquals(e.response.code, FORBIDDEN)
@inlineCallbacks
@@ -306,7 +288,6 @@
@inlineCallbacks
- @rewriteOrRemove
def test_createAddressBookWithName_absent(self):
"""
L{IAddressBookHome.createAddressBookWithName} creates a new L{IAddressBook} that
@@ -314,13 +295,13 @@
"""
home = yield self.homeUnderTest()
name = "addressbook"
- self.assertIdentical((yield home.addressbookWithName(name)), None)
+ #self.assertIdentical((yield home.addressbookWithName(name)), None)
yield home.createAddressBookWithName(name)
self.assertNotIdentical((yield home.addressbookWithName(name)), None)
@inlineCallbacks
def checkProperties():
addressbookProperties = (yield home.addressbookWithName(name)).properties()
- addressbookType = ResourceType.addressbook #@UndefinedVariable
+ addressbookType = ResourceType.addressbook
self.assertEquals(
addressbookProperties[
PropertyName.fromString(ResourceType.sname())
@@ -347,22 +328,6 @@
@inlineCallbacks
- def test_createAddressBookWithName_exists(self):
- """
- L{IAddressBookHome.createAddressBookWithName} raises
- L{AddressBookAlreadyExistsError} when the name conflicts with an already-
- existing address book.
- """
- for name in home1_addressbookNames:
- yield self.failUnlessFailure(
- maybeDeferred(
- (yield self.homeUnderTest()).createAddressBookWithName, name),
- HomeChildNameAlreadyExistsError,
- )
-
-
- @inlineCallbacks
- @fixFile
def test_removeAddressBookWithName_exists(self):
"""
L{IAddressBookHome.removeAddressBookWithName} removes a addressbook that already
@@ -644,7 +609,6 @@
@inlineCallbacks
- @rewriteOrRemove
def test_loadAllAddressBooks(self):
"""
L{IAddressBookHome.loadAddressBooks} returns an iterable of L{IAddressBook}
@@ -671,22 +635,6 @@
@inlineCallbacks
- @rewriteOrRemove
- def test_addressbooksAfterAddAddressBook(self):
- """
- L{IAddressBookHome.addressbooks} includes addressbooks recently added with
- L{IAddressBookHome.createAddressBookWithName}.
- """
- home = yield self.homeUnderTest()
- allAddressbooks = yield home.addressbooks()
- before = set(x.name() for x in allAddressbooks)
- yield home.createAddressBookWithName("new-name")
- allAddressbooks = yield home.addressbooks()
- after = set(x.name() for x in allAddressbooks)
- self.assertEquals(before | set(['new-name']), after)
-
-
- @inlineCallbacks
def test_createAddressBookObjectWithName_absent(self):
"""
L{IAddressBook.createAddressBookObjectWithName} creates a new
Modified: CalendarServer/branches/users/gaya/sharedgroups/txdav/carddav/datastore/test/test_file.py
===================================================================
--- CalendarServer/branches/users/gaya/sharedgroups/txdav/carddav/datastore/test/test_file.py 2013-03-06 02:45:48 UTC (rev 10862)
+++ CalendarServer/branches/users/gaya/sharedgroups/txdav/carddav/datastore/test/test_file.py 2013-03-07 01:59:44 UTC (rev 10863)
@@ -50,6 +50,7 @@
featureUnimplemented = lambda f: _todo(f, "Feature unimplemented")
testUnimplemented = lambda f: _todo(f, "Test unimplemented")
todo = lambda why: lambda f: _todo(f, why)
+fixFile = lambda f: _todo(f, "fix file implementation")
def setUpAddressBookStore(test):
@@ -490,3 +491,23 @@
((yield self.addressbookUnderTest())._path.child("not-a-vcard")
.createDirectory())
yield self.test_addressbookObjects()
+
+
+ @inlineCallbacks
+ @fixFile
+ def test_createAddressBookWithName_absent(self):
+ """
+ L{IAddressBookHome.createAddressBookWithName} creates a new L{IAddressBook} that
+ can be retrieved with L{IAddressBookHome.addressbookWithName}.
+ """
+ pass
+
+
+ @inlineCallbacks
+ @fixFile
+ def test_removeAddressBookWithName_exists(self):
+ """
+ L{IAddressBookHome.removeAddressBookWithName} removes a addressbook that already
+ exists.
+ """
+ pass
Modified: CalendarServer/branches/users/gaya/sharedgroups/txdav/carddav/datastore/test/test_sql.py
===================================================================
--- CalendarServer/branches/users/gaya/sharedgroups/txdav/carddav/datastore/test/test_sql.py 2013-03-06 02:45:48 UTC (rev 10862)
+++ CalendarServer/branches/users/gaya/sharedgroups/txdav/carddav/datastore/test/test_sql.py 2013-03-07 01:59:44 UTC (rev 10863)
@@ -35,16 +35,16 @@
from txdav.carddav.datastore.test.test_file import setUpAddressBookStore
from txdav.carddav.datastore.util import _migrateAddressbook, migrateHome
from txdav.common.datastore.sql import EADDRESSBOOKTYPE
-from txdav.common.datastore.sql_tables import \
- _ABO_KIND_PERSON, _ABO_KIND_GROUP, schema
+from txdav.common.datastore.sql_tables import _ABO_KIND_PERSON, _ABO_KIND_GROUP, \
+ schema
from txdav.common.datastore.test.util import buildStore
-from txdav.xml.rfc2518 import GETContentLanguage, ResourceType
+from txdav.xml.rfc2518 import GETContentLanguage
def _todo(f, why):
f.todo = why
return f
-rewriteOrRemove = lambda f: _todo(f, "Rewrite or remove")
+fixMigration = lambda f: _todo(f, "fix migration to shared groups")
class AddressBookSQLStorageTests(AddressBookCommonTests, unittest.TestCase):
"""
@@ -137,7 +137,6 @@
@inlineCallbacks
- @rewriteOrRemove
def test_migrateAddressbookFromFile(self):
"""
C{_migrateAddressbook()} can migrate a file-backed addressbook to a
@@ -154,7 +153,6 @@
@inlineCallbacks
- @rewriteOrRemove
def test_migrateBadAddressbookFromFile(self):
"""
C{_migrateAddressbook()} can migrate a file-backed addressbook to a
@@ -173,7 +171,7 @@
@inlineCallbacks
- @rewriteOrRemove
+ @fixMigration
def test_migrateHomeFromFile(self):
"""
L{migrateHome} will migrate an L{IAddressbookHome} provider from one
@@ -182,8 +180,6 @@
"""
fromHome = yield self.fileTransaction().addressbookHomeWithUID("home1")
- builtinProperties = [PropertyName.fromElement(ResourceType)]
-
# Populate an arbitrary / unused dead properties so there's something
# to verify against.
@@ -205,9 +201,8 @@
for c in fromAddressbooks:
self.assertPropertiesSimilar(
c, (yield toHome.addressbookWithName(c.name())),
- builtinProperties
)
- self.assertPropertiesSimilar(fromHome, toHome, builtinProperties)
+ self.assertPropertiesSimilar(fromHome, toHome,)
def test_addressBookHomeVersion(self):
@@ -528,29 +523,31 @@
@inlineCallbacks
- @rewriteOrRemove
def test_removeAddressBookPropertiesOnDelete(self):
"""
- L{IAddressBookHome.removeAddressBookWithName} removes an address book that already
- exists and makes sure properties are also removed.
+ L{IAddressBookHome.removeAddressBookWithName} clears an address book that already
+ exists and makes sure added properties are also removed.
"""
+ prop = schema.RESOURCE_PROPERTY
+ _allWithID = Select([prop.NAME, prop.VIEWER_UID, prop.VALUE],
+ From=prop,
+ Where=prop.RESOURCE_ID == Parameter("resourceID"))
+
# Create address book and add a property
home = yield self.homeUnderTest()
- name = "remove-me"
+ name = "addressbook"
addressbook = yield home.createAddressBookWithName(name)
resourceID = addressbook._resourceID
- addressbookProperties = addressbook.properties()
- prop = carddavxml.AddressBookDescription.fromString("Address Book to be removed")
+ rows = yield _allWithID.on(self.transactionUnderTest(), resourceID=resourceID)
+ self.assertEqual(len(tuple(rows)), 1)
+
+ addressbookProperties = addressbook.properties()
+ prop = carddavxml.AddressBookDescription.fromString("Address Book prop to be removed")
addressbookProperties[PropertyName.fromElement(prop)] = prop
yield self.commit()
- prop = schema.RESOURCE_PROPERTY
- _allWithID = Select([prop.NAME, prop.VIEWER_UID, prop.VALUE],
- From=prop,
- Where=prop.RESOURCE_ID == Parameter("resourceID"))
-
# Check that two properties are present
home = yield self.homeUnderTest()
rows = yield _allWithID.on(self.transactionUnderTest(), resourceID=resourceID)
@@ -561,12 +558,12 @@
home = yield self.homeUnderTest()
yield home.removeAddressBookWithName(name)
rows = yield _allWithID.on(self.transactionUnderTest(), resourceID=resourceID)
- self.assertEqual(len(tuple(rows)), 0)
+ self.assertEqual(len(tuple(rows)), 1)
yield self.commit()
# Recheck it
rows = yield _allWithID.on(self.transactionUnderTest(), resourceID=resourceID)
- self.assertEqual(len(tuple(rows)), 0)
+ self.assertEqual(len(tuple(rows)), 1)
yield self.commit()
@inlineCallbacks
Modified: CalendarServer/branches/users/gaya/sharedgroups/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/gaya/sharedgroups/txdav/common/datastore/sql.py 2013-03-06 02:45:48 UTC (rev 10862)
+++ CalendarServer/branches/users/gaya/sharedgroups/txdav/common/datastore/sql.py 2013-03-07 01:59:44 UTC (rev 10863)
@@ -3556,6 +3556,8 @@
yield child.remove()
self._objects.pop(name, None)
self._objects.pop(uid, None)
+ if self._objectNames:
+ self._objectNames.remove(name)
yield self._deleteRevision(name)
yield self.notifyChanged()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130306/49a7b076/attachment-0001.html>
More information about the calendarserver-changes
mailing list