[Zope-CVS] CVS: Packages/Moztop/moztopsupport/dav/tests - test_propfind.py:1.5
Sidnei da Silva
sidnei@x3ng.com.br
Sat, 29 Mar 2003 12:10:25 -0500
Update of /cvs-repository/Packages/Moztop/moztopsupport/dav/tests
In directory cvs.zope.org:/tmp/cvs-serv26151/moztopsupport/dav/tests
Modified Files:
test_propfind.py
Log Message:
Adding working propfind with depth, except allprop. MKCOL is working. TRACE and placeholder classes for MOVE and COPY
=== Packages/Moztop/moztopsupport/dav/tests/test_propfind.py 1.4 => 1.5 ===
--- Packages/Moztop/moztopsupport/dav/tests/test_propfind.py:1.4 Tue Mar 25 16:16:01 2003
+++ Packages/Moztop/moztopsupport/dav/tests/test_propfind.py Sat Mar 29 12:09:54 2003
@@ -31,11 +31,29 @@
from zope.app.browser.absoluteurl import AbsoluteURL
from zope.pagetemplate.tests.util import normalize_xml
from zope.schema import getFieldNamesInOrder
+from zope.app.interfaces.container import IReadContainer
from moztopsupport.dav import propfind
from moztopsupport.dav.views import ZPTDAVSource
from moztopsupport.dav.interfaces import IDAVSource, IDAVSchema
+class Folder:
+
+ __implements__ = IReadContainer
+
+ def __init__(self, name, level=0):
+ self.name = name
+ self.level=level
+
+ def items(self):
+ if self.level == 2:
+ return (('last', File('last', 'text/plain', 'blablabla')),)
+ result = []
+ for i in range(1, 5):
+ result.append((str(i), File(str(i), 'text/plain', 'blablabla')))
+ result.append(('sub1', Folder('sub1', level=self.level+1)))
+ return tuple(result)
+
class File:
__implements__ = IWriteFile
@@ -90,8 +108,10 @@
zpt = FooZPT()
self.content = "some content\n for testing"
file = File('spam', 'text/plain', self.content)
+ folder = Folder('bla')
root.setObject('file', file)
root.setObject('zpt', zpt)
+ root.setObject('folder', folder)
self.zpt = traverse(root, 'zpt')
self.file = traverse(root, 'file')
provideView=getService(None, Views).provideView
@@ -99,6 +119,8 @@
[ZPTDAVSource])
provideView(None, 'absolute_url', IBrowserPresentation,
[AbsoluteURL])
+ provideView(None, 'PROPFIND', IBrowserPresentation,
+ [propfind.PROPFIND])
def test_contenttype1(self):
file = self.file
@@ -178,12 +200,12 @@
pfind.PROPFIND()
# Check HTTP Response
self.assertEqual(request.response.getStatus(), 400)
- self.assertEqual(pfind.getDepth(), 'infinity')
+ self.assertEqual(pfind.getDepth(), 'full')
def test_zptdavsrc(self):
root = self.rootFolder
zpt = traverse(root, 'zpt')
- body = '''<?xml version="1.0" encoding="utf-8" ?>
+ body = '''<?xml version="1.0" encoding="utf-8"?>
<D:propfind xmlns:D="DAV:">
<D:prop>
<D:source/>
@@ -197,7 +219,7 @@
resource_url = str(getView(zpt, 'absolute_url', request))
- expect = '''<?xml version="1.0" encoding="utf-8" ?>
+ expect = '''<?xml version="1.0" encoding="utf-8"?>
<D:multistatus xmlns:D="DAV:">
<D:response>
<D:href>%(resource_url)s</D:href>
@@ -229,7 +251,7 @@
def test_davpropname(self):
root = self.rootFolder
zpt = traverse(root, 'zpt')
- body = '''<?xml version="1.0" encoding="utf-8" ?>
+ body = '''<?xml version="1.0" encoding="utf-8"?>
<propfind xmlns="DAV:">
<propname/>
</propfind>
@@ -243,8 +265,8 @@
props = getFieldNamesInOrder(IDAVSchema)
props_xml = ''
for p in props:
- props_xml += '<D:%s />' % p
- expect = '''<?xml version="1.0" encoding="utf-8" ?>
+ props_xml += '<D:%s/>' % p
+ expect = '''<?xml version="1.0" encoding="utf-8"?>
<D:multistatus xmlns:D="DAV:">
<D:response>
<D:href>%(resource_url)s</D:href>
@@ -260,11 +282,139 @@
'props_xml':props_xml}
pfind = propfind.PROPFIND(zpt, request)
+ pfind.PROPFIND()
+ # Check HTTP Response
+ self.assertEqual(request.response.getStatus(), 207)
+ self.assertEqual(pfind.getDepth(), '0')
+ s1 = normalize_xml(request.response._body)
+ s2 = normalize_xml(expect)
+ self.assertEqual(s1, s2)
+
+ def test_davpropnamefolderdepth0(self):
+ root = self.rootFolder
+ folder = traverse(root, 'folder')
+ body = '''<?xml version="1.0" encoding="utf-8"?>
+ <propfind xmlns="DAV:">
+ <propname/>
+ </propfind>
+ '''
+
+ request = _createRequest(body=body,
+ headers={'Content-type':'text/xml',
+ 'Depth':'0'})
+
+ resource_url = str(getView(folder, 'absolute_url', request))
+ props = getFieldNamesInOrder(IDAVSchema)
+ props_xml = ''
+ for p in props:
+ props_xml += '<D:%s/>' % p
+ expect = '''<?xml version="1.0" encoding="utf-8"?>
+ <D:multistatus xmlns:D="DAV:">
+ <D:response>
+ <D:href>%(resource_url)s</D:href>
+ <D:propstat>
+ <D:prop>
+ %(props_xml)s
+ </D:prop>
+ <D:status>HTTP/1.1 200 OK</D:status>
+ </D:propstat>
+ </D:response>
+ </D:multistatus>
+ ''' % {'resource_url':resource_url,
+ 'props_xml':props_xml}
+
+ pfind = propfind.PROPFIND(folder, request)
pfind.PROPFIND()
# Check HTTP Response
self.assertEqual(request.response.getStatus(), 207)
self.assertEqual(pfind.getDepth(), '0')
+ s1 = normalize_xml(request.response._body)
+ s2 = normalize_xml(expect)
+ self.assertEqual(s1, s2)
+
+ def test_davpropnamefolderdepth1(self):
+ root = self.rootFolder
+ folder = traverse(root, 'folder')
+ body = '''<?xml version="1.0" encoding="utf-8"?>
+ <propfind xmlns="DAV:">
+ <propname/>
+ </propfind>
+ '''
+
+ request = _createRequest(body=body,
+ headers={'Content-type':'text/xml',
+ 'Depth':'1'})
+
+ resource_url = str(getView(folder, 'absolute_url', request))
+ props = getFieldNamesInOrder(IDAVSchema)
+ props_xml = ''
+ for p in props:
+ props_xml += '<D:%s/>' % p
+ expect = '''<?xml version="1.0" encoding="utf-8"?>
+ <D:multistatus xmlns:D="DAV:">
+ <D:response>
+ <D:href>%(resource_url)s</D:href>
+ <D:propstat>
+ <D:prop>
+ %(props_xml)s
+ </D:prop>
+ <D:status>HTTP/1.1 200 OK</D:status>
+ </D:propstat>
+ </D:response>
+ </D:multistatus>
+ ''' % {'resource_url':resource_url,
+ 'props_xml':props_xml}
+
+ pfind = propfind.PROPFIND(folder, request)
+
+ pfind.PROPFIND()
+ # Check HTTP Response
+ self.assertEqual(request.response.getStatus(), 207)
+ self.assertEqual(pfind.getDepth(), '1')
+ s1 = normalize_xml(request.response._body)
+ s2 = normalize_xml(expect)
+ self.assertEqual(s1, s2)
+
+ def test_davpropnamefolderdepthinfinity(self):
+ root = self.rootFolder
+ folder = traverse(root, 'folder')
+ body = '''<?xml version="1.0" encoding="utf-8"?>
+ <propfind xmlns="DAV:">
+ <propname/>
+ </propfind>
+ '''
+
+ request = _createRequest(body=body,
+ headers={'Content-type':'text/xml',
+ 'Depth':'infinity'})
+
+ resource_url = str(getView(folder, 'absolute_url', request))
+ props = getFieldNamesInOrder(IDAVSchema)
+ props_xml = ''
+ for p in props:
+ props_xml += '<D:%s/>' % p
+ expect = '''<?xml version="1.0" encoding="utf-8"?>
+ <D:multistatus xmlns:D="DAV:">
+ <D:response>
+ <D:href>%(resource_url)s</D:href>
+ <D:propstat>
+ <D:prop>
+ %(props_xml)s
+ </D:prop>
+ <D:status>HTTP/1.1 200 OK</D:status>
+ </D:propstat>
+ </D:response>
+ </D:multistatus>
+ ''' % {'resource_url':resource_url,
+ 'props_xml':props_xml}
+
+ pfind = propfind.PROPFIND(folder, request)
+
+ pfind.PROPFIND()
+ # Check HTTP Response
+ self.assertEqual(request.response.getStatus(), 207)
+ self.assertEqual(pfind.getDepth(), 'infinity')
s1 = normalize_xml(request.response._body)
s2 = normalize_xml(expect)
self.assertEqual(s1, s2)