[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Publisher/Browser/tests - test.gif:1.1 test.txt:1.1 testFileResource.py:1.1 testResources.py:1.1 testDirectives.py:1.3
Jim Fulton
jim@zope.com
Thu, 13 Jun 2002 19:16:15 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/Publisher/Browser/tests
In directory cvs.zope.org:/tmp/cvs-serv10697/lib/python/Zope/App/Publisher/Browser/tests
Modified Files:
testDirectives.py
Added Files:
test.gif test.txt testFileResource.py testResources.py
Log Message:
Got icons working, and, along the way:
- Implemented the icon directive
- Implemented
http://dev.zope.org/Wikis/DevSite/Projects/ComponentArchitecture/ResourcesProposal
- Added a special view, named '', for service manager containers that
allows resources to have URLs like:
http://foo.com/@@/resourcename
- Fixed some server code that caused HTTP response data to get
promoted to unicode
- Updated the folder contents page to display icons.
- Ported icons for folder, file, image, and zptpage. Many more icons
need to be ported or created.
=== Added File Zope3/lib/python/Zope/App/Publisher/Browser/tests/test.gif ===
<Binary-ish file>
=== Added File Zope3/lib/python/Zope/App/Publisher/Browser/tests/test.txt ===
test
data
=== Added File Zope3/lib/python/Zope/App/Publisher/Browser/tests/testFileResource.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.
#
##############################################################################
"""
Revision information:
$Id: testFileResource.py,v 1.1 2002/06/13 23:15:44 jim Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
import os
from Zope.Exceptions import NotFoundError
from Zope.Publisher.Browser.BrowserRequest import TestRequest
import Zope.App.Publisher.Browser.tests as p
test_directory = os.path.split(p.__file__)[0]
from Zope.App.Publisher.Browser.FileResource import FileResourceFactory
from Zope.App.Publisher.Browser.FileResource import ImageResourceFactory
class Test(TestCase):
def testNoTraversal(self):
path = os.path.join(test_directory, 'test.txt')
resource = FileResourceFactory(path)(TestRequest())
self.assertRaises(NotFoundError,
resource.publishTraverse,
resource.request,
'_testData')
def testFileGET(self):
path = os.path.join(test_directory, 'test.txt')
resource = FileResourceFactory(path)(TestRequest())
self.assertEqual(resource.GET(), open(path, 'rb').read())
response = resource.request.getResponse()
self.assertEqual(response.getHeader('Content-Type'), 'text/plain')
def testFileHEAD(self):
path = os.path.join(test_directory, 'test.txt')
resource = FileResourceFactory(path)(TestRequest())
self.assertEqual(resource.HEAD(), '')
response = resource.request.getResponse()
self.assertEqual(response.getHeader('Content-Type'), 'text/plain')
def testImageGET(self):
path = os.path.join(test_directory, 'test.gif')
resource = ImageResourceFactory(path)(TestRequest())
self.assertEqual(resource.GET(), open(path, 'rb').read())
response = resource.request.getResponse()
self.assertEqual(response.getHeader('Content-Type'), 'image/gif')
def testImageHEAD(self):
path = os.path.join(test_directory, 'test.gif')
resource = ImageResourceFactory(path)(TestRequest())
self.assertEqual(resource.HEAD(), '')
response = resource.request.getResponse()
self.assertEqual(response.getHeader('Content-Type'), 'image/gif')
def test_suite():
return TestSuite((
makeSuite(Test),
))
if __name__=='__main__':
main(defaultTest='test_suite')
=== Added File Zope3/lib/python/Zope/App/Publisher/Browser/tests/testResources.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.
#
##############################################################################
"""
Revision information:
$Id: testResources.py,v 1.1 2002/06/13 23:15:44 jim Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from Zope.Publisher.Browser.BrowserRequest import TestRequest
from Zope.ComponentArchitecture.tests.PlacelessSetup import PlacelessSetup
from Zope.ComponentArchitecture.GlobalResourceService import provideResource
from Zope.Publisher.Browser.IBrowserView import IBrowserView
class Test(PlacelessSetup, TestCase):
def test(self):
from Zope.App.Publisher.Browser.Resources import Resources
request = TestRequest()
class Resource:
def __init__(self, request): pass
def __call__(self): return 42
provideResource('test', IBrowserView, Resource)
view = Resources(None, request)
resource = view.publishTraverse(request, 'test')
self.assertEqual(resource(), 42)
def test_suite():
return TestSuite((
makeSuite(Test),
))
if __name__=='__main__':
main(defaultTest='test_suite')
=== Zope3/lib/python/Zope/App/Publisher/Browser/tests/testDirectives.py 1.2 => 1.3 ===
from Zope.ComponentArchitecture import getDefaultViewName, getResource
from Zope.ComponentArchitecture.tests.PlacelessSetup import PlacelessSetup
+from Zope.Security.Proxy import ProxyFactory
from cStringIO import StringIO
from Zope.ComponentArchitecture.tests.Request import Request
@@ -168,6 +169,7 @@
))
v = getView(ob, 'test', request)
+ v = ProxyFactory(v)
self.assertEqual(v.index(), 'V1 here')
self.assertRaises(Exception, getattr, v, 'action')
@@ -184,6 +186,7 @@
))
v = getView(ob, 'test', request)
+ v = ProxyFactory(v)
self.assertEqual(v.action(), 'done')
self.assertRaises(Exception, getattr, v, 'index')
@@ -358,6 +361,26 @@
v = getResource(ob, 'action.html', request)
self.assertEqual(v(), 'R done')
+
+ def testFile(self):
+ path = os.path.join(os.path.split(defs_path)[0], 'tests', 'test.pt')
+
+ self.assertEqual(queryResource(ob, 'test', request),
+ None)
+
+ xmlconfig(StringIO(template %
+ """
+ <browser:resource
+ name="index.html"
+ file="%s"
+ />
+ """ % path
+ ))
+
+ v = getResource(ob, 'index.html', request)
+ self.assertEqual(v._testData(), open(path, 'rb').read())
+
+
def testtemplate(self):
path = os.path.join(os.path.split(defs_path)[0], 'tests', 'test.pt')
@@ -415,9 +438,11 @@
newSecurityManager('someuser')
v = getView(ob, 'xxx.html', request)
+ v = ProxyFactory(v)
self.assertRaises(Exception, v)
v = getView(ob, 'index.html', request)
+ v = ProxyFactory(v)
self.assertEqual(v().strip(), '<html><body><p>test</p></body></html>')