[Zope3-checkins] CVS: Zope3/src/zope/app/dav/ftests - dav.py:1.1 test_mkcol.py:1.1
Sidnei da Silva
sidnei@x3ng.com.br
Mon, 23 Jun 2003 13:21:09 -0400
Update of /cvs-repository/Zope3/src/zope/app/dav/ftests
In directory cvs.zope.org:/tmp/cvs-serv15059/ftests
Added Files:
dav.py test_mkcol.py
Log Message:
1. Whitespace cleanup. 2. Docstring fixing. 3. Modified DAV code and tests to append '/' to the path if the last element is 'dir-like'. 4. Support for MKCOL with tests + functional tests. 5. Refactored DAV functional tests into a base class for reusing
=== Added File Zope3/src/zope/app/dav/ftests/dav.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Base class for DAV functional tests.
$Id: dav.py,v 1.1 2003/06/23 17:21:08 sidnei Exp $
"""
from zope.testing.functional import HTTPTestCase
from zope.app.content.zpt import ZPTPage
from zope.app.content.folder import Folder
from transaction import get_transaction
__metaclass__ = type
class DAVTestCase(HTTPTestCase):
def createFolders(self, path):
"""createFolders('/a/b/c/d') would traverse and/or create three nested
folders (a, b, c) and return a tuple (c, 'd') where c is a Folder
instance at /a/b/c."""
folder = self.getRootFolder()
if path[0] == '/':
path = path[1:]
path = path.split('/')
for id in path[:-1]:
try:
folder = folder[id]
except KeyError:
folder.setObject(id, Folder())
folder = folder[id]
return folder, path[-1]
def createObject(self, path, obj):
folder, id = self.createFolders(path)
folder.setObject(id, obj)
get_transaction().commit()
def addPage(self, path, content):
page = ZPTPage()
page.source = content
self.createObject(path, page)
=== Added File Zope3/src/zope/app/dav/ftests/test_mkcol.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Functional tests for MKCOL.
$Id: test_mkcol.py,v 1.1 2003/06/23 17:21:08 sidnei Exp $
"""
import unittest
from datetime import datetime
from zope.app.dav.ftests.dav import DAVTestCase
from transaction import get_transaction
__metaclass__ = type
class TestMKCOL(DAVTestCase):
def test_mkcol_not_folderish(self):
self.addPage('/bar/pt', u'<span />')
get_transaction().commit()
self.verifyStatus(path='/bar/pt/foo', body='', basic='mgr:mgrpw', expected=404)
def test_mkcol_not_folderish_existing(self):
self.addPage('/bar/pt', u'<span />')
get_transaction().commit()
self.verifyStatus(path='/bar/pt', body='', basic='mgr:mgrpw', expected=405)
def test_mkcol_not_existing(self):
self.verifyStatus(path='/mkcol_test', body='', basic='mgr:mgrpw', expected=201)
def test_mkcol_parent_not_existing(self):
self.verifyStatus(path='/bar/mkcol_test', body='', basic='mgr:mgrpw',
expected=409)
def test_mkcol_existing(self):
self.createFolders('/bar/mkcol_test')
get_transaction().commit()
self.verifyStatus(path='/bar', body='', basic='mgr:mgrpw',
expected=405)
def test_mkcol_with_body(self):
self.verifyStatus(path='/mkcol_test', body='bla', basic='mgr:mgrpw', \
expected=415)
def verifyStatus(self, path, body, basic, expected=201):
clen = len(body)
result = self.publish(path, basic, env={'REQUEST_METHOD':'MKCOL',
'CONTENT-LENGHT': clen},
request_body=body, handle_errors=True)
self.assertEquals(result.getStatus(), expected)
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestMKCOL))
return suite
if __name__ == '__main__':
unittest.main()