[CalendarServer-changes] [2344] CalendarServer/branches/propfind-cache/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Thu Apr 24 14:41:10 PDT 2008


Revision: 2344
          http://trac.macosforge.org/projects/calendarserver/changeset/2344
Author:   dreid at apple.com
Date:     2008-04-24 14:41:09 -0700 (Thu, 24 Apr 2008)

Log Message:
-----------
Make writeDeadProperty notify the cache of a property change.

Modified Paths:
--------------
    CalendarServer/branches/propfind-cache/twistedcaldav/resource.py
    CalendarServer/branches/propfind-cache/twistedcaldav/test/test_cache.py
    CalendarServer/branches/propfind-cache/twistedcaldav/test/test_static.py
    CalendarServer/branches/propfind-cache/twistedcaldav/test/util.py

Added Paths:
-----------
    CalendarServer/branches/propfind-cache/twistedcaldav/test/test_resource.py

Modified: CalendarServer/branches/propfind-cache/twistedcaldav/resource.py
===================================================================
--- CalendarServer/branches/propfind-cache/twistedcaldav/resource.py	2008-04-24 21:30:23 UTC (rev 2343)
+++ CalendarServer/branches/propfind-cache/twistedcaldav/resource.py	2008-04-24 21:41:09 UTC (rev 2344)
@@ -214,14 +214,15 @@
 
         return super(CalDAVResource, self).writeProperty(property, request)
 
-#     def writeDeadProperty(self, property):
-#         val = super(CalDAVResource, self).writeDeadProperty(property, request)
+    def writeDeadProperty(self, property):
+        val = super(CalDAVResource, self).writeDeadProperty(property)
 
-#         if hasattr(self, 'cacheNotifier'):
-#             self.cacheNotifier.propertyChanged()
+        if hasattr(self, 'cacheNotifier'):
+            self.cacheNotifier.propertyChanged()
 
-#         return val
+        return val
 
+
     ##
     # ACL
     ##

Modified: CalendarServer/branches/propfind-cache/twistedcaldav/test/test_cache.py
===================================================================
--- CalendarServer/branches/propfind-cache/twistedcaldav/test/test_cache.py	2008-04-24 21:30:23 UTC (rev 2343)
+++ CalendarServer/branches/propfind-cache/twistedcaldav/test/test_cache.py	2008-04-24 21:41:09 UTC (rev 2344)
@@ -18,25 +18,11 @@
 
 from twisted.trial.unittest import TestCase
 
-from twisted.web2.http import HTTPError, StatusResponse
-
 from twistedcaldav.cache import CacheChangeNotifier, CacheTokensProperty
 
+from twistedcaldav.test.util import InMemoryPropertyStore
 
-class InMemoryPropertyStore(object):
-    def __init__(self):
-        self._properties = {}
 
-    def get(self, qname):
-        data = self._properties.get(qname)
-        if data is None:
-            raise HTTPError(StatusResponse(404, "No such property"))
-        return data
-
-    def set(self, property):
-        self._properties[property.qname()] = property
-
-
 def _newCacheTokens(prefix):
     def _(self):
         called = getattr(self, '_%scalled' % (prefix,), 0)

Added: CalendarServer/branches/propfind-cache/twistedcaldav/test/test_resource.py
===================================================================
--- CalendarServer/branches/propfind-cache/twistedcaldav/test/test_resource.py	                        (rev 0)
+++ CalendarServer/branches/propfind-cache/twistedcaldav/test/test_resource.py	2008-04-24 21:41:09 UTC (rev 2344)
@@ -0,0 +1,57 @@
+##
+# Copyright (c) 2008 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 twisted.trial.unittest import TestCase
+
+from twistedcaldav.resource import CalDAVResource
+
+from twistedcaldav.test.util import StubCacheChangeNotifier
+from twistedcaldav.test.util import InMemoryPropertyStore
+
+
+class StubProperty(object):
+    def qname(self):
+        return "StubQname"
+
+
+class CalDAVResourceTests(TestCase):
+    def setUp(self):
+        self.resource = CalDAVResource()
+        self.resource._dead_properties = InMemoryPropertyStore()
+        self.resource.cacheNotifier = StubCacheChangeNotifier()
+
+
+    def test_writeDeadPropertyNotifiesCache(self):
+        self.resource.writeDeadProperty(StubProperty())
+        self.assertEquals(self.resource.cacheNotifier.propertyChangedCount, 1)
+
+
+    def test_writeDeadPropertyWritesProperty(self):
+        prop = StubProperty()
+        self.resource.writeDeadProperty(prop)
+        self.assertEquals(self.resource._dead_properties.get("StubQname"),
+                          prop)
+
+
+    def test_writeDeadPropertyFailureDoesntNotifyCache(self):
+        self.resource._dead_properties = None
+        self.assertRaises(Exception,
+                          self.resource.writeDeadProperty, StubProperty())
+        self.assertEquals(self.resource.cacheNotifier.propertyChangedCount, 0)
+
+    def test_writeDeadPropertyDoesntFailWithoutACacheNotifier(self):
+        del self.resource.cacheNotifier
+        self.resource.writeDeadProperty(StubProperty())

Modified: CalendarServer/branches/propfind-cache/twistedcaldav/test/test_static.py
===================================================================
--- CalendarServer/branches/propfind-cache/twistedcaldav/test/test_static.py	2008-04-24 21:30:23 UTC (rev 2343)
+++ CalendarServer/branches/propfind-cache/twistedcaldav/test/test_static.py	2008-04-24 21:41:09 UTC (rev 2344)
@@ -18,30 +18,25 @@
 
 from twistedcaldav.static import CalendarHomeFile, CalDAVFile
 from twistedcaldav.cache import CacheChangeNotifier
+from twistedcaldav.test.util import StubCacheChangeNotifier
 
-
 class StubParentResource(object):
     def principalCollections(self):
         return set([])
 
 
-class StubCacheChangeNotifier(object):
-    dataChangedCount = 0
-
-    def dataChanged(self):
-        self.dataChangedCount += 1
-
-
 class CalendarHomeFileTests(TestCase):
     def setUp(self):
         self.calendarHome = CalendarHomeFile(self.mktemp(),
                                              StubParentResource(),
                                              object())
 
+
     def test_hasCacheNotifier(self):
         self.failUnless(isinstance(self.calendarHome.cacheNotifier,
                                    CacheChangeNotifier))
 
+
     def test_childrenHaveCacheNotifier(self):
         child = self.calendarHome.createSimilarFile('/fake/path')
         self.assertEquals(child.cacheNotifier, self.calendarHome.cacheNotifier)
@@ -59,3 +54,8 @@
     def test_updateCTagNotifiesCache(self):
         self.caldavFile.updateCTag()
         self.assertEquals(self.caldavFile.cacheNotifier.dataChangedCount, 1)
+
+
+    def test_updateCTagDoesntFailWithoutACacheNotifier(self):
+        del self.caldavFile.cacheNotifier
+        self.caldavFile.updateCTag()

Modified: CalendarServer/branches/propfind-cache/twistedcaldav/test/util.py
===================================================================
--- CalendarServer/branches/propfind-cache/twistedcaldav/test/util.py	2008-04-24 21:30:23 UTC (rev 2343)
+++ CalendarServer/branches/propfind-cache/twistedcaldav/test/util.py	2008-04-24 21:41:09 UTC (rev 2344)
@@ -15,8 +15,35 @@
 ##
 
 import twisted.web2.dav.test.util
+from twisted.web2.http import HTTPError, StatusResponse
 
 from twistedcaldav.static import CalDAVFile
 
+
 class TestCase(twisted.web2.dav.test.util.TestCase):
     resource_class = CalDAVFile
+
+
+class InMemoryPropertyStore(object):
+    def __init__(self):
+        self._properties = {}
+
+    def get(self, qname):
+        data = self._properties.get(qname)
+        if data is None:
+            raise HTTPError(StatusResponse(404, "No such property"))
+        return data
+
+    def set(self, property):
+        self._properties[property.qname()] = property
+
+
+class StubCacheChangeNotifier(object):
+    dataChangedCount = 0
+    propertyChangedCount = 0
+
+    def dataChanged(self):
+        self.dataChangedCount += 1
+
+    def propertyChanged(self):
+        self.propertyChangedCount += 1

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20080424/67938d9b/attachment-0001.html


More information about the calendarserver-changes mailing list