2
# Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
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:
11
# The above copyright notice and this permission notice shall be included in all
12
# copies or substantial portions of the Software.
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
22
# DRI: Wilfredo Sanchez, wsanchez@apple.com
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
34
class MKCOL(twisted.web2.dav.test.util.TestCase):
39
# Try in nonexistant parent collection.
40
# Try on existing resource.
41
# Try with request body?
46
path, uri = self.mkdtemp("collection")
50
def check_result(response):
51
response = IResponse(response)
53
if response.code != responsecode.CREATED:
54
self.fail("MKCOL response %s != %s" % (response.code, responsecode.CREATED))
56
if not os.path.isdir(path):
57
self.fail("MKCOL did not create directory %s" % (path,))
59
request = SimpleRequest(self.site, "MKCOL", uri)
61
return self.send(request, check_result)
63
def test_MKCOL_invalid_body(self):
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.)
69
path, uri = self.mkdtemp("collection")
73
def check_result(response):
74
response = IResponse(response)
76
if response.code != responsecode.UNSUPPORTED_MEDIA_TYPE:
77
self.fail("MKCOL response %s != %s" % (response.code, responsecode.UNSUPPORTED_MEDIA_TYPE))
79
if os.path.isdir(path):
80
self.fail("MKCOL incorrectly created directory %s" % (path,))
82
request = SimpleRequest(self.site, "MKCOL", uri)
83
request.stream = MemoryStream("This is not a valid MKCOL request body.")
85
return self.send(request, check_result)