~landscape/zope3/newer-from-ztk

« back to all changes in this revision

Viewing changes to src/twisted/web2/dav/test/test_mkcol.py

  • Committer: Thomas Hervé
  • Date: 2009-07-08 13:52:04 UTC
  • Revision ID: thomas@canonical.com-20090708135204-df5eesrthifpylf8
Remove twisted copy

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
##
2
 
# Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
3
 
#
4
 
# Permission is hereby granted, free of charge, to any person obtaining a copy
5
 
# of this software and associated documentation files (the "Software"), to deal
6
 
# in the Software without restriction, including without limitation the rights
7
 
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
 
# copies of the Software, and to permit persons to whom the Software is
9
 
# furnished to do so, subject to the following conditions:
10
 
11
 
# The above copyright notice and this permission notice shall be included in all
12
 
# copies or substantial portions of the Software.
13
 
14
 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
 
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
 
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
 
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
 
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
 
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
 
# SOFTWARE.
21
 
#
22
 
# DRI: Wilfredo Sanchez, wsanchez@apple.com
23
 
##
24
 
 
25
 
import os
26
 
 
27
 
from twisted.web2 import responsecode
28
 
from twisted.web2.iweb import IResponse
29
 
from twisted.web2.stream import MemoryStream
30
 
from twisted.web2.dav.fileop import rmdir
31
 
from twisted.web2.test.test_server import SimpleRequest
32
 
import twisted.web2.dav.test.util
33
 
 
34
 
class MKCOL(twisted.web2.dav.test.util.TestCase):
35
 
    """
36
 
    MKCOL request
37
 
    """
38
 
    # FIXME:
39
 
    # Try in nonexistant parent collection.
40
 
    # Try on existing resource.
41
 
    # Try with request body?
42
 
    def test_MKCOL(self):
43
 
        """
44
 
        MKCOL request
45
 
        """
46
 
        path, uri = self.mkdtemp("collection")
47
 
 
48
 
        rmdir(path)
49
 
 
50
 
        def check_result(response):
51
 
            response = IResponse(response)
52
 
 
53
 
            if response.code != responsecode.CREATED:
54
 
                self.fail("MKCOL response %s != %s" % (response.code, responsecode.CREATED))
55
 
 
56
 
            if not os.path.isdir(path):
57
 
                self.fail("MKCOL did not create directory %s" % (path,))
58
 
 
59
 
        request = SimpleRequest(self.site, "MKCOL", uri)
60
 
 
61
 
        return self.send(request, check_result)
62
 
 
63
 
    def test_MKCOL_invalid_body(self):
64
 
        """
65
 
        MKCOL request with invalid request body
66
 
        (Any body at all is invalid in our implementation; there is no
67
 
        such thing as a valid body.)
68
 
        """
69
 
        path, uri = self.mkdtemp("collection")
70
 
 
71
 
        rmdir(path)
72
 
 
73
 
        def check_result(response):
74
 
            response = IResponse(response)
75
 
 
76
 
            if response.code != responsecode.UNSUPPORTED_MEDIA_TYPE:
77
 
                self.fail("MKCOL response %s != %s" % (response.code, responsecode.UNSUPPORTED_MEDIA_TYPE))
78
 
 
79
 
            if os.path.isdir(path):
80
 
                self.fail("MKCOL incorrectly created directory %s" % (path,))
81
 
 
82
 
        request = SimpleRequest(self.site, "MKCOL", uri)
83
 
        request.stream = MemoryStream("This is not a valid MKCOL request body.")
84
 
 
85
 
        return self.send(request, check_result)