[CalendarServer-changes] [5580] CalendarServer/branches/users/wsanchez/transations/twistedcaldav/ test/test_collectioncontents.py

source_changes at macosforge.org source_changes at macosforge.org
Sun May 9 15:53:03 PDT 2010


Revision: 5580
          http://trac.macosforge.org/projects/calendarserver/changeset/5580
Author:   glyph at apple.com
Date:     2010-05-09 15:52:58 -0700 (Sun, 09 May 2010)
Log Message:
-----------
Safer, more correct/complete setUp that establishes the back-end state necessary to create calendars now.

Modified Paths:
--------------
    CalendarServer/branches/users/wsanchez/transations/twistedcaldav/test/test_collectioncontents.py

Modified: CalendarServer/branches/users/wsanchez/transations/twistedcaldav/test/test_collectioncontents.py
===================================================================
--- CalendarServer/branches/users/wsanchez/transations/twistedcaldav/test/test_collectioncontents.py	2010-05-09 22:42:09 UTC (rev 5579)
+++ CalendarServer/branches/users/wsanchez/transations/twistedcaldav/test/test_collectioncontents.py	2010-05-09 22:52:58 UTC (rev 5580)
@@ -16,7 +16,8 @@
 
 import os
 
-from twisted.internet.defer import DeferredList
+from twisted.internet.defer import DeferredList, succeed
+from twext.python.filepath import CachingFilePath as FilePath
 from twext.web2 import responsecode
 from twext.web2.iweb import IResponse
 from twext.web2.stream import MemoryStream, FileStream
@@ -27,35 +28,74 @@
 from twistedcaldav.memcachelock import MemcacheLock
 from twistedcaldav.memcacher import Memcacher
 from twistedcaldav.method.put_common import StoreCalendarObjectResource
+
+
 import twistedcaldav.test.util
+from twistedcaldav.static import CalendarHomeUIDProvisioningFile,\
+    CalendarHomeProvisioningFile
+from twistedcaldav.directory.principal import DirectoryPrincipalProvisioningResource
+from twext.web2.dav import davxml
 
 class CollectionContents (twistedcaldav.test.util.TestCase):
     """
     PUT request
     """
-    data_dir = os.path.join(os.path.dirname(__file__), "data")
+    data_dir = FilePath(__file__).sibling("data").path
 
     def setUp(self):
-        
+
         # Need to fake out memcache
         def _getFakeMemcacheProtocol(self):
-            
+
             result = super(MemcacheLock, self)._getMemcacheProtocol()
             if isinstance(result, Memcacher.nullCacher):
                 result = self._memcacheProtocol = Memcacher.memoryCacher()
-            
+
             return result
-        
+
         MemcacheLock._getMemcacheProtocol = _getFakeMemcacheProtocol
 
         # Need to not do implicit behavior during these tests
         def _fakeDoImplicitScheduling(self):
             return False, False, False
-        
-        StoreCalendarObjectResource.doImplicitScheduling = _fakeDoImplicitScheduling
+        self.patch(StoreCalendarObjectResource , "doImplicitScheduling",
+                   _fakeDoImplicitScheduling)
 
+        # Tests in this suite assume that the root resource is a calendar home.
+        # FIXME: there should be a centralized way of saying 'make this look
+        # like a calendar home'
         super(CollectionContents, self).setUp()
 
+        fp = FilePath(self.mktemp())
+
+        self.createStockDirectoryService()
+
+        # FIXME: see FIXME in DirectoryPrincipalProvisioningResource.__init__;
+        # this performs a necessary modification to the directory service
+        # object.
+        DirectoryPrincipalProvisioningResource(
+            "/principals/", self.directoryService
+        )
+        provFile = CalendarHomeProvisioningFile(fp, self.directoryService, "/")
+
+        users = provFile.getChild("users")
+        user = users.getChild("wsanchez")
+
+        # Fix the site to point directly at the user's calendar home so that we
+        # can focus on testing just that rather than hierarchy traversal..
+        self.site.resource = user
+
+        # Fix the docroot so that 'mkdtemp' will create directories in the right
+        # place (beneath the calendar).
+        self.docroot = user.fp.path
+
+        # Force the request to succeed regardless of the implementation of
+        # accessControlList.
+        user.accessControlList = lambda request, *a, **k: succeed(
+            self.grantInherit(davxml.All())
+        ) 
+
+
     def test_collection_in_calendar(self):
         """
         Make (regular) collection in calendar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100509/592c9709/attachment.html>


More information about the calendarserver-changes mailing list