[Checkins] SVN: z3c.dav/trunk/src/z3c/dav/ Remove the
`assertMSPropertyValue` method and replace it with by testing
Michael Kerrin
michael.kerrin at openapp.ie
Sun May 6 11:11:12 EDT 2007
Log message for revision 75567:
Remove the `assertMSPropertyValue` method and replace it with by testing
the whole response element.
Changed:
U z3c.dav/trunk/src/z3c/dav/ftests/dav.py
U z3c.dav/trunk/src/z3c/dav/tests/test_propfind.py
D z3c.dav/trunk/src/z3c/dav/tests/utils.py
-=-
Modified: z3c.dav/trunk/src/z3c/dav/ftests/dav.py
===================================================================
--- z3c.dav/trunk/src/z3c/dav/ftests/dav.py 2007-05-06 14:41:45 UTC (rev 75566)
+++ z3c.dav/trunk/src/z3c/dav/ftests/dav.py 2007-05-06 15:11:11 UTC (rev 75567)
@@ -39,7 +39,6 @@
from z3c.dav.publisher import WebDAVRequest
from z3c.dav.properties import DAVProperty
-from z3c.dav.tests.utils import TestMultiStatusBody
import z3c.dav.testing
@@ -121,7 +120,7 @@
self.xmlDataSource[0][0].append(elem)
-class DAVTestCase(z3c.dav.testing.WebDAVTestCase, TestMultiStatusBody):
+class DAVTestCase(z3c.dav.testing.WebDAVTestCase):
layer = WebDAVLayer
Modified: z3c.dav/trunk/src/z3c/dav/tests/test_propfind.py
===================================================================
--- z3c.dav/trunk/src/z3c/dav/tests/test_propfind.py 2007-05-06 14:41:45 UTC (rev 75566)
+++ z3c.dav/trunk/src/z3c/dav/tests/test_propfind.py 2007-05-06 15:11:11 UTC (rev 75567)
@@ -46,7 +46,6 @@
from test_proppatch import unauthProperty, UnauthorizedPropertyStorage, \
IUnauthorizedPropertyStorage
-from utils import TestMultiStatusBody
class TestRequest(z3c.dav.publisher.WebDAVRequest):
@@ -407,7 +406,7 @@
self.errors.append((exc_info, request))
-class PROPFINDTestRender(unittest.TestCase, TestMultiStatusBody):
+class PROPFINDTestRender(unittest.TestCase):
# 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.
@@ -434,12 +433,6 @@
# 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")
- self.assertMSPropertyValue(response, "{DAVtest:}unauthprop")
-
assertXMLEqual(response, """<ns0:response xmlns:ns0="DAV:">
<ns0:href xmlns:ns0="DAV:">/resource</ns0:href>
<ns0:propstat xmlns:ns0="DAV:" xmlns:ns01="DAVtest:">
@@ -596,8 +589,15 @@
response = propf.renderSelectedProperties(resource, request, props)
response = response()
- self.assertMSPropertyValue(response, "{DAVtest:}brokenprop",
- status = 500)
+ assertXMLEqual("""<response xmlns="DAV:">
+<href>/resource</href>
+<propstat>
+ <prop>
+ <ns1:brokenprop xmlns:ns1="DAVtest:" />
+ </prop>
+ <status>HTTP/1.1 500 Internal Server Error</status>
+</propstat>
+</response>""", response)
# now check that the error reporting utility caught the error.
self.assertEqual(len(self.errUtility.errors), 1)
@@ -620,10 +620,21 @@
# The PROPFIND method should return a 401 when the user is unauthorized
# to view a property.
- self.assertMSPropertyValue(response, "{DAVtest:}exampletextprop",
- text_value = "some text")
- self.assertMSPropertyValue(response, "{DAVtest:}unauthprop",
- status = 401)
+ assertXMLEqual("""<response xmlns="DAV:">
+<href>/resource</href>
+<propstat>
+ <prop>
+ <ns1:exampletextprop xmlns:ns1="DAVtest:">some text</ns1:exampletextprop>
+ </prop>
+ <status>HTTP/1.1 200 OK</status>
+</propstat>
+<propstat>
+ <prop>
+ <ns1:unauthprop xmlns:ns1="DAVtest:" />
+ </prop>
+ <status>HTTP/1.1 401 Unauthorized</status>
+</propstat>
+</response>""", response)
# PROPFIND does catch all exceptions during the main PROPFIND method
# but instead we need to make sure that the renderSelectedProperties
@@ -647,18 +658,19 @@
response = propf.renderAllProperties(resource, request, None)
response = response()
- self.assertEqual(len(response.findall("{DAV:}propstat")), 1)
- self.assertEqual(len(response.findall("{DAV:}propstat/{DAV:}prop")), 1)
+ # Note that the unauthprop is not included in the response.
+ assertXMLEqual("""<response xmlns="DAV:">
+<href>/resource</href>
+<propstat>
+ <prop>
+ <ns1:exampletextprop xmlns:ns1="DAVtest:">some text</ns1:exampletextprop>
+ <ns1:exampleintprop xmlns:ns1="DAVtest:">10</ns1:exampleintprop>
+ <resourcetype />
+ </prop>
+ <status>HTTP/1.1 200 OK</status>
+</propstat>
+</response>""", response)
- foundUnauthProp = False
- for prop in response.findall("{DAV:}propstat/{DAV:}prop")[0]:
- if prop.tag == "{DAVtest:}unauthprop":
- foundUnauthProp = True
-
- self.assert_(not foundUnauthProp,
- "The unauthprop should not be included in the all " \
- "property response since it has security restrictions.")
-
def test_renderAllProperties_unauthorized_included(self):
# If we request to render all properties, and request to render a
# property we ain't authorized via the 'include' element then we
@@ -676,11 +688,24 @@
response = propf.renderAllProperties(resource, request, includes)
response = response()
- self.assertEqual(len(response.findall("{DAV:}propstat")), 2)
+ assertXMLEqual("""<response xmlns="DAV:">
+<href>/resource</href>
+<propstat>
+ <prop>
+ <ns1:exampletextprop xmlns:ns1="DAVtest:">some text</ns1:exampletextprop>
+ <ns1:exampleintprop xmlns:ns1="DAVtest:">10</ns1:exampleintprop>
+ <resourcetype />
+ </prop>
+ <status>HTTP/1.1 200 OK</status>
+</propstat>
+<propstat>
+ <prop>
+ <ns1:unauthprop xmlns:ns1="DAVtest:" />
+ </prop>
+ <status>HTTP/1.1 401 Unauthorized</status>
+</propstat>
+</response>""", response)
- self.assertMSPropertyValue(
- response, "{DAVtest:}unauthprop", status = 401)
-
def test_renderAllProperties_broken_included(self):
# If we request to render all properties, and to forse render a
# broken property via the 'include' element then we should get
@@ -698,11 +723,24 @@
response = propf.renderAllProperties(resource, request, includes)
response = response()
- self.assertEqual(len(response.findall("{DAV:}propstat")), 2)
+ assertXMLEqual("""<response xmlns="DAV:">
+<href>/resource</href>
+<propstat>
+ <prop>
+ <ns1:exampletextprop xmlns:ns1="DAVtest:">some text</ns1:exampletextprop>
+ <ns1:exampleintprop xmlns:ns1="DAVtest:">10</ns1:exampleintprop>
+ <resourcetype />
+ </prop>
+ <status>HTTP/1.1 200 OK</status>
+</propstat>
+<propstat>
+ <prop>
+ <ns1:brokenprop xmlns:ns1="DAVtest:" />
+ </prop>
+ <status>HTTP/1.1 500 Internal Server Error</status>
+</propstat>
+</response>""", response)
- self.assertMSPropertyValue(
- response, "{DAVtest:}brokenprop", status = 500)
-
self.assertEqual(len(self.errUtility.errors), 1)
exc_info = self.errUtility.errors[0]
self.assertEqual(isinstance(exc_info[0][1], NotImplementedError), True)
@@ -815,6 +853,7 @@
</ns0:response></ns0:multistatus>
""")
+
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(PROPFINDBodyTestCase),
Deleted: z3c.dav/trunk/src/z3c/dav/tests/utils.py
===================================================================
--- z3c.dav/trunk/src/z3c/dav/tests/utils.py 2007-05-06 14:41:45 UTC (rev 75566)
+++ z3c.dav/trunk/src/z3c/dav/tests/utils.py 2007-05-06 15:11:11 UTC (rev 75567)
@@ -1,78 +0,0 @@
-##############################################################################
-# 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 z3c.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 z3c.etree.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))
More information about the Checkins
mailing list