[Zope3-checkins] CVS: Zope3/src/zope/app/http/tests - test_put.py:1.2
Jim Fulton
jim@zope.com
Fri, 28 Feb 2003 17:33:46 -0500
Update of /cvs-repository/Zope3/src/zope/app/http/tests
In directory cvs.zope.org:/tmp/cvs-serv28877/tests
Modified Files:
test_put.py
Log Message:
Changed the add behavior to return a 201 status on success in
accordance to the spec. Thanks to Paul for pointing this out.
Also added a check for any fancy Content-* headers. The spec
says we should fail if we see any we don't understand.
=== Zope3/src/zope/app/http/tests/test_put.py 1.1 => 1.2 ===
--- Zope3/src/zope/app/http/tests/test_put.py:1.1 Fri Feb 7 10:59:38 2003
+++ Zope3/src/zope/app/http/tests/test_put.py Fri Feb 28 17:33:46 2003
@@ -53,27 +53,69 @@
container = Container()
content = "some content\n for testing"
request = TestRequest(StringIO(content), StringIO(),
- {'CONTENT_TYPE': 'test/foo'})
+ {'CONTENT_TYPE': 'test/foo',
+ 'CONTENT_LENGTH': str(len(content)),
+ })
null = zope.app.http.put.NullResource(container, 'spam')
put = zope.app.http.put.NullPUT(null, request)
self.assertEqual(getattr(container, 'spam', None), None)
self.assertEqual(put.PUT(), '')
+ request.response.setBody('')
file = container.spam
self.assertEqual(file.__class__, File)
self.assertEqual(file.name, 'spam')
self.assertEqual(file.content_type, 'test/foo')
self.assertEqual(file.data, content)
+ # Check HTTP Response
+ self.assertEqual(request.response.getStatus(), 201)
+
+ def test_bad_content_header(self):
+ container = Container()
+ content = "some content\n for testing"
+ request = TestRequest(StringIO(content), StringIO(),
+ {'CONTENT_TYPE': 'test/foo',
+ 'CONTENT_LENGTH': str(len(content)),
+ 'HTTP_CONTENT_FOO': 'Bar',
+ })
+ null = zope.app.http.put.NullResource(container, 'spam')
+ put = zope.app.http.put.NullPUT(null, request)
+ self.assertEqual(getattr(container, 'spam', None), None)
+ self.assertEqual(put.PUT(), '')
+ request.response.setBody('')
+
+ # Check HTTP Response
+ self.assertEqual(request.response.getStatus(), 501)
+
class TestFilePUT(PlacelessSetup, TestCase):
def test(self):
file = File("thefile", "text/x", "initial content")
content = "some content\n for testing"
request = TestRequest(StringIO(content), StringIO(),
- {'CONTENT_TYPE': 'test/foo'})
+ {'CONTENT_TYPE': 'test/foo',
+ 'CONTENT_LENGTH': str(len(content)),
+ })
put = zope.app.http.put.FilePUT(file, request)
self.assertEqual(put.PUT(), '')
+ request.response.setBody('')
self.assertEqual(file.data, content)
+
+ def test_bad_content_header(self):
+ file = File("thefile", "text/x", "initial content")
+ content = "some content\n for testing"
+ request = TestRequest(StringIO(content), StringIO(),
+ {'CONTENT_TYPE': 'test/foo',
+ 'CONTENT_LENGTH': str(len(content)),
+ 'HTTP_CONTENT_FOO': 'Bar',
+ })
+ put = zope.app.http.put.FilePUT(file, request)
+ self.assertEqual(put.PUT(), '')
+ request.response.setBody('')
+ self.assertEqual(file.data, "initial content")
+
+ # Check HTTP Response
+ self.assertEqual(request.response.getStatus(), 501)
def test_suite():
return TestSuite((