[Zope-CVS] CVS: Packages/Moztop/moztopsupport/dav/tests - __init__.py:1.1 test_davschema.py:1.1 test_propfind.py:1.1
Sidnei da Silva
sidnei@x3ng.com.br
Mon, 24 Mar 2003 06:26:32 -0500
Update of /cvs-repository/Packages/Moztop/moztopsupport/dav/tests
In directory cvs.zope.org:/tmp/cvs-serv24465/dav/tests
Added Files:
__init__.py test_davschema.py test_propfind.py
Log Message:
Initial support for PROPFIND. I need to figure out how to parse XML this week. :)
=== Added File Packages/Moztop/moztopsupport/dav/tests/__init__.py ===
#
# This file is necessary to make this directory a package.
=== Added File Packages/Moztop/moztopsupport/dav/tests/test_davschema.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 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.
#
##############################################################################
"""
$Id: test_davschema.py,v 1.1 2003/03/24 11:26:31 sidnei Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from zope.schema import getFields, getFieldsInOrder
from zope.schema import getFieldNames, getFieldNamesInOrder
from moztopsupport.dav.interfaces import IDAVSchema
class DAVSchemaTest(TestCase):
def test_getFieldNames(self):
names = getFieldNames(IDAVSchema)
self.assertEqual(len(names),11)
self.assert_('creationdate' in names)
self.assert_('displayname' in names)
self.assert_('getcontentlanguage' in names)
self.assert_('getcontentlength' in names)
self.assert_('getcontenttype' in names)
self.assert_('getetag' in names)
self.assert_('getlastmodified' in names)
self.assert_('lockdiscovery' in names)
self.assert_('resourcetype' in names)
self.assert_('source' in names)
self.assert_('supportedlock' in names)
def test_getFields(self):
fields = getFields(IDAVSchema)
self.assert_(fields.has_key('creationdate'))
self.assert_(fields.has_key('displayname'))
self.assert_(fields.has_key('getcontentlanguage'))
self.assert_(fields.has_key('getcontentlength'))
self.assert_(fields.has_key('getcontenttype'))
self.assert_(fields.has_key('getetag'))
self.assert_(fields.has_key('getlastmodified'))
self.assert_(fields.has_key('lockdiscovery'))
self.assert_(fields.has_key('resourcetype'))
self.assert_(fields.has_key('source'))
self.assert_(fields.has_key('supportedlock'))
# test whether getName() has the right value
for key, value in fields.iteritems():
self.assertEquals(key, value.getName())
def test_getFieldsInOrder(self):
fields = getFieldsInOrder(IDAVSchema)
field_names = [name for name, field in fields]
self.assertEquals(field_names, ['creationdate', 'displayname',
'source',
'getcontentlanguage',
'getcontentlength',
'getcontenttype', 'getetag',
'getlastmodified',
'resourcetype',
'lockdiscovery',
'supportedlock'])
for key, value in fields:
self.assertEquals(key, value.getName())
def test_getFieldsNamesInOrder(self):
names = getFieldNamesInOrder(IDAVSchema)
self.assertEquals(names, ['creationdate', 'displayname',
'source', 'getcontentlanguage',
'getcontentlength',
'getcontenttype', 'getetag',
'getlastmodified', 'resourcetype',
'lockdiscovery', 'supportedlock'])
def test_suite():
return makeSuite(DAVSchemaTest)
if __name__ == '__main__':
main(defaultTest='test_suite')
=== Added File Packages/Moztop/moztopsupport/dav/tests/test_propfind.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.
#
##############################################################################
"""
$Id: test_propfind.py,v 1.1 2003/03/24 11:26:31 sidnei Exp $
"""
__metaclass__ = type
from unittest import TestCase, TestSuite, main, makeSuite
from StringIO import StringIO
from zope.interface import Interface
from zope.publisher.browser import TestRequest
from zope.app.interfaces.file import IWriteFile
from zope.app.tests.placelesssetup import PlacelessSetup
from moztopsupport.dav import propfind
class File:
__implements__ = IWriteFile
def __init__(self, name, content_type, data):
self.name = name
self.content_type = content_type
self.data = data
def write(self, data):
self.data = data
def setHeader(request, header, value):
header = header.upper()
request._environ.update({header:value})
class TestPROPFIND(PlacelessSetup, TestCase):
def setUp(self):
PlacelessSetup.setUp(self)
self.body = '''\
<?xml version="1.0" encoding="utf-8" ?>
<D:propfind xmlns:D="DAV:">
<D:prop xmlns:R="http://www.foo.bar/boxschema/">
<R:bigbox/>
<R:author/>
<R:DingALing/>
<R:Random/>
</D:prop>
</D:propfind>
'''
self.content = "some content\n for testing"
self.file = File('spam', 'text/plain', self.content)
self.request = TestRequest(StringIO(self.body), StringIO(),
{'CONTENT_TYPE': 'text/xml',
'CONTENT_LENGTH': str(len(self.body)),
})
def test_contenttype1(self):
file = self.file
request = self.request
setHeader(request, 'Content-type', 'text/xml')
pfind = propfind.PROPFIND(file, request)
pfind.PROPFIND()
# Check HTTP Response
self.assertEqual(request.response.getStatus(), 207)
def test_contenttype2(self):
file = self.file
request = self.request
setHeader(request, 'Content-type', 'application/xml')
pfind = propfind.PROPFIND(file, request)
pfind.PROPFIND()
# Check HTTP Response
self.assertEqual(request.response.getStatus(), 207)
def test_bad_contenttype(self):
file = self.file
request = self.request
setHeader(request, 'Content-type', 'text/foo')
pfind = propfind.PROPFIND(file, request)
pfind.PROPFIND()
# Check HTTP Response
self.assertEqual(request.response.getStatus(), 207)
def test_nodepth(self):
file = self.file
request = self.request
setHeader(request, 'Content-type', 'text/xml')
pfind = propfind.PROPFIND(file, request)
pfind.PROPFIND()
# Check HTTP Response
self.assertEqual(request.response.getStatus(), 207)
self.assertEqual(pfind.getDepth(), 'infinity')
def test_depth0(self):
file = self.file
request = self.request
setHeader(request, 'Content-type', 'text/xml')
setHeader(request, 'Depth', '0')
pfind = propfind.PROPFIND(file, request)
pfind.PROPFIND()
# Check HTTP Response
self.assertEqual(request.response.getStatus(), 207)
self.assertEqual(pfind.getDepth(), '0')
def test_depth1(self):
file = self.file
request = self.request
setHeader(request, 'Content-type', 'text/xml')
setHeader(request, 'Depth', '1')
pfind = propfind.PROPFIND(file, request)
pfind.PROPFIND()
# Check HTTP Response
self.assertEqual(request.response.getStatus(), 207)
self.assertEqual(pfind.getDepth(), '1')
def test_depthinf(self):
file = self.file
request = self.request
setHeader(request, 'Content-type', 'text/xml')
setHeader(request, 'Depth', 'infinity')
pfind = propfind.PROPFIND(file, request)
pfind.PROPFIND()
# Check HTTP Response
self.assertEqual(request.response.getStatus(), 207)
self.assertEqual(pfind.getDepth(), 'infinity')
def test_depthinvalid(self):
file = self.file
request = self.request
setHeader(request, 'Content-type', 'text/xml')
setHeader(request, 'Depth', 'full')
pfind = propfind.PROPFIND(file, request)
pfind.PROPFIND()
# Check HTTP Response
self.assertEqual(request.response.getStatus(), 400)
self.assertEqual(pfind.getDepth(), 'infinity')
def test_suite():
return TestSuite((
makeSuite(TestPROPFIND),
))
if __name__ == '__main__':
main(defaultTest='test_suite')