~hardware-certification/zope3/certify-staging-2.5

« back to all changes in this revision

Viewing changes to src/zope/app/http/tests/test_functional_put.py

  • Committer: Marc Tardif
  • Date: 2008-04-26 19:03:34 UTC
  • Revision ID: cr3@lime-20080426190334-u16xo4llz56vliqf
Initial import.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##############################################################################
 
2
#
 
3
# Copyright (c) 2003 Zope Corporation and Contributors.
 
4
# All Rights Reserved.
 
5
#
 
6
# This software is subject to the provisions of the Zope Public License,
 
7
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
 
8
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
 
9
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
10
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 
11
# FOR A PARTICULAR PURPOSE.
 
12
#
 
13
##############################################################################
 
14
"""Test HTTP PUT verb
 
15
 
 
16
$Id: test_functional_put.py 81052 2007-10-24 19:16:25Z srichter $
 
17
"""
 
18
 
 
19
from unittest import TestSuite, makeSuite
 
20
 
 
21
from zope.app.testing.functional import FunctionalTestCase, HTTPCaller
 
22
from zope.app.http.testing import AppHttpLayer
 
23
 
 
24
class TestPUT(FunctionalTestCase):
 
25
    def test_put(self):
 
26
        # PUT something for the first time
 
27
        response = HTTPCaller()(r"""PUT /testfile.txt HTTP/1.1
 
28
Authorization: Basic bWdyOm1ncnB3
 
29
Content-Length: 20
 
30
Content-Type: text/plain
 
31
 
 
32
This is just a test.""")
 
33
        self.assertEquals(response._response.getStatus(), 201)
 
34
        self.assertEquals(response._response.getHeader("Location"),
 
35
                          "http://localhost/testfile.txt")
 
36
 
 
37
        response = HTTPCaller()(r"""GET /testfile.txt HTTP/1.1
 
38
Authorization: Basic bWdyOm1ncnB3""")
 
39
        self.assertEquals(response.getBody(), "This is just a test.")
 
40
 
 
41
        # now modify it
 
42
        response = HTTPCaller()(r"""PUT /testfile.txt HTTP/1.1
 
43
Authorization: Basic bWdyOm1ncnB3
 
44
Content-Length: 22
 
45
Content-Type: text/plain
 
46
 
 
47
And now it is modified.""")
 
48
        self.assertEquals(response._response.getStatus(), 200)
 
49
        self.assertEquals(response.getBody(), "")
 
50
 
 
51
        response = HTTPCaller()(r"""GET /testfile.txt HTTP/1.1
 
52
Authorization: Basic bWdyOm1ncnB3""")
 
53
        self.assertEquals(response.getBody(), "And now it is modified.")
 
54
        
 
55
        
 
56
def test_suite():
 
57
    TestPUT.layer = AppHttpLayer
 
58
    return TestSuite((
 
59
        makeSuite(TestPUT),
 
60
        ))