[Checkins] SVN: z3c.dav/trunk/src/z3c/dav/ftests/ Remove dependency of the functional tests on zope.app.file, in preparation of

Michael Kerrin michael.kerrin at openapp.ie
Mon May 7 11:31:51 EDT 2007


Log message for revision 75613:
  Remove dependency of the functional tests on zope.app.file, in preparation of
  moving zope.app.file into a WebDAV add-on package.
  

Changed:
  U   z3c.dav/trunk/src/z3c/dav/ftests/dav.py
  U   z3c.dav/trunk/src/z3c/dav/ftests/ftesting-locking.zcml
  U   z3c.dav/trunk/src/z3c/dav/ftests/ftesting.zcml
  U   z3c.dav/trunk/src/z3c/dav/ftests/test_propfind.py
  U   z3c.dav/trunk/src/z3c/dav/ftests/test_proppatch.py

-=-
Modified: z3c.dav/trunk/src/z3c/dav/ftests/dav.py
===================================================================
--- z3c.dav/trunk/src/z3c/dav/ftests/dav.py	2007-05-07 13:45:06 UTC (rev 75612)
+++ z3c.dav/trunk/src/z3c/dav/ftests/dav.py	2007-05-07 15:31:50 UTC (rev 75613)
@@ -31,7 +31,6 @@
 
 from zope.security.proxy import removeSecurityProxy
 from zope.app.folder.folder import Folder
-from zope.app.file.file import File
 from zope.app.publication.http import HTTPPublication
 from zope.security.management import newInteraction, endInteraction
 from zope.security.testing import Principal, Participation
@@ -120,6 +119,19 @@
             self.xmlDataSource[0][0].append(elem)
 
 
+class IResource(interface.Interface):
+
+    title = interface.Attribute("Title of resource")
+
+class Resource(object):
+    interface.implements(IResource)
+
+    def __init__(self, data, contentType, title = None):
+        self.data = data
+        self.contentType = contentType
+        self.title = title
+
+
 class DAVTestCase(z3c.dav.testing.WebDAVTestCase):
 
     layer = WebDAVLayer
@@ -159,9 +171,8 @@
         return collection[id]
 
     def addResource(self, path, content, title = None, contentType = ''):
-        resource = File(data = content, contentType = contentType)
-        if title is not None:
-            IWriteZopeDublinCore(resource).title = title
+        resource = Resource(data = content, contentType = contentType,
+                            title = title)
         return self.createObject(path, resource)
 
     def addCollection(self, path, title = None):
@@ -195,7 +206,7 @@
         self.createObject("/b", Folder())
 
     def checkPropfind(self, path = "/", basic = None, env = {},
-                      properties = None):
+                      properties = None, handle_errors = True):
         # - properties if set is a string containing the contents of the
         #   propfind XML element has specified in the WebDAV spec.
         if properties is not None:
@@ -215,7 +226,8 @@
             env["REQUEST_METHOD"] = "PROPFIND"
 
         response = self.publish(path, basic = basic, env = env,
-                                request_body = body)
+                                request_body = body,
+                                handle_errors = handle_errors)
 
         self.assertEqual(response.getStatus(), 207)
         self.assertEqual(response.getHeader("content-type"), "application/xml")

Modified: z3c.dav/trunk/src/z3c/dav/ftests/ftesting-locking.zcml
===================================================================
--- z3c.dav/trunk/src/z3c/dav/ftests/ftesting-locking.zcml	2007-05-07 13:45:06 UTC (rev 75612)
+++ z3c.dav/trunk/src/z3c/dav/ftests/ftesting-locking.zcml	2007-05-07 15:31:50 UTC (rev 75613)
@@ -2,7 +2,6 @@
 
   <include package="z3c.dav" file="ftesting.zcml" />
 
-  <include package="zope.app.file" />
   <include package="zope.app.keyreference" />
 
   <include package="zope.locking" />

Modified: z3c.dav/trunk/src/z3c/dav/ftests/ftesting.zcml
===================================================================
--- z3c.dav/trunk/src/z3c/dav/ftests/ftesting.zcml	2007-05-07 13:45:06 UTC (rev 75612)
+++ z3c.dav/trunk/src/z3c/dav/ftests/ftesting.zcml	2007-05-07 15:31:50 UTC (rev 75613)
@@ -2,8 +2,6 @@
 
   <include package="z3c.dav" file="ftesting.zcml" />
 
-  <include package="zope.app.file" />
-
   <!--
       Some random bits.
     -->
@@ -11,6 +9,7 @@
      name="{DAVtest:}unauthprop"
      component="z3c.dav.tests.test_proppatch.unauthProperty"
      />
+
   <adapter
      factory="z3c.dav.tests.test_proppatch.UnauthorizedPropertyStorage"
      for="zope.interface.Interface
@@ -22,10 +21,12 @@
      name="{DAVtest:}exampletextprop"
      component="z3c.dav.ftests.dav.exampleTextProperty"
      />
+
   <utility
      name="{DAVtest:}exampleintprop"
      component="z3c.dav.ftests.dav.exampleIntProperty"
      />
+
   <adapter
      factory="z3c.dav.ftests.dav.ExamplePropertyStorage"
      for="zope.interface.Interface

Modified: z3c.dav/trunk/src/z3c/dav/ftests/test_propfind.py
===================================================================
--- z3c.dav/trunk/src/z3c/dav/ftests/test_propfind.py	2007-05-07 13:45:06 UTC (rev 75612)
+++ z3c.dav/trunk/src/z3c/dav/ftests/test_propfind.py	2007-05-07 15:31:50 UTC (rev 75613)
@@ -66,7 +66,7 @@
 
         self.assertEqual(response.getStatus(), 422)
 
-    def test_simplepropfind_textxml(self):
+    def test_simplepropfind_for_resourcetype(self):
         body = """<?xml version="1.0" encoding="utf-8" ?>
 <ff0:propfind xmlns:ff0="DAV:">
   <ff0:prop>
@@ -76,15 +76,20 @@
         httpresponse = self.checkPropfind(
             "/", env = {"DEPTH": "0", "CONTENT_TYPE": "text/xml"},
             properties = "<D:prop><D:resourcetype/></D:prop>")
-        self.assertEqual(len(httpresponse.getMSResponses()), 1)
 
-        resourcetype = httpresponse.getMSProperty(
-            "http://localhost/", "{DAV:}resourcetype")
         z3c.etree.testing.assertXMLEqual(
-            """<resourcetype xmlns="DAV:">
-                 <collection />
-               </resourcetype>""",
-            resourcetype)
+            """<multistatus xmlns="DAV:">
+<response>
+  <href>http://localhost/</href>
+  <propstat>
+    <prop>
+      <resourcetype><collection /></resourcetype>
+    </prop>
+    <status>HTTP/1.1 200 OK</status>
+  </propstat>
+</response>
+</multistatus>""",
+            httpresponse.getBody())
 
     def test_propnames_on_collection(self):
         collection = self.addCollection("/coll")
@@ -92,126 +97,49 @@
         httpresponse = self.checkPropfind(
             "/coll", env = {"DEPTH": "0"}, properties = "<D:propname />")
 
-        self.assertEqual(len(httpresponse.getMSResponses()), 1)
-
         z3c.etree.testing.assertXMLEqual(
-            '<resourcetype xmlns="DAV:" />',
-            httpresponse.getMSProperty(
-                "http://localhost/coll/", "{DAV:}resourcetype"))
-        z3c.etree.testing.assertXMLEqual(
-            '<creationdate xmlns="DAV:" />',
-            httpresponse.getMSProperty(
-                "http://localhost/coll/", "{DAV:}creationdate"))
-        z3c.etree.testing.assertXMLEqual(
-            '<displayname xmlns="DAV:" />',
-            httpresponse.getMSProperty(
-                "http://localhost/coll/", "{DAV:}displayname"))
-        z3c.etree.testing.assertXMLEqual(
-            '<getlastmodified xmlns="DAV:" />',
-            httpresponse.getMSProperty(
-                "http://localhost/coll/", "{DAV:}getlastmodified"))
+            """<multistatus xmlns="DAV:">
+<response>
+  <href>http://localhost/coll/</href>
+  <propstat>
+    <prop>
+      <creationdate />
+      <displayname />
+      <ns1:exampletextprop xmlns:ns1="DAVtest:" />
+      <getlastmodified />
+      <resourcetype />
+      <ns1:exampleintprop xmlns:ns1="DAVtest:" />
+      <ns1:unauthprop xmlns:ns1="DAVtest:" />
+    </prop>
+    <status>HTTP/1.1 200 OK</status>
+  </propstat>
+</response>
+</multistatus>""",
+            httpresponse.getBody())
 
-    def test_propnames_on_resource(self):
-        self.addResource("/r1", "some content")
-        
-        httpresponse = self.checkPropfind(
-            "/r1", env = {"DEPTH": "0"}, properties = "<D:propname />")
-
-        self.assertEqual(len(httpresponse.getMSResponses()), 1)
-
-        z3c.etree.testing.assertXMLEqual(
-            '<resourcetype xmlns="DAV:" />',
-            httpresponse.getMSProperty(
-                "http://localhost/r1", "{DAV:}resourcetype"))
-        z3c.etree.testing.assertXMLEqual(
-            '<creationdate xmlns="DAV:" />',
-            httpresponse.getMSProperty(
-                "http://localhost/r1", "{DAV:}creationdate"))
-        z3c.etree.testing.assertXMLEqual(
-            '<displayname xmlns="DAV:" />',
-            httpresponse.getMSProperty(
-                "http://localhost/r1", "{DAV:}displayname"))
-        z3c.etree.testing.assertXMLEqual(
-            '<getlastmodified xmlns="DAV:" />',
-            httpresponse.getMSProperty(
-                "http://localhost/r1", "{DAV:}getlastmodified"))
-        z3c.etree.testing.assertXMLEqual(
-            '<getcontenttype xmlns="DAV:" />',
-            httpresponse.getMSProperty(
-                "http://localhost/r1", "{DAV:}getcontenttype"))
-        z3c.etree.testing.assertXMLEqual(
-            '<getcontentlength xmlns="DAV:" />',
-            httpresponse.getMSProperty(
-                "http://localhost/r1", "{DAV:}getcontentlength"))
-        z3c.etree.testing.assertXMLEqual(
-            '<getcontentlanguage xmlns="DAV:" />',
-            httpresponse.getMSProperty(
-                "http://localhost/r1", "{DAV:}getcontentlanguage"))
-        z3c.etree.testing.assertXMLEqual(
-            '<getetag xmlns="DAV:" />',
-            httpresponse.getMSProperty(
-                "http://localhost/r1", "{DAV:}getetag"))
-
     def test_allprop(self):
         collection = self.addCollection("/coll", title = u"Test Collection")
         httpresponse = self.checkPropfind(
             "/coll", env = {"DEPTH": "0"}, properties = "<D:allprop />")
 
-        self.assertEqual(len(httpresponse.getMSResponses()), 1)
-
         z3c.etree.testing.assertXMLEqual(
-            """<resourcetype xmlns="DAV:">
-                 <collection />
-               </resourcetype>""",
-            httpresponse.getMSProperty(
-                "http://localhost/coll/", "{DAV:}resourcetype"))
-        z3c.etree.testing.assertXMLEqual(
-            """<displayname xmlns="DAV:">Test Collection</displayname>""",
-            httpresponse.getMSProperty(
-                "http://localhost/coll/", "{DAV:}displayname"))
+            """<multistatus xmlns="DAV:">
+<response>
+  <href>http://localhost/coll/</href>
+  <propstat>
+    <prop>
+      <creationdate />
+      <displayname>Test Collection</displayname>
+      <getlastmodified />
+      <resourcetype><collection /></resourcetype>
+      <ns1:exampleintprop xmlns:ns1="DAVtest:">0</ns1:exampleintprop>
+    </prop>
+    <status>HTTP/1.1 200 OK</status>
+  </propstat>
+</response>
+</multistatus>""",
+            httpresponse.getBody())
 
-    def test_allprop_on_resource(self):
-        collection = self.addResource("/r1", "test resource content",
-                                      title = u"Test Resource")
-
-        httpresponse = self.checkPropfind(
-            "/r1", env = {"DEPTH": "0"}, properties = "<D:allprop />")
-
-        self.assertEqual(len(httpresponse.getMSResponses()), 1)
-
-        z3c.etree.testing.assertXMLEqual(
-            '<resourcetype xmlns="DAV:" />',
-            httpresponse.getMSProperty(
-                "http://localhost/r1", "{DAV:}resourcetype"))
-        z3c.etree.testing.assertXMLEqual(
-            '<creationdate xmlns="DAV:" />',
-            httpresponse.getMSProperty(
-                "http://localhost/r1", "{DAV:}creationdate"))
-        z3c.etree.testing.assertXMLEqual(
-            '<displayname xmlns="DAV:">Test Resource</displayname>',
-            httpresponse.getMSProperty(
-                "http://localhost/r1", "{DAV:}displayname"))
-        z3c.etree.testing.assertXMLEqual(
-            '<getlastmodified xmlns="DAV:" />',
-            httpresponse.getMSProperty(
-                "http://localhost/r1", "{DAV:}getlastmodified"))
-        z3c.etree.testing.assertXMLEqual(
-            '<getcontenttype xmlns="DAV:" />',
-            httpresponse.getMSProperty(
-                "http://localhost/r1", "{DAV:}getcontenttype"))
-        z3c.etree.testing.assertXMLEqual(
-            '<getcontentlength xmlns="DAV:">21</getcontentlength>',
-            httpresponse.getMSProperty(
-                "http://localhost/r1", "{DAV:}getcontentlength"))
-        z3c.etree.testing.assertXMLEqual(
-            '<getcontentlanguage xmlns="DAV:" />',
-            httpresponse.getMSProperty(
-                "http://localhost/r1", "{DAV:}getcontentlanguage"))
-        z3c.etree.testing.assertXMLEqual(
-            '<getetag xmlns="DAV:" />',
-            httpresponse.getMSProperty(
-                "http://localhost/r1", "{DAV:}getetag"))
-
     def test_allprop_by_default(self):
         self.addCollection("/coll")
         httpresponse = self.checkPropfind("/coll",
@@ -326,10 +254,9 @@
                                     "http://localhost/r1"])
 
     def test_opaque_properties(self):
-        file = self.addResource("/r", "some file content",
-                                title = u"Test resource")
+        coll = self.addCollection("/coll", title = u"Test resource")
 
-        opaqueProperties = z3c.dav.interfaces.IOpaquePropertyStorage(file)
+        opaqueProperties = z3c.dav.interfaces.IOpaquePropertyStorage(coll)
         opaqueProperties.setProperty(
             "{examplens:}testdeadprop",
             """<E:testdeadprop xmlns:E="examplens:">TEST</E:testdeadprop>""")
@@ -340,23 +267,27 @@
 </D:prop>
 """
         httpresponse = self.checkPropfind(
-            "/r", env = {"DEPTH": "0"}, properties = properties)
+            "/coll", env = {"DEPTH": "0"}, properties = properties)
 
-        self.assertEqual(len(httpresponse.getMSResponses()), 1)
         z3c.etree.testing.assertXMLEqual(
-            '<resourcetype xmlns="DAV:" />',
-            httpresponse.getMSProperty(
-                "http://localhost/r", "{DAV:}resourcetype"))
-        z3c.etree.testing.assertXMLEqual(
-            '<testdeadprop xmlns="examplens:">TEST</testdeadprop>',
-            httpresponse.getMSProperty(
-                "http://localhost/r", "{examplens:}testdeadprop"))
+            """<multistatus xmlns="DAV:">
+<response>
+  <href>http://localhost/coll/</href>
+  <propstat>
+    <prop>
+      <resourcetype><collection /></resourcetype>
+      <ns1:testdeadprop xmlns:ns1="examplens:">TEST</ns1:testdeadprop>
+    </prop>
+    <status>HTTP/1.1 200 OK</status>
+  </propstat>
+</response>
+</multistatus>""",
+            httpresponse.getBody())
 
     def test_allprop_with_opaque_properties(self):
-        file = self.addResource("/r", "some file content",
-                                title = u"Test Resource")
+        coll = self.addCollection("/coll", title = u"Test collection")
 
-        opaqueProperties = z3c.dav.interfaces.IOpaquePropertyStorage(file)
+        opaqueProperties = z3c.dav.interfaces.IOpaquePropertyStorage(coll)
         opaqueProperties.setProperty(
             "{examplens:}testdeadprop",
             """<E:testdeadprop xmlns:E="examplens:">TEST</E:testdeadprop>""")
@@ -364,47 +295,85 @@
 
         properties = "<D:allprop />"
         httpresponse = self.checkPropfind(
-            "/r", env = {"DEPTH": "0"}, properties = properties)
+            "/coll", env = {"DEPTH": "0"}, properties = properties)
 
+        z3c.etree.testing.assertXMLEqual(
+            """<multistatus xmlns="DAV:">
+<response>
+  <href>http://localhost/coll/</href>
+  <propstat>
+    <prop>
+      <creationdate />
+      <displayname>Test collection</displayname>
+      <getlastmodified />
+      <resourcetype><collection /></resourcetype>
+      <ns1:exampleintprop xmlns:ns1="DAVtest:">0</ns1:exampleintprop>
+      <ns1:testdeadprop xmlns:ns1="examplens:">TEST</ns1:testdeadprop>
+    </prop>
+    <status>HTTP/1.1 200 OK</status>
+  </propstat>
+</response>
+</multistatus>""",
+            httpresponse.getBody())
+
     def test_unicode_title(self):
         teststr = u"copyright \xa9 me"
-        file = self.addResource(u"/" + teststr, "some file content",
-                                title = teststr)
+        self.addCollection(u"/" + teststr, title = teststr)
 
         httpresponse = self.checkPropfind(
             "/" + teststr.encode("utf-8"), env = {"DEPTH": "0",
                                                   "CONTENT_TYPE": "text/xml"},
             properties = "<D:prop><D:displayname /></D:prop>")
 
-        want = '<displayname xmlns="DAV:">%s</displayname>' % teststr
         z3c.etree.testing.assertXMLEqual(
-            want.encode("utf-8"), # needed in order for elementtree to parse
-            httpresponse.getMSProperty(
-                "http://localhost/%s" % urllib.quote(teststr.encode("utf-8")),
-                "{DAV:}displayname"))
+            """<multistatus xmlns="DAV:">
+<response>
+  <href>http://localhost/copyright%20%C2%A9%20me/</href>
+  <propstat>
+    <prop>
+      <displayname>copyright \xc2\xa9 me</displayname>
+    </prop>
+    <status>HTTP/1.1 200 OK</status>
+  </propstat>
+</response>
+</multistatus>""",
+            httpresponse.getBody())
 
     def test_allprop_with_deadprops(self):
-        file = self.addResource("/r", "some content", title = u"Test Resource")
+        coll = self.addCollection("/coll", title = u"Test collection")
 
-        opaqueProperties = z3c.dav.interfaces.IOpaquePropertyStorage(file)
+        opaqueProperties = z3c.dav.interfaces.IOpaquePropertyStorage(coll)
         opaqueProperties.setProperty("{deadprop:}deadprop",
                                      """<X:deadprop xmlns:X="deadprop:">
 This is a dead property.</X:deadprop>""")
         transaction.commit()
 
         httpresponse = self.checkPropfind(
-            "/r", env = {"DEPTH": "0", "CONTENT_TYPE": "text/xml"},
+            "/coll", env = {"DEPTH": "0", "CONTENT_TYPE": "text/xml"},
             properties = "<D:allprop />")
 
-        self.assertEqual(len(httpresponse.getMSResponses()), 1)
         z3c.etree.testing.assertXMLEqual(
-            """<deadprop xmlns="deadprop:">
-This is a dead property.</deadprop>""",
-            httpresponse.getMSProperty(
-                "http://localhost/r", "{deadprop:}deadprop"))
+            """<multistatus xmlns="DAV:">
+<response>
+  <href>http://localhost/coll/</href>
+  <propstat>
+    <prop>
+      <creationdate />
+      <displayname>Test collection</displayname>
+      <getlastmodified />
+      <resourcetype><collection /></resourcetype>
+      <ns1:exampleintprop xmlns:ns1="DAVtest:">0</ns1:exampleintprop>
+      <ns1:deadprop xmlns:ns1="deadprop:">
+This is a dead property.</ns1:deadprop>
+    </prop>
+    <status>HTTP/1.1 200 OK</status>
+  </propstat>
+</response>
+</multistatus>""",
+            httpresponse.getBody())
 
     def test_allprop_with_restricted(self):
-        file = self.addResource("/r", "some content", title = u"Test Resource")
+        file = self.addCollection("/coll", title = u"Test collection")
 
         examplePropStorage = component.getMultiAdapter(
             (file, dav.TestWebDAVRequest()), dav.IExamplePropertyStorage)
@@ -412,17 +381,18 @@
         transaction.commit()
 
         httpresponse = self.checkPropfind(
-            "/r", env = {"DEPTH": "0", "CONTENT_TYPE": "application/xml"},
+            "/coll", env = {"DEPTH": "0", "CONTENT_TYPE": "application/xml"},
             properties = "<D:allprop />")
 
         self.assertRaises(KeyError, httpresponse.getMSProperty,
-                          "http://localhost/r", "{DAVtest:}exampletextprop")
+                          "http://localhost/coll/",
+                          "{DAVtest:}exampletextprop")
 
     def test_allprop_with_include(self):
-        file = self.addResource("/r", "some content", title = u"Test Resource")
+        coll = self.addCollection("/coll", title = u"Test collection")
 
         examplePropStorage = component.getMultiAdapter(
-            (file, dav.TestWebDAVRequest()), dav.IExamplePropertyStorage)
+            (coll, dav.TestWebDAVRequest()), dav.IExamplePropertyStorage)
         examplePropStorage.exampletextprop = "EXAMPLE TEXT PROP"
         transaction.commit()
 
@@ -431,7 +401,7 @@
         textprop.restricted = True
 
         httpresponse = self.checkPropfind(
-            "/r", env = {"DEPTH": "0", "CONTENT_TYPE": "application/xml"},
+            "/coll", env = {"DEPTH": "0", "CONTENT_TYPE": "application/xml"},
             properties = """<D:allprop />
 <D:include>
   <Dtest:exampletextprop xmlns:Dtest="DAVtest:" />
@@ -439,13 +409,26 @@
 """)
 
         z3c.etree.testing.assertXMLEqual(
-            """<exampletextprop
-                xmlns="DAVtest:">EXAMPLE TEXT PROP</exampletextprop>""",
-            httpresponse.getMSProperty(
-                "http://localhost/r", "{DAVtest:}exampletextprop"))
+            """<multistatus xmlns="DAV:">
+<response>
+  <href>http://localhost/coll/</href>
+  <propstat>
+    <prop>
+      <creationdate />
+      <displayname>Test collection</displayname>
+      <ns1:exampletextprop xmlns:ns1="DAVtest:">EXAMPLE TEXT PROP</ns1:exampletextprop>
+      <getlastmodified />
+      <resourcetype><collection /></resourcetype>
+      <ns1:exampleintprop xmlns:ns1="DAVtest:">0</ns1:exampleintprop>
+    </prop>
+    <status>HTTP/1.1 200 OK</status>
+  </propstat>
+</response>
+</multistatus>""",
+            httpresponse.getBody())
 
     def test_allprop_with_include_on_unauthorized(self):
-        file = self.addResource("/r", "some content", title = u"Test Resource")
+        self.addCollection("/coll", title = u"Test collection")
 
         body = """<?xml version="1.0" encoding="utf-8" ?>
 <propfind xmlns:D="DAV:" xmlns="DAV:">
@@ -456,67 +439,39 @@
 </propfind>"""
 
         httpresponse = self.checkPropfind(
-            "/r", env = {"DEPTH": "0", "CONTENT_TYPE": "application/xml"},
+            "/coll/", env = {"DEPTH": "0", "CONTENT_TYPE": "application/xml"},
             properties = """<D:allprop />
 <D:include>
   <Dtest:unauthprop xmlns:Dtest="DAVtest:" />
 </D:include>
 """)
 
-        self.assertEqual(len(httpresponse.getMSResponses()), 1)
-
         z3c.etree.testing.assertXMLEqual(
-            '<unauthprop xmlns="DAVtest:" />',
-            httpresponse.getMSProperty(
-                "http://localhost/r", "{DAVtest:}unauthprop", status = 401))
+            """<multistatus xmlns="DAV:">
+<response>
+  <href>http://localhost/coll/</href>
+  <propstat>
+    <prop>
+      <creationdate />
+      <displayname>Test collection</displayname>
+      <getlastmodified />
+      <resourcetype><collection /></resourcetype>
+      <ns1:exampleintprop xmlns:ns1="DAVtest:">0</ns1:exampleintprop>
+    </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>
+</multistatus>""",
+            httpresponse.getBody())
 
-    def test_propfind_onfile(self):
-        self.addResource("/testfile", "some file content",
-                         contentType = "text/plain")
-        httpresponse = self.checkPropfind(
-            "/testfile", env = {"DEPTH": "0"}, properties = "<D:allprop />")
 
-        self.assertEqual(len(httpresponse.getMSResponses()), 1)
-
-        # all properties should be defined on a file.
-        z3c.etree.testing.assertXMLEqual(
-            '<resourcetype xmlns="DAV:" />',
-            httpresponse.getMSProperty(
-                "http://localhost/testfile", "{DAV:}resourcetype"))
-        z3c.etree.testing.assertXMLEqual(
-            '<creationdate xmlns="DAV:" />',
-            httpresponse.getMSProperty(
-                "http://localhost/testfile", "{DAV:}creationdate"))
-        z3c.etree.testing.assertXMLEqual(
-            '<displayname xmlns="DAV:" />',
-            httpresponse.getMSProperty(
-                "http://localhost/testfile", "{DAV:}displayname"))
-        z3c.etree.testing.assertXMLEqual(
-            '<getcontentlanguage xmlns="DAV:" />',
-            httpresponse.getMSProperty(
-                "http://localhost/testfile", "{DAV:}getcontentlanguage"))
-        z3c.etree.testing.assertXMLEqual(
-            '<getcontentlength xmlns="DAV:">17</getcontentlength>',
-            httpresponse.getMSProperty(
-                "http://localhost/testfile", "{DAV:}getcontentlength"))
-        z3c.etree.testing.assertXMLEqual(
-            '<getcontenttype xmlns="DAV:">text/plain</getcontenttype>',
-            httpresponse.getMSProperty(
-                "http://localhost/testfile", "{DAV:}getcontenttype"))
-        z3c.etree.testing.assertXMLEqual(
-            '<getetag xmlns="DAV:" />',
-            httpresponse.getMSProperty(
-                "http://localhost/testfile", "{DAV:}getetag"))
-        z3c.etree.testing.assertXMLEqual(
-            '<getlastmodified xmlns="DAV:" />',
-            httpresponse.getMSProperty(
-                "http://localhost/testfile", "{DAV:}getlastmodified"))
-
-
 def test_suite():
     return unittest.TestSuite((
             unittest.makeSuite(PROPFINDTests),
             ))
-
-if __name__ == "__main__":
-    unittest.main(defaultTest = "test_suite")

Modified: z3c.dav/trunk/src/z3c/dav/ftests/test_proppatch.py
===================================================================
--- z3c.dav/trunk/src/z3c/dav/ftests/test_proppatch.py	2007-05-07 13:45:06 UTC (rev 75612)
+++ z3c.dav/trunk/src/z3c/dav/ftests/test_proppatch.py	2007-05-07 15:31:50 UTC (rev 75613)
@@ -56,17 +56,18 @@
         self.assertEqual(response.getBody(), "")
 
     def test_setdisplayname_unauthorized(self):
-        self.addResource("/r", "some content", title = u"Test Resource")
+        self.addCollection("/coll", title = u"Test collection")
         body = """<?xml version="1.0" encoding="utf-8" ?>
 <D:propertyupdate xmlns:D="DAV:" xmlns="DAV:">
   <D:set><D:prop>
-    <D:displayname>Test File</D:displayname>
+    <D:displayname>Big collection</D:displayname>
   </D:prop></D:set>
 </D:propertyupdate>"""
 
-        response = self.publish("/r", env = {"REQUEST_METHOD": "PROPPATCH",
-                                             "CONTENT_TYPE": "application/xml",
-                                             "CONTENT_LENGTH": len(body)},
+        response = self.publish("/coll",
+                                env = {"REQUEST_METHOD": "PROPPATCH",
+                                       "CONTENT_TYPE": "application/xml",
+                                       "CONTENT_LENGTH": len(body)},
                                 request_body = body,
                                 handle_errors = True)
 
@@ -77,49 +78,73 @@
             'basic realm="Zope"')
 
     def test_setdisplayname(self):
-        set_properties = "<D:displayname>Test File</D:displayname>"
-        self.addResource("/r", "some content", title = u"Test Resource")
+        set_properties = "<D:displayname>Big collection</D:displayname>"
+        self.addCollection("/coll", title = u"Test collection")
 
         httpresponse = self.checkProppatch(
-            "/r", basic = "mgr:mgrpw", set_properties = set_properties)
+            "/coll", basic = "mgr:mgrpw", set_properties = set_properties)
 
-        self.assertEqual(len(httpresponse.getMSResponses()), 1)
-        assertXMLEqual('<displayname xmlns="DAV:" />',
-            httpresponse.getMSProperty(
-                "http://localhost/r", "{DAV:}displayname"))
+        assertXMLEqual(
+            """<multistatus xmlns="DAV:">
+<response>
+  <href>http://localhost/coll/</href>
+  <propstat>
+    <prop>
+      <displayname />
+    </prop>
+    <status>HTTP/1.1 200 OK</status>
+  </propstat>
+</response>
+</multistatus>""",
+            httpresponse.getBody())
 
-        title = IZopeDublinCore(self.getRootFolder()["r"]).title
-        self.assertEqual(title, u"Test File")
+        title = IZopeDublinCore(self.getRootFolder()["coll"]).title
+        self.assertEqual(title, u"Big collection")
 
     def test_readonly_property(self):
-        set_properties = "<D:getcontentlength>10</D:getcontentlength>"
-        self.addResource("/r", "some file content", title = u"Test Resource")
+        set_properties = "<D:resourcetype><D:collection /></D:resourcetype>"
+        self.addCollection("/coll", title = u"Test collection")
 
         httpresponse = self.checkProppatch(
-            "/r", basic = "mgr:mgrpw", set_properties = set_properties)
+            "/coll/", basic = "mgr:mgrpw", set_properties = set_properties)
 
-        self.assertEqual(len(httpresponse.getMSResponses()), 1)
         assertXMLEqual(
-            '<getcontentlength xmlns="DAV:" />',
-            httpresponse.getMSProperty(
-                "http://localhost/r", "{DAV:}getcontentlength", status = 403))
+            """<multistatus xmlns="DAV:">
+<response>
+  <href>http://localhost/coll/</href>
+  <propstat>
+    <prop>
+      <resourcetype />
+    </prop>
+    <status>HTTP/1.1 403 Forbidden</status>
+  </propstat>
+</response>
+</multistatus>""",
+            httpresponse.getBody())
 
     def test_badinput(self):
         set_properties = """
         <E:exampleintprop xmlns:E="DAVtest:">BAD INT</E:exampleintprop>
         """
-        resource = self.addResource("/testresource", "some resource content")
+        self.addCollection("/coll")
 
         httpresponse = self.checkProppatch(
-            "/testresource", basic = "mgr:mgrpw",
+            "/coll", basic = "mgr:mgrpw",
             set_properties = set_properties)
 
-        self.assertEqual(len(httpresponse.getMSResponses()), 1)
         assertXMLEqual(
-            '<exampleintprop xmlns="DAVtest:" />',
-            httpresponse.getMSProperty(
-                "http://localhost/testresource", "{DAVtest:}exampleintprop",
-                status = 409))
+            """<multistatus xmlns="DAV:">
+<response>
+  <href>http://localhost/coll/</href>
+  <propstat>
+    <prop>
+      <ns1:exampleintprop xmlns:ns1="DAVtest:" />
+    </prop>
+    <status>HTTP/1.1 409 Conflict</status>
+  </propstat>
+</response>
+</multistatus>""",
+            httpresponse.getBody())
 
     def test_badinput_plus_faileddep(self):
         set_properties = """
@@ -128,32 +153,40 @@
           Test Property
         </E:exampletextprop>
         """
-        resource = self.addResource("/testresource", "some resource content")
+        coll = self.addCollection("/coll")
 
         request = WebDAVRequest(StringIO(""), {})
-        exampleStorage = component.getMultiAdapter((resource, request),
+        exampleStorage = component.getMultiAdapter((coll, request),
                                                    dav.IExamplePropertyStorage)
         # set up a default value to test later
         exampleStorage.exampletextprop = u"Example Text Property"
         transaction.commit()
 
         httpresponse = self.checkProppatch(
-            "/testresource", basic = "mgr:mgrpw",
+            "/coll", basic = "mgr:mgrpw",
             set_properties = set_properties)
 
-        self.assertEqual(len(httpresponse.getMSResponses()), 1)
         assertXMLEqual(
-            '<exampletextprop xmlns="DAVtest:" />',
-            httpresponse.getMSProperty(
-                "http://localhost/testresource", "{DAVtest:}exampletextprop",
-                status = 424))
-        assertXMLEqual(
-            '<exampleintprop xmlns="DAVtest:" />',
-            httpresponse.getMSProperty(
-                "http://localhost/testresource", "{DAVtest:}exampleintprop",
-                status = 409))
+            """<multistatus xmlns="DAV:">
+<response>
+  <href>http://localhost/coll/</href>
+  <propstat>
+    <prop>
+      <ns1:exampletextprop xmlns:ns1="DAVtest:" />
+    </prop>
+    <status>HTTP/1.1 424 Failed Dependency</status>
+  </propstat>
+  <propstat>
+    <prop>
+      <ns1:exampleintprop xmlns:ns1="DAVtest:" />
+    </prop>
+    <status>HTTP/1.1 409 Conflict</status>
+  </propstat>
+</response>
+</multistatus>""",
+            httpresponse.getBody())
 
-        exampleStorage = component.getMultiAdapter((resource, request),
+        exampleStorage = component.getMultiAdapter((coll, request),
                                                    dav.IExamplePropertyStorage)
         self.assertEqual(exampleStorage.exampletextprop,
                          u"Example Text Property")
@@ -163,13 +196,26 @@
 Jim Whitehead
 </Z:Author>
         """
-        file = self.addResource("/r", "some content",
-                                title = u"Test Resource")
+        coll = self.addCollection("/coll", title = u"Test collection")
 
         httpresponse = self.checkProppatch(
-            "/r", basic = "mgr:mgrpw", set_properties = set_properties)
+            "/coll", basic = "mgr:mgrpw", set_properties = set_properties)
 
-        opaqueProperties = z3c.dav.interfaces.IOpaquePropertyStorage(file)
+        assertXMLEqual(
+            """<multistatus xmlns="DAV:">
+<response>
+  <href>http://localhost/coll/</href>
+  <propstat>
+    <prop>
+      <ns1:Author xmlns:ns1="http://ns.example.com/z39.50/" />
+    </prop>
+    <status>HTTP/1.1 200 OK</status>
+  </propstat>
+</response>
+</multistatus>""",
+            httpresponse.getBody())
+
+        opaqueProperties = z3c.dav.interfaces.IOpaquePropertyStorage(coll)
         self.assertEqual(opaqueProperties.hasProperty(
             "{http://ns.example.com/z39.50/}Author"), True)
         assertXMLEqual(opaqueProperties.getProperty(
@@ -185,12 +231,29 @@
 <E:prop3 xmlns:E="example:">PROP0</E:prop3>
         """
 
-        file = self.addResource("/r", "some content", title = u"Test Resource")
+        coll = self.addCollection("/coll", title = u"Test collection")
 
         httpresponse = self.checkProppatch(
-            "/r", basic = "mgr:mgrpw", set_properties = set_properties)
+            "/coll", basic = "mgr:mgrpw", set_properties = set_properties)
 
-        opaqueProperties = z3c.dav.interfaces.IOpaquePropertyStorage(file)
+        assertXMLEqual(
+            """<multistatus xmlns="DAV:">
+<response>
+  <href>http://localhost/coll/</href>
+  <propstat>
+    <prop>
+      <ns1:prop0 xmlns:ns1="example:" />
+      <ns1:prop1 xmlns:ns1="example:" />
+      <ns1:prop2 xmlns:ns1="example:" />
+      <ns1:prop3 xmlns:ns1="example:" />
+    </prop>
+    <status>HTTP/1.1 200 OK</status>
+  </propstat>
+</response>
+</multistatus>""",
+            httpresponse.getBody())
+
+        opaqueProperties = z3c.dav.interfaces.IOpaquePropertyStorage(coll)
         allprops = [tag for tag in opaqueProperties.getAllProperties()]
         allprops.sort()
         self.assertEqual(allprops, ["{example:}prop0", "{example:}prop1",
@@ -199,76 +262,106 @@
     def test_unicode_title(self):
         teststr = u"copyright \xa9 me"
         set_properties = "<D:displayname>%s</D:displayname>" % teststr
-        self.addResource("/r", "some content", title = u"Test Resource")
+        coll = self.addCollection("/coll", title = u"Test Resource")
 
         httpresponse = self.checkProppatch(
-            "/r", basic = "mgr:mgrpw", set_properties = set_properties)
+            "/coll", basic = "mgr:mgrpw", set_properties = set_properties)
 
-        self.assertEqual(len(httpresponse.getMSResponses()), 1)
         assertXMLEqual(
-            '<displayname xmlns="DAV:" />',
-            httpresponse.getMSProperty(
-                "http://localhost/r", "{DAV:}displayname"))
+            """<multistatus xmlns="DAV:">
+<response>
+  <href>http://localhost/coll/</href>
+  <propstat>
+    <prop>
+      <displayname />
+    </prop>
+    <status>HTTP/1.1 200 OK</status>
+  </propstat>
+</response>
+</multistatus>""",
+            httpresponse.getBody())
 
+        self.assertEqual(IZopeDublinCore(coll).title, teststr)
+
     def test_remove_live_prop(self):
-        file = self.addResource("/r", "some content", title = u"Test Resource")
+        coll = self.addCollection("/coll", title = u"Test collection")
 
-        opaqueProperties = z3c.dav.interfaces.IOpaquePropertyStorage(file)
+        opaqueProperties = z3c.dav.interfaces.IOpaquePropertyStorage(coll)
         opaqueProperties.setProperty("{deadprop:}deadprop",
                                      """<X:deadprop xmlns:X="deadprop:">
 This is a dead property.</X:deadprop>""")
         transaction.commit()
 
         httpresponse = self.checkProppatch(
-            "/r", basic = "mgr:mgrpw",
+            "/coll", basic = "mgr:mgrpw",
             remove_properties = """<E:exampleintprop xmlns:E="DAVtest:" />""")
 
-        self.assertEqual(len(httpresponse.getMSResponses()), 1)
-
         assertXMLEqual(
-            '<exampleintprop xmlns="DAVtest:" />',
-            httpresponse.getMSProperty(
-                "http://localhost/r", "{DAVtest:}exampleintprop",
-                status = 409))
+            """<multistatus xmlns="DAV:">
+<response>
+  <href>http://localhost/coll/</href>
+  <propstat>
+    <prop>
+      <ns1:exampleintprop xmlns:ns1="DAVtest:" />
+    </prop>
+    <status>HTTP/1.1 409 Conflict</status>
+  </propstat>
+</response>
+</multistatus>""",
+            httpresponse.getBody())
 
     def test_remove_dead_prop(self):
         proptag = "{deadprop:}deadprop"
-        file = self.addResource("/r", "some content", title = u"Test Resource")
+        coll = self.addCollection("/coll", title = u"Test collection")
 
-        opaqueProperties = z3c.dav.interfaces.IOpaquePropertyStorage(file)
+        opaqueProperties = z3c.dav.interfaces.IOpaquePropertyStorage(coll)
         opaqueProperties.setProperty(proptag,
                                      """<X:deadprop xmlns:X="deadprop:">
 This is a dead property.</X:deadprop>""")
         transaction.commit()
 
         httpresponse = self.checkProppatch(
-            "/r", basic = "mgr:mgrpw",
+            "/coll", basic = "mgr:mgrpw",
             remove_properties = """<X:deadprop xmlns:X="deadprop:" />""")
 
-        self.assertEqual(len(httpresponse.getMSResponses()), 1)
         assertXMLEqual(
-            '<deadprop xmlns="deadprop:" />',
-            httpresponse.getMSProperty(
-                "http://localhost/r", "{deadprop:}deadprop"))
+            """<multistatus xmlns="DAV:">
+<response>
+  <href>http://localhost/coll/</href>
+  <propstat>
+    <prop>
+      <ns1:deadprop xmlns:ns1="deadprop:" />
+    </prop>
+    <status>HTTP/1.1 200 OK</status>
+  </propstat>
+</response>
+</multistatus>""",
+            httpresponse.getBody())
 
-        opaqueProperties = z3c.dav.interfaces.IOpaquePropertyStorage(file)
+        opaqueProperties = z3c.dav.interfaces.IOpaquePropertyStorage(coll)
         self.assertEqual(opaqueProperties.hasProperty(proptag), False)
 
     def test_setting_unicode_title(self):
         teststr = u"copyright \xa9 me"
-        self.addResource(u"/" + teststr, "some file content",
-                         title = u"Old title")
+        coll = self.addCollection(u"/" + teststr, title = u"Old title")
 
         httpresponse = self.checkProppatch(
             "/" + teststr.encode("utf-8"), basic = "mgr:mgrpw",
             set_properties = "<D:displayname>%s</D:displayname>" % teststr)
 
-        self.assertEqual(len(httpresponse.getMSResponses()), 1)
         assertXMLEqual(
-            '<displayname xmlns="DAV:" />',
-            httpresponse.getMSProperty(
-                "http://localhost/%s" % urllib.quote(teststr.encode("utf-8")),
-                "{DAV:}displayname"))
+            """<multistatus xmlns="DAV:">
+<response>
+  <href>http://localhost/copyright%20%C2%A9%20me/</href>
+  <propstat>
+    <prop>
+      <displayname />
+    </prop>
+    <status>HTTP/1.1 200 OK</status>
+  </propstat>
+</response>
+</multistatus>""",
+            httpresponse.getBody())
 
         resourcetitle = IZopeDublinCore(self.getRootFolder()[teststr]).title
         self.assertEqual(resourcetitle, teststr)
@@ -278,6 +371,3 @@
     return unittest.TestSuite((
             unittest.makeSuite(PROPPATCHTestCase),
             ))
-
-if __name__ == "__main__":
-    unittest.main(defaultTest = "test_suite")



More information about the Checkins mailing list