[CalendarServer-changes] [5555] CalendarServer/branches/users/wsanchez/transations/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Sun May 2 14:40:10 PDT 2010


Revision: 5555
          http://trac.macosforge.org/projects/calendarserver/changeset/5555
Author:   glyph at apple.com
Date:     2010-05-02 14:40:09 -0700 (Sun, 02 May 2010)
Log Message:
-----------
very first basic insinuation of new backend into "old" protocol logic

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

Added Paths:
-----------
    CalendarServer/branches/users/wsanchez/transations/twistedcaldav/test/test_wrapping.py

Modified: CalendarServer/branches/users/wsanchez/transations/twistedcaldav/static.py
===================================================================
--- CalendarServer/branches/users/wsanchez/transations/twistedcaldav/static.py	2010-05-02 21:38:37 UTC (rev 5554)
+++ CalendarServer/branches/users/wsanchez/transations/twistedcaldav/static.py	2010-05-02 21:40:09 UTC (rev 5555)
@@ -1,3 +1,4 @@
+# -*- test-case-name: twistedcaldav.test -*-
 ##
 # Copyright (c) 2005-2010 Apple Inc. All rights reserved.
 #
@@ -108,6 +109,8 @@
 from twistedcaldav.notifications import NotificationCollectionResource,\
     NotificationResource
 
+from txcaldav.calendarstore.file import CalendarStore
+
 log = Logger()
 
 class ReadOnlyResourceMixIn(object):
@@ -834,16 +837,22 @@
         """
         DAVFile.__init__(self, path)
         DirectoryCalendarHomeProvisioningResource.__init__(self, directory, url)
+        storagePath = self.fp.child(uidsResourceName)
+        self._newStore = CalendarStore(storagePath)
 
+
     def provisionChild(self, name):
         if name == uidsResourceName:
             return CalendarHomeUIDProvisioningFile(self.fp.child(name).path, self)
 
         return CalendarHomeTypeProvisioningFile(self.fp.child(name).path, self, name)
 
+
     def createSimilarFile(self, path):
         raise HTTPError(responsecode.NOT_FOUND)
 
+
+
 class CalendarHomeTypeProvisioningFile (AutoProvisioningFileMixIn, DirectoryCalendarHomeTypeProvisioningResource, DAVFile):
     def __init__(self, path, parent, recordType):
         """
@@ -854,6 +863,8 @@
         DAVFile.__init__(self, path)
         DirectoryCalendarHomeTypeProvisioningResource.__init__(self, parent, recordType)
 
+
+
 class CalendarHomeUIDProvisioningFile (AutoProvisioningFileMixIn, DirectoryCalendarHomeUIDProvisioningResource, DAVFile):
     def __init__(self, path, parent, homeResourceClass=None):
         """
@@ -969,6 +980,9 @@
         self.clientNotifier = ClientNotifier(self)
         CalDAVFile.__init__(self, path)
         DirectoryCalendarHomeResource.__init__(self, parent, record)
+        self._newStoreCalendar = (self.parent.parent._newStore.newTransaction()
+                                  .calendarHomeWithUID(self.record.uid,
+                                                       create=True))
 
     def provision(self):
         result = super(CalendarHomeFile, self).provision()

Added: CalendarServer/branches/users/wsanchez/transations/twistedcaldav/test/test_wrapping.py
===================================================================
--- CalendarServer/branches/users/wsanchez/transations/twistedcaldav/test/test_wrapping.py	                        (rev 0)
+++ CalendarServer/branches/users/wsanchez/transations/twistedcaldav/test/test_wrapping.py	2010-05-02 21:40:09 UTC (rev 5555)
@@ -0,0 +1,90 @@
+##
+# Copyright (c) 2010 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+from twistedcaldav.test.util import TestCase
+from twistedcaldav.config import config
+from twext.python.filepath import CachingFilePath as FilePath
+from twistedcaldav.directory.test.test_xmlfile import xmlFile
+from twistedcaldav.directory.xmlfile import XMLDirectoryService
+from twistedcaldav.directory import augment
+from twistedcaldav.directory.test.test_xmlfile import augmentsFile
+from twistedcaldav.directory.principal import DirectoryPrincipalProvisioningResource
+from twext.web2.dav import davxml
+from twistedcaldav.static import CalendarHomeProvisioningFile
+from txcaldav.calendarstore.file import CalendarStore
+from twisted.internet.defer import inlineCallbacks
+from twistedcaldav.directory.calendar import uidsResourceName
+
+
+class WrappingTests(TestCase):
+    """
+    Tests for L{twistedcaldav.static.CalDAVFile} creating the appropriate type
+    of txcaldav.calendarstore.file underlying object when it can determine what
+    type it really represents.
+    """
+
+    def setUp(self):
+        # Mostly copied from
+        # twistedcaldav.directory.test.test_calendar.ProvisionedCalendars; this
+        # should probably be refactored, perhaps even to call (some part of) the
+        # actual root-resource construction logic?
+        super(WrappingTests, self).setUp()
+        # Setup the initial directory
+        self.xmlFile = FilePath(config.DataRoot).child("accounts.xml")
+        self.xmlFile.setContent(xmlFile.getContent())
+        self.directoryService = XMLDirectoryService({'xmlFile' :
+                                                     "accounts.xml"})
+        augment.AugmentService = augment.AugmentXMLDB(
+            xmlFiles=(augmentsFile.path,))
+        # Set up a principals hierarchy for each service we're testing with
+        provisioningResource = DirectoryPrincipalProvisioningResource(
+            "/principals/", self.directoryService
+        )
+        self.site.resource.putChild("principals", provisioningResource)
+        calendarsPath = FilePath(self.docroot).child("calendars")
+        calendarsPath.makedirs()
+        self.calendarCollection = CalendarHomeProvisioningFile(
+            calendarsPath, self.directoryService, "/calendars/"
+        )
+        self.site.resource.putChild("calendars", self.calendarCollection)
+        self.site.resource.setAccessControlList(davxml.ACL())
+
+
+    def test_createStore(self):
+        """
+        Creating a CalendarHomeProvisioningFile will create a paired
+        CalendarStore.
+        """
+        self.assertIsInstance(self.calendarCollection._newStore, CalendarStore)
+        self.assertEqual(self.calendarCollection._newStore._path,
+                         self.calendarCollection.fp.child(uidsResourceName))
+
+
+    @inlineCallbacks
+    def test_lookupCalendar(self):
+        """
+        When a L{CalDAVFile} representing an existing calendar collection is
+        looked up in a CalendarHomeProvisioningFile, it will create a
+        corresponding L{txcaldav.calendarstore.file.Calendar} via
+        calendarHomeWithUID.
+        """
+        segments = ["users", "wsanchez", ""]
+        resource = self.calendarCollection
+        while segments:
+            resource, segments = yield resource.locateChild(None, segments)
+        self.assertEqual(resource.fp, resource._newStoreCalendar._path)
+
+
+


Property changes on: CalendarServer/branches/users/wsanchez/transations/twistedcaldav/test/test_wrapping.py
___________________________________________________________________
Added: svn:mime-type
   + text/plain
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100502/f70059b7/attachment.html>


More information about the calendarserver-changes mailing list