[Zope3-checkins] SVN: Zope3/branches/isarsprint-dav-work/src/zope/app/dav/ Alter the commit call to the new transaction module style

Martijn Pieters mj at zopatista.com
Wed Oct 13 07:47:16 EDT 2004


Log message for revision 28063:
  Alter the commit call to the new transaction module style
  

Changed:
  U   Zope3/branches/isarsprint-dav-work/src/zope/app/dav/ftests/test_propfind.py
  A   Zope3/branches/isarsprint-dav-work/src/zope/app/dav/ftests/test_proppatch.py
  U   Zope3/branches/isarsprint-dav-work/src/zope/app/dav/opaquenamespaces.py
  U   Zope3/branches/isarsprint-dav-work/src/zope/app/dav/proppatch.py

-=-
Modified: Zope3/branches/isarsprint-dav-work/src/zope/app/dav/ftests/test_propfind.py
===================================================================
--- Zope3/branches/isarsprint-dav-work/src/zope/app/dav/ftests/test_propfind.py	2004-10-13 11:40:01 UTC (rev 28062)
+++ Zope3/branches/isarsprint-dav-work/src/zope/app/dav/ftests/test_propfind.py	2004-10-13 11:47:14 UTC (rev 28063)
@@ -17,7 +17,7 @@
 """
 import unittest
 from datetime import datetime
-from transaction import get_transaction
+import transaction
 from zope.pagetemplate.tests.util import normalize_xml
 
 from zope.app import zapi
@@ -38,7 +38,7 @@
         pt = traverse(self.getRootFolder(), '/pt')
         adapted = IZopeDublinCore(pt)
         adapted.title = u'Test Title'
-        get_transaction().commit()
+        transaction.commit()
         self.verifyPropOK(path='/pt', ns='http://purl.org/dc/1.1',
                           prop='title', expect='Test Title', basic='mgr:mgrpw')
 
@@ -47,7 +47,7 @@
         pt = traverse(self.getRootFolder(), '/pt')
         adapted = IZopeDublinCore(pt)
         adapted.created = datetime.utcnow()
-        get_transaction().commit()
+        transaction.commit()
         expect = str(adapted.created)
         self.verifyPropOK(path='/pt', ns='http://purl.org/dc/1.1',
                           prop='created', expect=expect, basic='mgr:mgrpw')
@@ -57,7 +57,7 @@
         pt = traverse(self.getRootFolder(), '/pt')
         adapted = IZopeDublinCore(pt)
         adapted.subjects = (u'Bla', u'Ble', u'Bli')
-        get_transaction().commit()
+        transaction.commit()
         expect = ', '.join(adapted.subjects)
         self.verifyPropOK(path='/pt', ns='http://purl.org/dc/1.1',
                           prop='subjects', expect=expect, basic='mgr:mgrpw')
@@ -67,7 +67,7 @@
         pt = traverse(self.getRootFolder(), '/pt')
         adapted = IDAVOpaqueNamespaces(pt)
         adapted[u'uri://bar'] = {u'foo': '<foo>spam</foo>'}
-        get_transaction().commit()
+        transaction.commit()
         expect = 'spam'
         self.verifyPropOK(path='/pt', ns='uri://bar',
                           prop='foo', expect=expect, basic='mgr:mgrpw')

Added: Zope3/branches/isarsprint-dav-work/src/zope/app/dav/ftests/test_proppatch.py
===================================================================
--- Zope3/branches/isarsprint-dav-work/src/zope/app/dav/ftests/test_proppatch.py	2004-10-13 11:40:01 UTC (rev 28062)
+++ Zope3/branches/isarsprint-dav-work/src/zope/app/dav/ftests/test_proppatch.py	2004-10-13 11:47:14 UTC (rev 28063)
@@ -0,0 +1,142 @@
+##############################################################################
+#
+# Copyright (c) 2003 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.
+#
+##############################################################################
+"""Functional tests for PROPPATCH.
+
+$Id$
+"""
+import unittest
+import transaction
+from zope.pagetemplate.tests.util import normalize_xml
+from zope.publisher.http import status_reasons
+
+from zope.app import zapi
+from zope.app.dav.ftests.dav import DAVTestCase
+from zope.app.dublincore.interfaces import IZopeDublinCore
+from zope.app.dav.opaquenamespaces import IDAVOpaqueNamespaces
+from zope.app.traversing.api import traverse
+
+class TestPROPPATCH(DAVTestCase):
+
+    def test_set(self):
+        self.addPage('/pt', u'<span />')
+        transaction.commit()
+        expect = self._makePropstat(('uri://foo',), '<bar xmlns="a0"/>')
+        self.verifyPropOK(path='/pt', namespaces=(('foo', 'uri://foo'),),
+            set=('<foo:bar>spam</foo:bar>',), expect=expect)
+        pt = traverse(self.getRootFolder(), '/pt')
+        self._assertOPropsEqual(pt, 
+            {u'uri://foo': {u'bar': '<bar>spam</bar>'}})
+
+    def test_remove(self):
+        self.addPage('/pt', u'<span />')
+        pt = traverse(self.getRootFolder(), '/pt')
+        adapted = IDAVOpaqueNamespaces(pt)
+        adapted[u'uri://foo'] = {u'bar': '<bar>spam</bar>'}
+        transaction.commit()
+        expect = self._makePropstat(('uri://foo',), '<bar xmlns="a0"/>')
+        self.verifyPropOK(path='/pt', namespaces=(('foo', 'uri://foo'),),
+            rm=('<foo:bar/>',), expect=expect)
+        self._assertOPropsEqual(pt, {})
+        
+    def test_complex(self):
+        self.addPage('/pt', u'<span />')
+        pt = traverse(self.getRootFolder(), '/pt')
+        adapted = IDAVOpaqueNamespaces(pt)
+        adapted[u'uri://foo'] = {u'bar': '<bar>eggs</bar>'}
+        adapted[u'uri://montypython'] = {u'castle': '<castle>camelot</castle>'}
+        transaction.commit()
+        expect = self._makePropstat(('uri://foo', 'uri://montypython'),
+            '<bar xmlns="a0"/><castle xmlns="a1"/><song xmlns="a1"/>')
+        self.verifyPropOK(path='/pt', 
+            namespaces=(('foo', 'uri://foo'), ('mp', 'uri://montypython')),
+            set=('<foo:bar>spam</foo:bar>',),
+            rm=('<mp:castle/>', '<mp:song/>'), expect=expect)
+        self._assertOPropsEqual(pt, 
+            {u'uri://foo': {u'bar': '<bar>spam</bar>'}})
+        
+    def _assertOPropsEqual(self, obj, expect):
+        oprops = IDAVOpaqueNamespaces(obj)
+        namespacesA = list(oprops.keys())
+        namespacesA.sort()
+        namespacesB = expect.keys()
+        namespacesB.sort()
+        self.assertEqual(namespacesA, namespacesB, 
+                         'available opaque namespaces were %s, '
+                         'expected %s' % (namespacesA, namespacesB))
+        
+        for ns in namespacesA:
+            propnamesA = list(oprops[ns].keys())
+            propnamesA.sort()
+            propnamesB = expect[ns].keys()
+            propnamesB.sort()
+            self.assertEqual(propnamesA, propnamesB, 
+                             'props for opaque namespaces %s were %s, '
+                             'expected %s' % (ns, propnamesA, propnamesB))
+            for prop in propnamesA:
+                valueA = oprops[ns][prop]
+                valueB = expect[ns][prop]
+                self.assertEqual(valueA, valueB, 
+                                 'opaque prop %s:%s was %s, '
+                                 'expected %s' % (ns, prop, valueA, valueB))
+ 
+
+    def _makePropstat(self, ns, properties, status=200):
+        nsattrs = ''
+        count = 0
+        for uri in ns:
+            nsattrs += ' xmlns:a%d="%s"' % (count, uri)
+            count += 1
+        reason = status_reasons[status]
+        return '''<propstat>
+            <prop%s>%s</prop>
+            <status>HTTP/1.1 %d %s</status>
+            </propstat>''' % (nsattrs, properties, status, reason)
+
+    def verifyPropOK(self, path, namespaces=(), set=(), rm=(), expect='', 
+                     basic='mgr:mgrpw'):
+        nsAttrs = setProps = removeProps = ''
+        if set:
+            setProps = '<set><prop>\n%s\n</prop></set>\n' % (''.join(set))
+        if rm:
+            removeProps = '<remove><prop>\n%s\n</prop></remove>\n' % (
+                ''.join(rm))
+        for prefix, ns in namespaces:
+            nsAttrs += ' xmlns:%s="%s"' % (prefix, ns)
+        body = """<?xml version="1.0" ?>
+        <propertyupdate xmlns="DAV:"%s>
+        %s
+        </propertyupdate>""" % (nsAttrs, setProps + removeProps)
+        result = self.publish(path, basic, env={'REQUEST_METHOD':'PROPPATCH',
+                                                'CONTENT-LENGHT': len(body)},
+                              request_body=body)
+        self.assertEquals(result.getStatus(), 207)
+        s1 = normalize_xml(result.getBody())
+        s2 = normalize_xml("""<?xml version="1.0" ?>
+        <multistatus xmlns="DAV:">
+        <response>
+        <href>http://localhost/pt</href>
+        %s
+        </response>
+        </multistatus>""" % expect)
+        self.assertEquals(s1, s2)
+
+
+def test_suite():
+    suite = unittest.TestSuite()
+    suite.addTest(unittest.makeSuite(TestPROPPATCH))
+    return suite
+
+
+if __name__ == '__main__':
+    unittest.main()


Property changes on: Zope3/branches/isarsprint-dav-work/src/zope/app/dav/ftests/test_proppatch.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: Zope3/branches/isarsprint-dav-work/src/zope/app/dav/opaquenamespaces.py
===================================================================
--- Zope3/branches/isarsprint-dav-work/src/zope/app/dav/opaquenamespaces.py	2004-10-13 11:40:01 UTC (rev 28062)
+++ Zope3/branches/isarsprint-dav-work/src/zope/app/dav/opaquenamespaces.py	2004-10-13 11:47:14 UTC (rev 28063)
@@ -62,6 +62,9 @@
         property name are taken to be stored.
         
         """
+        
+    def removeProperty(ns, prop):
+        """Remove the indicated property altogether"""
 
     
 class DAVOpaqueNamespacesAdapter(DictMixin, Location):
@@ -121,6 +124,13 @@
         props = self.setdefault(ns, OOBTree())
         propel = makeDOMStandalone(propel)
         props[propel.nodeName] = propel.toxml('utf-8')
+        
+    def removeProperty(self, ns, prop):
+        if self.get(ns, {}).get(prop) is None:
+            return
+        del self[ns][prop]
+        if not self[ns]:
+            del self[ns]
 
 
 def makeDOMStandalone(element):

Modified: Zope3/branches/isarsprint-dav-work/src/zope/app/dav/proppatch.py
===================================================================
--- Zope3/branches/isarsprint-dav-work/src/zope/app/dav/proppatch.py	2004-10-13 11:40:01 UTC (rev 28062)
+++ Zope3/branches/isarsprint-dav-work/src/zope/app/dav/proppatch.py	2004-10-13 11:47:14 UTC (rev 28063)
@@ -169,10 +169,7 @@
             # opaque DAV properties
             if self.oprops is None:
                 return 200
-            if self.oprops.get(ns, {}).get(prop.localName):
-                del self.oprops[ns][prop.localName]
-                if not list(self.oprops[ns].keys()):
-                    del self.oprops[ns]
+            self.oprops.removeProperty(ns, prop.localName)
             return 200
             
         # XXX: Deal with registered ns interfaces here



More information about the Zope3-Checkins mailing list