[Checkins] SVN: zope.webdav/trunk/src/zope/webdav/ Add more tests
for the exceptions. This highlighted a
Michael Kerrin
michael.kerrin at openapp.biz
Sun Aug 27 09:22:31 EDT 2006
Log message for revision 69792:
Add more tests for the exceptions. This highlighted a
bug in the PROPFIND propname response handling where if
the property can't be rendered then the whole propname
response breaks. This is now fixed.
Also updated the TODO
Changed:
U zope.webdav/trunk/src/zope/webdav/TODO.txt
U zope.webdav/trunk/src/zope/webdav/exceptions/__init__.py
U zope.webdav/trunk/src/zope/webdav/exceptions/tests/test_multiviews.py
U zope.webdav/trunk/src/zope/webdav/ftests/dav.py
U zope.webdav/trunk/src/zope/webdav/propfind.py
U zope.webdav/trunk/src/zope/webdav/tests/test_propfind.py
A zope.webdav/trunk/src/zope/webdav/tests/utils.py
U zope.webdav/trunk/src/zope/webdav/widgets.py
-=-
Modified: zope.webdav/trunk/src/zope/webdav/TODO.txt
===================================================================
--- zope.webdav/trunk/src/zope/webdav/TODO.txt 2006-08-27 10:44:23 UTC (rev 69791)
+++ zope.webdav/trunk/src/zope/webdav/TODO.txt 2006-08-27 13:22:31 UTC (rev 69792)
@@ -11,9 +11,6 @@
started this process but gave up after a while. Hence we have the
z3-configure.zcml file. This should be a basis for *zope.app.webdav*.
-The ElemenetTree support should to be moved out into its own project, has
-it is probable of interest to others.
-
We need better integration with Zope3. That includes providing better support
for caching (ETags), and all the "IF*" headers defined in the HTTP and WebDAV
specs. Also the exceptions and there views are not neccessarly WebDAV specific
Modified: zope.webdav/trunk/src/zope/webdav/exceptions/__init__.py
===================================================================
--- zope.webdav/trunk/src/zope/webdav/exceptions/__init__.py 2006-08-27 10:44:23 UTC (rev 69791)
+++ zope.webdav/trunk/src/zope/webdav/exceptions/__init__.py 2006-08-27 13:22:31 UTC (rev 69792)
@@ -98,6 +98,8 @@
response = zope.webdav.utils.Response(
zope.webdav.utils.getObjectURL(error.resource, self.request))
response.status = davwidget.status
+ # we don't generate a propstat elements during this view so
+ # we just ignore the propstatdescription.
response.responsedescription += davwidget.responsedescription
multistatus.responses.append(response)
@@ -106,7 +108,7 @@
response = zope.webdav.utils.Response(
zope.webdav.utils.getObjectURL(
self.error.context, self.request))
- response.status = 424
+ response.status = 424 # Failed Dependency
multistatus.responses.append(response)
self.request.response.setStatus(207)
Modified: zope.webdav/trunk/src/zope/webdav/exceptions/tests/test_multiviews.py
===================================================================
--- zope.webdav/trunk/src/zope/webdav/exceptions/tests/test_multiviews.py 2006-08-27 10:44:23 UTC (rev 69791)
+++ zope.webdav/trunk/src/zope/webdav/exceptions/tests/test_multiviews.py 2006-08-27 13:22:31 UTC (rev 69792)
@@ -240,7 +240,35 @@
<ns0:status>HTTP/1.1 404 Not Found</ns0:status>
</ns0:response></ns0:multistatus>""")
+ def test_simple_not_seen_context(self):
+ # multi-status responses should contain a entry for the context
+ # corresponding to the request-uri.
+ resource = Resource()
+ resource1 = Resource()
+ resource1.__name__ = "secondresource"
+ error = zope.webdav.interfaces.WebDAVErrors(resource)
+ error.append(zope.webdav.interfaces.PropertyNotFound(
+ resource1, "{DAV:}getcontentlength", message = u"readonly field"))
+ request = TestRequest()
+ view = zope.webdav.exceptions.MultiStatusErrorView(error, request)
+ result = view()
+
+ self.assertEqual(request.response.getStatus(), 207)
+ self.assertEqual(request.response.getHeader("content-type"),
+ "application/xml")
+
+ assertXMLEqual(result, """<ns0:multistatus xmlns:ns0="DAV:">
+<ns0:response>
+ <ns0:href>/secondresource</ns0:href>
+ <ns0:status>HTTP/1.1 404 Not Found</ns0:status>
+</ns0:response>
+<ns0:response>
+ <ns0:href>/resource</ns0:href>
+ <ns0:status>HTTP/1.1 424 Failed Dependency</ns0:status>
+</ns0:response></ns0:multistatus>""")
+
+
def test_suite():
suite = unittest.TestSuite((
unittest.makeSuite(TestPropstatErrorView),
Modified: zope.webdav/trunk/src/zope/webdav/ftests/dav.py
===================================================================
--- zope.webdav/trunk/src/zope/webdav/ftests/dav.py 2006-08-27 10:44:23 UTC (rev 69791)
+++ zope.webdav/trunk/src/zope/webdav/ftests/dav.py 2006-08-27 13:22:31 UTC (rev 69792)
@@ -28,7 +28,6 @@
from zope import interface
from zope import component
from zope import schema
-from zope.publisher.http import status_reasons
from zope.app.testing.functional import HTTPTestCase, FunctionalTestSetup
from zope.security.proxy import removeSecurityProxy
from zope.app.folder.folder import Folder
@@ -43,9 +42,8 @@
from zope.webdav.properties import DAVProperty
import zope.webdav.coreproperties
from zope.etree.interfaces import IEtree
-from zope.etree.testing import assertXMLEqual
+from zope.webdav.tests.utils import TestMultiStatusBody
-
class IExamplePropertyStorage(interface.Interface):
exampleintprop = schema.Int(
@@ -219,7 +217,7 @@
del self.annots[tag]
-class DAVTestCase(HTTPTestCase):
+class DAVTestCase(HTTPTestCase, TestMultiStatusBody):
def setUp(self):
super(DAVTestCase, self).setUp()
@@ -453,55 +451,3 @@
xmlbody = etree.fromstring(respbody)
return response, xmlbody
-
- def assertMSPropertyValue(self, response, proptag, status = 200,
- tag = None, text_value = None,
- prop_element = None):
- # For the XML response element make sure that the proptag belongs
- # to the propstat element that has the given status.
- # - response - etree XML element
- # - proptag - tag name of the property we are testing
- # - status - integre status code
- # - tag -
- # - text_value -
- # - propelement - etree Element that we compare with the property
- # using zope.webdav.testing.assertXMLEqual
- self.assertEqual(response.tag, "{DAV:}response")
-
- # set to true if we found the property, under the correct status code
- found_property = False
-
- propstats = response.findall("{DAV:}propstat")
- for propstat in propstats:
- statusresp = propstat.findall("{DAV:}status")
- self.assertEqual(len(statusresp), 1)
-
- if statusresp[0].text == "HTTP/1.1 %d %s" %(
- status, status_reasons[status]):
- # make sure that proptag is in this propstat element
- props = propstat.findall("{DAV:}prop/%s" % proptag)
- self.assertEqual(len(props), 1)
- prop = props[0]
-
- # now test the the tag and text match this propstat element
- if tag is not None:
- ## XXX - this is not right.
- ## self.assertEqual(len(prop), 1)
- self.assertEqual(prop[0].tag, tag)
- else:
- self.assertEqual(len(prop), 0)
- self.assertEqual(prop.text, text_value)
-
- if prop_element is not None:
- assertXMLEqual(prop, prop_element)
-
- found_property = True
- else:
- # make sure that proptag is NOT in this propstat element
- props = propstat.findall("{DAV:}prop/%s" % proptag)
- self.assertEqual(len(props), 0)
-
- self.assert_(
- found_property,
- "The property %s doesn't exist for the status code %d" %(proptag,
- status))
Modified: zope.webdav/trunk/src/zope/webdav/propfind.py
===================================================================
--- zope.webdav/trunk/src/zope/webdav/propfind.py 2006-08-27 10:44:23 UTC (rev 69791)
+++ zope.webdav/trunk/src/zope/webdav/propfind.py 2006-08-27 13:22:31 UTC (rev 69792)
@@ -148,10 +148,13 @@
response = zope.webdav.utils.Response(
zope.webdav.utils.getObjectURL(ob, req))
+ etree = component.getUtility(IEtree)
+
for davprop, adapter in \
zope.webdav.properties.getAllProperties(ob, req):
- davwidget = zope.webdav.properties.getWidget(davprop, adapter, req)
- response.addProperty(200, davwidget.renderName())
+ rendered_name = etree.Element(etree.QName(davprop.namespace,
+ davprop.__name__))
+ response.addProperty(200, rendered_name)
return response
@@ -185,7 +188,7 @@
davwidget = zope.webdav.properties.getWidget(
davprop, adapter, req)
propstat = response.getPropstat(200)
- propstat.properties.append(davwidget.render())
+ rendered_el = davwidget.render()
except Exception, error:
exc_info = sys.exc_info()
@@ -200,6 +203,8 @@
propstat.responsedescription += error_view.propstatdescription
response.responsedescription += error_view.responsedescription
- propstat.properties.append(etree.Element(prop.tag))
+ rendered_el = etree.Element(prop.tag)
+ propstat.properties.append(rendered_el)
+
return response
Modified: zope.webdav/trunk/src/zope/webdav/tests/test_propfind.py
===================================================================
--- zope.webdav/trunk/src/zope/webdav/tests/test_propfind.py 2006-08-27 10:44:23 UTC (rev 69791)
+++ zope.webdav/trunk/src/zope/webdav/tests/test_propfind.py 2006-08-27 13:22:31 UTC (rev 69792)
@@ -39,6 +39,8 @@
from zope.etree.testing import etreeSetup, etreeTearDown, assertXMLEqual
from zope.etree.interfaces import IEtree
+from utils import TestMultiStatusBody
+
class TestRequest(zope.webdav.publisher.WebDAVRequest):
def __init__(self, properties = None, environ = {}):
@@ -174,13 +176,22 @@
extratextprop = schema.Text(
title = u"Property with no storage")
+class IBrokenPropertyStorage(interface.Interface):
+
+ brokenprop = schema.Text(
+ title = u"Property which does not render")
+
exampleIntProperty = zope.webdav.properties.DAVProperty(
"{DAVtest:}exampleintprop", IExamplePropertyStorage)
exampleTextProperty = zope.webdav.properties.DAVProperty(
"{DAVtest:}exampletextprop", IExamplePropertyStorage)
extraTextProperty = zope.webdav.properties.DAVProperty(
"{DAVtest:}extratextprop", IExtraPropertyStorage)
+brokenProperty = zope.webdav.properties.DAVProperty(
+ "{DAVtest:}brokenprop", IBrokenPropertyStorage)
+brokenProperty.restricted = True
+
class ExamplePropertyStorage(object):
interface.implements(IExamplePropertyStorage)
@@ -200,6 +211,17 @@
exampletextprop = _getproperty("text", default = u"")
+class BrokenPropertyStorage(object):
+ interface.implements(IBrokenPropertyStorage)
+
+ def __init__(self, context, request):
+ pass
+
+ @property
+ def brokenprop(self):
+ raise NotImplementedError("The property brokenprop is not implemented.")
+
+
class IResource(interface.Interface):
text = schema.TextLine(
@@ -273,10 +295,15 @@
provided = zope.webdav.interfaces.IDAVProperty)
gsm.registerUtility(zope.webdav.coreproperties.resourcetype,
name = "{DAV:}resourcetype")
+ gsm.registerUtility(brokenProperty, name = "{DAVtest:}brokenprop",
+ provided = zope.webdav.interfaces.IDAVProperty)
gsm.registerAdapter(ExamplePropertyStorage,
(IResource, zope.webdav.interfaces.IWebDAVRequest),
provided = IExamplePropertyStorage)
+ gsm.registerAdapter(BrokenPropertyStorage,
+ (IResource, zope.webdav.interfaces.IWebDAVRequest),
+ provided = IBrokenPropertyStorage)
gsm.registerAdapter(zope.webdav.coreproperties.ResourceTypeAdapter)
gsm.registerAdapter(DummyResourceURL,
@@ -314,10 +341,15 @@
provided = zope.webdav.interfaces.IDAVProperty)
gsm.unregisterUtility(zope.webdav.coreproperties.resourcetype,
name = "{DAV:}resourcetype")
+ gsm.unregisterUtility(brokenProperty, name = "{DAVtest:}brokenprop",
+ provided = zope.webdav.interfaces.IDAVProperty)
gsm.unregisterAdapter(ExamplePropertyStorage,
(IResource, zope.webdav.interfaces.IWebDAVRequest),
provided = IExamplePropertyStorage)
+ gsm.unregisterAdapter(BrokenPropertyStorage,
+ (IResource, zope.webdav.interfaces.IWebDAVRequest),
+ provided = IBrokenPropertyStorage)
gsm.unregisterAdapter(zope.webdav.coreproperties.ResourceTypeAdapter)
gsm.unregisterAdapter(DummyResourceURL,
@@ -339,7 +371,7 @@
zope.webdav.interfaces.IWebDAVRequest))
-class PROPFINDTestRender(unittest.TestCase):
+class PROPFINDTestRender(unittest.TestCase, TestMultiStatusBody):
# Test all the methods that render a resource into a `response' XML
# element. We are going to need to register the DAV widgets for
# text and int properties.
@@ -356,10 +388,20 @@
propf = PROPFIND(None, None)
response = propf.renderPropnames(resource, request, None)
- assertXMLEqual(response(), """<ns0:response xmlns:ns0="DAV:">
+
+ # call the response to render to an XML fragment.
+ response = response()
+
+ self.assertMSPropertyValue(response, "{DAVtest:}exampletextprop")
+ self.assertMSPropertyValue(response, "{DAVtest:}exampleintprop")
+ self.assertMSPropertyValue(response, "{DAV:}resourcetype")
+ self.assertMSPropertyValue(response, "{DAVtest:}brokenprop")
+
+ assertXMLEqual(response, """<ns0:response xmlns:ns0="DAV:">
<ns0:href xmlns:ns0="DAV:">/resource</ns0:href>
<ns0:propstat xmlns:ns0="DAV:" xmlns:ns01="DAVtest:">
<ns0:prop xmlns:ns0="DAV:">
+ <ns01:brokenprop xmlns:ns0="DAVtest:"/>
<ns01:exampletextprop xmlns:ns0="DAVtest:"/>
<ns01:exampleintprop xmlns:ns0="DAVtest:"/>
<ns0:resourcetype />
Added: zope.webdav/trunk/src/zope/webdav/tests/utils.py
===================================================================
--- zope.webdav/trunk/src/zope/webdav/tests/utils.py 2006-08-27 10:44:23 UTC (rev 69791)
+++ zope.webdav/trunk/src/zope/webdav/tests/utils.py 2006-08-27 13:22:31 UTC (rev 69792)
@@ -0,0 +1,78 @@
+##############################################################################
+# Copyright (c) 2006 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.
+##############################################################################
+"""Miscellanous methods used for testing different parts of the WebDAV
+implementation.
+
+$Id$
+"""
+__docformat__ = 'restructuredtext'
+
+from zope.publisher.http import status_reasons
+from zope.etree.testing import assertXMLEqual
+
+class TestMultiStatusBody(object):
+ #
+ # If you need to use any methods in this just make sure that your test case
+ # class extends this one.
+ #
+
+ def assertMSPropertyValue(self, response, proptag, status = 200,
+ tag = None, text_value = None,
+ prop_element = None):
+ # For the XML response element make sure that the proptag belongs
+ # to the propstat element that has the given status.
+ # - response - etree XML element
+ # - proptag - tag name of the property we are testing
+ # - status - integre status code
+ # - tag -
+ # - text_value -
+ # - propelement - etree Element that we compare with the property
+ # using zope.webdav.testing.assertXMLEqual
+ self.assertEqual(response.tag, "{DAV:}response")
+
+ # set to true if we found the property, under the correct status code
+ found_property = False
+
+ propstats = response.findall("{DAV:}propstat")
+ for propstat in propstats:
+ statusresp = propstat.findall("{DAV:}status")
+ self.assertEqual(len(statusresp), 1)
+
+ if statusresp[0].text == "HTTP/1.1 %d %s" %(
+ status, status_reasons[status]):
+ # make sure that proptag is in this propstat element
+ props = propstat.findall("{DAV:}prop/%s" % proptag)
+ self.assertEqual(len(props), 1)
+ prop = props[0]
+
+ # now test the the tag and text match this propstat element
+ if tag is not None:
+ ## XXX - this is not right.
+ ## self.assertEqual(len(prop), 1)
+ self.assertEqual(prop[0].tag, tag)
+ else:
+ self.assertEqual(len(prop), 0)
+ self.assertEqual(prop.text, text_value)
+
+ if prop_element is not None:
+ assertXMLEqual(prop, prop_element)
+
+ found_property = True
+ else:
+ # make sure that proptag is NOT in this propstat element
+ props = propstat.findall("{DAV:}prop/%s" % proptag)
+ self.assertEqual(len(props), 0)
+
+ self.assert_(
+ found_property,
+ "The property %s doesn't exist for the status code %d" %(proptag,
+ status))
Property changes on: zope.webdav/trunk/src/zope/webdav/tests/utils.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: zope.webdav/trunk/src/zope/webdav/widgets.py
===================================================================
--- zope.webdav/trunk/src/zope/webdav/widgets.py 2006-08-27 10:44:23 UTC (rev 69791)
+++ zope.webdav/trunk/src/zope/webdav/widgets.py 2006-08-27 13:22:31 UTC (rev 69792)
@@ -55,10 +55,6 @@
raise NotImplementedError, \
"please implemented this method in a subclass of DAVWidget."
- def renderName(self):
- etree = component.getUtility(IEtree)
- return etree.Element(etree.QName(self.namespace, self.name))
-
def render(self):
etree = component.getUtility(IEtree)
el = etree.Element(etree.QName(self.namespace, self.name))
More information about the Checkins
mailing list