[Zope3-checkins] SVN: Zope3/trunk/ Fixed issue 497: HTTP DELETE now
returns 405 Method Not Allowed when the
Marius Gedminas
marius at pov.lt
Fri Dec 16 13:48:14 EST 2005
Log message for revision 40823:
Fixed issue 497: HTTP DELETE now returns 405 Method Not Allowed when the
container cannot be adapted to IWriteDirectory.
Changed:
U Zope3/trunk/doc/CHANGES.txt
U Zope3/trunk/src/zope/app/http/delete.py
U Zope3/trunk/src/zope/app/http/tests/test_delete.py
U Zope3/trunk/src/zope/app/publication/methodnotallowed.txt
-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt 2005-12-16 18:46:35 UTC (rev 40822)
+++ Zope3/trunk/doc/CHANGES.txt 2005-12-16 18:48:13 UTC (rev 40823)
@@ -17,6 +17,9 @@
attributes were ignored if you didn't explicitly specify a
class for the viewlet.
+ - Fixed issue 497: HTTP DELETE now returns 405 Method Not Allowed
+ when the container cannot be adapted to IWriteDirectory.
+
------------------------------------------------------------------
Zope 3.2.0b1 (2005/12/06)
Modified: Zope3/trunk/src/zope/app/http/delete.py
===================================================================
--- Zope3/trunk/src/zope/app/http/delete.py 2005-12-16 18:46:35 UTC (rev 40822)
+++ Zope3/trunk/src/zope/app/http/delete.py 2005-12-16 18:48:13 UTC (rev 40823)
@@ -16,7 +16,9 @@
__docformat__ = 'restructuredtext'
from zope.app.filerepresentation.interfaces import IWriteDirectory
+from zope.app.publication.http import MethodNotAllowed
+
class DELETE(object):
"""Delete handler for all objects
"""
@@ -34,7 +36,9 @@
# Get a "directory" surrogate for the container
- dir = IWriteDirectory(container)
+ dir = IWriteDirectory(container, None)
+ if dir is None:
+ raise MethodNotAllowed(self.context, self.request)
del dir[name]
Modified: Zope3/trunk/src/zope/app/http/tests/test_delete.py
===================================================================
--- Zope3/trunk/src/zope/app/http/tests/test_delete.py 2005-12-16 18:46:35 UTC (rev 40822)
+++ Zope3/trunk/src/zope/app/http/tests/test_delete.py 2005-12-16 18:48:13 UTC (rev 40823)
@@ -22,7 +22,13 @@
from zope.app.testing.placelesssetup import PlacelessSetup
from zope.interface import implements
from zope.app.container.contained import contained
+from zope.app.publication.http import MethodNotAllowed
+
+class UnwritableContainer(object):
+ pass
+
+
class Container(object):
implements(IWriteDirectory, IFileFactory)
@@ -44,6 +50,15 @@
self.assertEqual(delete.DELETE(), '')
self.assert_(not hasattr(container, 'a'))
+ def test_not_deletable(self):
+ container = UnwritableContainer()
+ container.a = 'spam'
+ item = contained(UnwritableContainer(), container, name='a')
+ request = TestRequest()
+ delete = zope.app.http.delete.DELETE(item, request)
+ self.assertRaises(MethodNotAllowed, delete.DELETE)
+
+
def test_suite():
return TestSuite((
makeSuite(TestDelete),
Modified: Zope3/trunk/src/zope/app/publication/methodnotallowed.txt
===================================================================
--- Zope3/trunk/src/zope/app/publication/methodnotallowed.txt 2005-12-16 18:46:35 UTC (rev 40822)
+++ Zope3/trunk/src/zope/app/publication/methodnotallowed.txt 2005-12-16 18:48:13 UTC (rev 40823)
@@ -13,17 +13,17 @@
<BLANKLINE>
Method Not Allowed
-The requests below should return 405, but instead crash with a TypeError,
+ >>> print http(r"""
+ ... DELETE / HTTP/1.1
+ ... Authorization: Basic mgr:mgrpw
+ ... """)
+ HTTP/1.1 405 Method Not Allowed
+ ...
+
+The request below should return 405, but instead crashes with a TypeError,
when the view tries to adapt context to IWriteFile.
# >>> print http(r"""
-# ... DELETE / HTTP/1.1
-# ... Authorization: Basic mgr:mgrpw
-# ... """, handle_errors=False)
-# HTTP/1.1 405 Method Not Allowed
-# ...
-#
-# >>> print http(r"""
# ... PUT / HTTP/1.1
# ... Authorization: Basic mgr:mgrpw
# ... """, handle_errors=False)
More information about the Zope3-Checkins
mailing list