[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/dav/ Fix the DAV breakage introduced by r26364.

Philipp von Weitershausen philikon at philikon.de
Tue Jul 20 11:37:40 EDT 2004


Log message for revision 26634:
  Fix the DAV breakage introduced by r26364.
  
  The PROPFIND view before didn't care whether schema adapters provided
  the values as attributes or methods; if they were methods, it called
  them.  This is not possible anymore as of r26364, which broke DAV
  severely.  This fix turns all those methods into getattr'able
  attributes (using properties) and finally provides a test for
  DAVSchemaAdapter (this bug did not show up in tests at all).


Changed:
  U   Zope3/trunk/src/zope/app/dav/adapter.py
  A   Zope3/trunk/src/zope/app/dav/tests/test_adapter.py


-=-
Modified: Zope3/trunk/src/zope/app/dav/adapter.py
===================================================================
--- Zope3/trunk/src/zope/app/dav/adapter.py	2004-07-19 17:09:02 UTC (rev 26633)
+++ Zope3/trunk/src/zope/app/dav/adapter.py	2004-07-20 15:37:40 UTC (rev 26634)
@@ -38,13 +38,14 @@
         if IReadDirectory(self.context, None) is not None:
             value = value + '/'
         return value
+    displayname = property(displayname)
 
     def creationdate(self):
-        value = IDCTimes(self.context).created
-        if value is None:
+        dc = IDCTimes(self.context, None)
+        if dc is None or dc.created is None:
             return ''
-        value = value.strftime('%Y-%m-%d %TZ')
-        return value
+        return dc.created.strftime('%Y-%m-%d %TZ')
+    creationdate = property(creationdate)
 
     def resourcetype(self):
         value = IReadDirectory(self.context, None)
@@ -53,17 +54,22 @@
             node = xml.createElement('collection')
             return node
         return ''
+    resourcetype = property(resourcetype)
 
     def getcontentlength(self):
-        value = ISized(self.context).sizeForDisplay()
-        return str(value)
+        sized = ISized(self.context, None)
+        if sized is None:
+            return ''
+        return str(sized.sizeForDisplay())
+    getcontentlength = property(getcontentlength)
 
     def getlastmodified(self):
-        value = IDCTimes(self.context).modified
-        if value is None:
+        dc = IDCTimes(self.context, None)
+        if dc is None or dc.created is None:
             return ''
-        value = value.strftime('%a, %d %b %Y %H:%M:%S GMT')
-        return value
+        return dc.modified.strftime('%a, %d %b %Y %H:%M:%S GMT')
+    getlastmodified = property(getlastmodified)
 
     def executable(self):
         return ''
+    executable = property(executable)

Added: Zope3/trunk/src/zope/app/dav/tests/test_adapter.py
===================================================================
--- Zope3/trunk/src/zope/app/dav/tests/test_adapter.py	2004-07-19 17:09:02 UTC (rev 26633)
+++ Zope3/trunk/src/zope/app/dav/tests/test_adapter.py	2004-07-20 15:37:40 UTC (rev 26634)
@@ -0,0 +1,150 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Test DAVSchemaAdapter
+
+$Id$
+"""
+import unittest
+from zope.testing.doctestunit import DocTestSuite
+
+from zope.interface import Interface, implements
+
+from zope.app.tests import ztapi
+from zope.app.tests.placelesssetup import setUp, tearDown
+from zope.app.size.interfaces import ISized
+from zope.app.filerepresentation.interfaces import IReadDirectory
+
+import zope.app.location
+from zope.app.dublincore.interfaces import IWriteZopeDublinCore
+from zope.app.annotation.interfaces import IAnnotatable, IAttributeAnnotatable
+from zope.app.annotation.interfaces import IAnnotations
+from zope.app.annotation.attribute import AttributeAnnotations
+from zope.app.dublincore.annotatableadapter import ZDCAnnotatableAdapter
+
+from zope.app.location.interfaces import ILocation
+from zope.app.traversing.interfaces import IPhysicallyLocatable
+from zope.app.location.traversing import LocationPhysicallyLocatable
+
+class IRobot(Interface):
+    pass
+
+class Robot(zope.app.location.Location):
+    implements(IRobot, IAttributeAnnotatable)
+
+class RobotSize(object):
+    implements(ISized)
+
+    def __init__(self, context):
+	self.context = context
+
+    def sizeForSorting(self):
+	return None
+
+    def sizeForDisplay(self):
+	return u"1 robot unit"
+
+class RobotDirectory(object):
+    implements(IReadDirectory)
+
+    def __init__(self, context):
+	self.context = context
+
+def test_DAVSchemaAdapter():
+    """Before we can start off, we need to provide a few basic components.
+    Let's setup the necessary services and a minimum of the location
+    machinery:
+
+    >>> setUp()
+    >>> ztapi.provideAdapter(ILocation, IPhysicallyLocatable,
+    ...                      LocationPhysicallyLocatable)
+
+    Now, let's make an object and give it a name.  We can at least
+    rely on it being locatable:
+
+    >>> bender = Robot()
+    >>> bender.__name__ = u'bender'
+
+    With these minimal circumstances, the DAV adapter should still work:
+
+    >>> from zope.app.dav.adapter import DAVSchemaAdapter
+    >>> dav = DAVSchemaAdapter(bender)
+
+    >>> dav.displayname
+    u'bender'
+    >>> dav.creationdate, dav.resourcetype, dav.getcontentlength
+    ('', '', '')
+    >>> dav.getlastmodified, dav.executable
+    ('', '')
+
+    Now, after that dull test, let's provide some actual meta-data.
+    First, we have to set up the necessary adapter:
+
+    >>> ztapi.provideAdapter(IAnnotatable, IAnnotations, AttributeAnnotations)
+    >>> ztapi.provideAdapter(IAnnotatable, IWriteZopeDublinCore,
+    ...                      ZDCAnnotatableAdapter)
+    >>> dc = IWriteZopeDublinCore(bender)
+
+    For example, we can set a creation date and a last modified date:
+
+    >>> from datetime import datetime
+    >>> y2k = datetime(1999, 12, 31, 23, 59, 59)
+    >>> y3k = datetime(2999, 12, 31, 23, 59, 59)
+    >>> dc.created = y2k
+    >>> dc.modified = y3k
+
+    Now, exercise the whole IDAVSchema again:
+
+    >>> dav.displayname
+    u'bender'
+    >>> dav.creationdate == y2k.strftime('%Y-%m-%d %TZ')
+    True
+    >>> dav.resourcetype, dav.getcontentlength
+    ('', '')
+    >>> dav.getlastmodified == y3k.strftime('%a, %d %b %Y %H:%M:%S GMT')
+    True
+
+    To make `getcontentlength` work, we can provide our adapter to
+    `ISized`:
+
+    >>> ztapi.provideAdapter(IRobot, ISized, RobotSize)
+    >>> dav.getcontentlength
+    '1 robot unit'
+
+    And if robots were directories:
+
+    >>> ztapi.provideAdapter(IRobot, IReadDirectory, RobotDirectory)
+
+    then the adapter would actually tell us:
+
+    >>> dav.displayname
+    u'bender/'
+
+    >>> import xml.dom.minidom
+    >>> isinstance(dav.resourcetype, xml.dom.minidom.Element)
+    True
+    >>> dav.resourcetype.localName
+    'collection'
+
+    All there is now to it is cleaning up after ourselves:
+
+    >>> tearDown()
+    """
+
+def test_suite():
+    return unittest.TestSuite((
+            DocTestSuite(),
+            ))
+
+if __name__ == '__main__':
+    unittest.main()


Property changes on: Zope3/trunk/src/zope/app/dav/tests/test_adapter.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native



More information about the Zope3-Checkins mailing list