[Zope3-checkins] CVS: Zope3/src/zope/app/publisher/browser/tests - test_directoryresource.py:1.1 test_pagetemplateresource.py:1.1 test_directives.py:1.22 test_fileresource.py:1.7 test_icondirective.py:1.9 testi18nfileresource.py:1.5 test.gif:NONE test.pt:NONE test.txt:NONE test2.pt:NONE test3.pt:NONE testusage.pt:NONE

Philipp von Weitershausen philikon at philikon.de
Mon Aug 11 11:58:53 EDT 2003


Update of /cvs-repository/Zope3/src/zope/app/publisher/browser/tests
In directory cvs.zope.org:/tmp/cvs-serv28048/browser/tests

Modified Files:
	test_directives.py test_fileresource.py test_icondirective.py 
	testi18nfileresource.py 
Added Files:
	test_directoryresource.py test_pagetemplateresource.py 
Removed Files:
	test.gif test.pt test.txt test2.pt test3.pt testusage.pt 
Log Message:
Added implementations and tests for

a) PageTemplateResource

  This allows resources to be page templates. They will not have any context,
  container nor view variable in their namespace. My current and only use
  case for them right now is to provide i18n'd, markup-based resources.
  You may add one using::

  <browser:resource name="foobar.html" template="foobar.pt" />

b) DirectoryResource

  This is a browser resource that represents a file system directory. It
  uses a simple mapping based on file extensions to delegate to either
  FileResourceFactory, ImageResourceFactory or PageTemplateResourceFactory.
  You may add one using::

  <browser:resourceDirectory name="myresdir" directory="myresdir" />


=== Added File Zope3/src/zope/app/publisher/browser/tests/test_directoryresource.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_directoryresource.py,v 1.1 2003/08/11 14:58:13 philikon Exp $
"""

import os
from unittest import TestCase, main, makeSuite

from zope.proxy import isProxy, removeAllProxies
from zope.security.checker import NamesChecker
from zope.exceptions import NotFoundError
from zope.publisher.browser import TestRequest

from zope.app.tests.placelesssetup import PlacelessSetup
from zope.app.publisher.browser.directoryresource import \
     DirectoryResourceFactory
from zope.app.publisher.browser.fileresource import FileResource
from zope.app.publisher.browser.pagetemplateresource import \
     PageTemplateResource
import zope.app.publisher.browser.tests as p

test_directory = os.path.split(p.__file__)[0]

checker = NamesChecker(
    ('get', '__getitem__', 'request', 'publishTraverse')
    )

class Test(PlacelessSetup, TestCase):

    def setUp(self):
        PlacelessSetup.setUp(self)

    def testNotFound(self):
        path = os.path.join(test_directory, 'testfiles')
        request = TestRequest()
        resource = DirectoryResourceFactory(path, checker)(request)
        self.assertRaises(NotFoundError, resource.publishTraverse,
                          resource.request, 'doesnotexist')
        self.assertRaises(NotFoundError, resource.get, 'doesnotexist')

    def testGetitem(self):
        path = os.path.join(test_directory, 'testfiles')
        request = TestRequest()
        resource = DirectoryResourceFactory(path, checker)(request)
        self.assertRaises(KeyError, resource.__getitem__, 'doesnotexist')
        file = resource['test.txt']

    def testProxy(self):
        path = os.path.join(test_directory, 'testfiles')
        request = TestRequest()
        resource = DirectoryResourceFactory(path, checker)(request)
        file = resource['test.txt']
        self.assert_(isProxy(file))

    def testCorrectFactories(self):
        path = os.path.join(test_directory, 'testfiles')
        request = TestRequest()
        resource = DirectoryResourceFactory(path, checker)(request)

        image = resource['test.gif']
        self.assert_(isinstance(removeAllProxies(image), FileResource))
        template = resource['test.pt']
        self.assert_(isinstance(removeAllProxies(template), PageTemplateResource))
        file = resource['test.txt']
        self.assert_(isinstance(removeAllProxies(file), FileResource))

def test_suite():
    return makeSuite(Test)

if __name__ == '__main__':
    main(defaultTest='test_suite')


=== Added File Zope3/src/zope/app/publisher/browser/tests/test_pagetemplateresource.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_pagetemplateresource.py,v 1.1 2003/08/11 14:58:13 philikon Exp $
"""

import os
from unittest import TestCase, main, makeSuite

from zope.exceptions import NotFoundError
from zope.component.adapter import provideAdapter
from zope.security.checker import NamesChecker
from zope.publisher.browser import TestRequest

from zope.app.tests.placelesssetup import PlacelessSetup
from zope.app.publisher.browser.pagetemplateresource import \
     PageTemplateResourceFactory
from zope.app.interfaces.traversing import ITraversable
from zope.app.traversing.adapters import DefaultTraversable
import zope.app.publisher.browser.tests as p

test_directory = os.path.split(p.__file__)[0]

checker = NamesChecker(
    ('__call__', 'request', 'publishTraverse')
    )

class Test(PlacelessSetup, TestCase):

    def setUp(self):
        PlacelessSetup.setUp(self)
        provideAdapter(None, ITraversable, DefaultTraversable)

    def testNoTraversal(self):
        path = os.path.join(test_directory, 'testfiles', 'test.pt')
        request = TestRequest()
        resource = PageTemplateResourceFactory(path, checker)(request)
        self.assertRaises(NotFoundError, resource.publishTraverse,
                          resource.request, ())

    def testCall(self):
        path = os.path.join(test_directory, 'testfiles', 'testresource.pt')
        test_data = "Foobar"
        request = TestRequest(test_data=test_data)
        resource = PageTemplateResourceFactory(path, checker)(request)
        self.assert_(resource(), test_data)        

def test_suite():
    return makeSuite(Test)

if __name__=='__main__':
    main(defaultTest='test_suite')


=== Zope3/src/zope/app/publisher/browser/tests/test_directives.py 1.21 => 1.22 ===
--- Zope3/src/zope/app/publisher/browser/tests/test_directives.py:1.21	Sun Aug  3 13:50:24 2003
+++ Zope3/src/zope/app/publisher/browser/tests/test_directives.py	Mon Aug 11 10:58:13 2003
@@ -126,7 +126,7 @@
     def testPageWithClassWithMenu(self):
         self.assertEqual(queryView(ob, 'test', request),
                          None)
-        testusage = os.path.join(tests_path, 'testusage.pt')
+        testusage = os.path.join(tests_path, 'testfiles', 'testusage.pt')
                          
 
         xmlconfig(StringIO(template % (
@@ -152,7 +152,7 @@
     def testPageWithClassWithUsage(self):
         self.assertEqual(queryView(ob, 'test', request),
                          None)
-        testusage = os.path.join(tests_path, 'testusage.pt')
+        testusage = os.path.join(tests_path, 'testfiles', 'testusage.pt')
                          
 
         xmlconfig(StringIO(template % (
@@ -173,7 +173,7 @@
     def testPageWithClassWithMenuAndUsage(self):
         self.assertEqual(queryView(ob, 'test', request),
                          None)
-        testusage = os.path.join(tests_path, 'testusage.pt')
+        testusage = os.path.join(tests_path, 'testfiles', 'testusage.pt')
                          
 
         xmlconfig(StringIO(template % (
@@ -200,7 +200,7 @@
     def testPageWithTemplateWithMenu(self):
         self.assertEqual(queryView(ob, 'test', request),
                          None)
-        testusage = os.path.join(tests_path, 'testusage.pt')
+        testusage = os.path.join(tests_path, 'testfiles', 'testusage.pt')
                          
 
         xmlconfig(StringIO(template % (
@@ -225,7 +225,7 @@
     def testPageWithTemplateWithUsage(self):
         self.assertEqual(queryView(ob, 'test', request),
                          None)
-        testusage = os.path.join(tests_path, 'testusage.pt')
+        testusage = os.path.join(tests_path, 'testfiles', 'testusage.pt')
                          
 
         xmlconfig(StringIO(template % (
@@ -245,7 +245,7 @@
     def testPageWithTemplateWithMenuAndUsage(self):
         self.assertEqual(queryView(ob, 'test', request),
                          None)
-        testusage = os.path.join(tests_path, 'testusage.pt')
+        testusage = os.path.join(tests_path, 'testfiles', 'testusage.pt')
                          
 
         xmlconfig(StringIO(template % (
@@ -271,7 +271,7 @@
     def testPageInPagesWithTemplateWithMenu(self):
         self.assertEqual(queryView(ob, 'test', request),
                          None)
-        testusage = os.path.join(tests_path, 'testusage.pt')
+        testusage = os.path.join(tests_path, 'testfiles', 'testusage.pt')
                          
 
         xmlconfig(StringIO(template % (
@@ -297,7 +297,7 @@
     def testPageInPagesWithClassWithMenu(self):
         self.assertEqual(queryView(ob, 'test', request),
                          None)
-        testusage = os.path.join(tests_path, 'testusage.pt')
+        testusage = os.path.join(tests_path, 'testfiles', 'testusage.pt')
                          
 
         xmlconfig(StringIO(template % (
@@ -369,8 +369,8 @@
                                        None),
                          None)
 
-        path1 = os.path.join(tests_path, 'test.pt')
-        path2 = os.path.join(tests_path, 'test2.pt')
+        path1 = os.path.join(tests_path, 'testfiles', 'test.pt')
+        path2 = os.path.join(tests_path, 'testfiles', 'test2.pt')
 
         xmlconfig(StringIO(template % (
             """
@@ -518,7 +518,7 @@
 
     def testPageViews(self):
         self.assertEqual(queryView(ob, 'test', request), None)
-        test3 = os.path.join(tests_path, 'test3.pt')
+        test3 = os.path.join(tests_path, 'testfiles', 'test3.pt')
 
         xmlconfig(StringIO(template %
             """
@@ -611,7 +611,7 @@
 
     def testNamedViewPageViewsNoDefault(self):
         self.assertEqual(queryView(ob, 'test', request), None)
-        test3 = os.path.join(tests_path, 'test3.pt')
+        test3 = os.path.join(tests_path, 'testfiles', 'test3.pt')
 
         xmlconfig(StringIO(template %
             """
@@ -646,7 +646,7 @@
 
     def testNamedViewPageViewsWithDefault(self):
         self.assertEqual(queryView(ob, 'test', request), None)
-        test3 = os.path.join(tests_path, 'test3.pt')
+        test3 = os.path.join(tests_path, 'testfiles', 'test3.pt')
 
         xmlconfig(StringIO(template %
             """
@@ -792,7 +792,7 @@
         self.assertEqual(v(), 'done')
 
     def testFile(self):
-        path = os.path.join(tests_path, 'test.pt')
+        path = os.path.join(tests_path, 'testfiles', 'test.pt')
 
         self.assertEqual(queryResource(ob, 'test', request),
                          None)
@@ -823,7 +823,7 @@
             queryResource(ob, 'test', request, None),
             None)
 
-        path = os.path.join(tests_path, 'test.pt')
+        path = os.path.join(tests_path, 'testfiles', 'test.pt')
 
         xmlconfig(StringIO(template % (
             """
@@ -840,7 +840,7 @@
         self.assertEqual(r._testData(), open(path, 'rb').read())
 
     def test_template_page(self):
-        path = os.path.join(tests_path, 'test.pt')
+        path = os.path.join(tests_path, 'testfiles', 'test.pt')
 
         self.assertEqual(queryView(ob, 'index.html', request),
                          None)
@@ -859,7 +859,7 @@
         self.assertEqual(v().strip(), '<html><body><p>test</p></body></html>')
 
     def testtemplateWClass(self):
-        path = os.path.join(tests_path, 'test2.pt')
+        path = os.path.join(tests_path, 'testfiles', 'test2.pt')
 
         self.assertEqual(queryView(ob, 'index.html', request),
                          None)
@@ -883,7 +883,7 @@
         serviceManager.defineService(Permissions, IPermissionService)
         serviceManager.provideService(Permissions, permissionRegistry)
         
-        path = os.path.join(tests_path, 'test.pt')
+        path = os.path.join(tests_path, 'testfiles', 'test.pt')
 
         self.assertEqual(queryView(ob, 'test', request),
                          None)
@@ -932,7 +932,7 @@
 
 
     def testtemplateNoName(self):
-        path = os.path.join(tests_path, 'test.pt')
+        path = os.path.join(tests_path, 'testfiles', 'test.pt')
         self.assertRaises(
             ConfigurationError,
             xmlconfig,
@@ -946,7 +946,7 @@
             ))
 
     def testtemplateAndPage(self):
-        path = os.path.join(tests_path, 'test.pt')
+        path = os.path.join(tests_path, 'testfiles', 'test.pt')
         self.assertRaises(
             ConfigurationError,
             xmlconfig,


=== Zope3/src/zope/app/publisher/browser/tests/test_fileresource.py 1.6 => 1.7 ===
--- Zope3/src/zope/app/publisher/browser/tests/test_fileresource.py:1.6	Wed May 28 11:46:10 2003
+++ Zope3/src/zope/app/publisher/browser/tests/test_fileresource.py	Mon Aug 11 10:58:13 2003
@@ -53,7 +53,7 @@
 
     def testNoTraversal(self):
 
-        path = os.path.join(test_directory, 'test.txt')
+        path = os.path.join(test_directory, 'testfiles', 'test.txt')
         resource = FileResourceFactory(path, checker)(TestRequest())
         self.assertRaises(NotFoundError,
                           resource.publishTraverse,
@@ -62,7 +62,7 @@
 
     def testFileGET(self):
 
-        path = os.path.join(test_directory, 'test.txt')
+        path = os.path.join(test_directory, 'testfiles', 'test.txt')
 
         resource = FileResourceFactory(path, checker)(TestRequest())
         self.assertEqual(resource.GET(), open(path, 'rb').read())
@@ -72,7 +72,7 @@
 
     def testFileHEAD(self):
 
-        path = os.path.join(test_directory, 'test.txt')
+        path = os.path.join(test_directory, 'testfiles', 'test.txt')
         resource = FileResourceFactory(path, checker)(TestRequest())
 
         self.assertEqual(resource.HEAD(), '')
@@ -82,7 +82,7 @@
 
     def testImageGET(self):
 
-        path = os.path.join(test_directory, 'test.gif')
+        path = os.path.join(test_directory, 'testfiles', 'test.gif')
 
         resource = ImageResourceFactory(path, checker)(TestRequest())
 
@@ -93,7 +93,7 @@
 
     def testImageHEAD(self):
 
-        path = os.path.join(test_directory, 'test.gif')
+        path = os.path.join(test_directory, 'testfiles', 'test.gif')
         resource = ImageResourceFactory(path, checker)(TestRequest())
 
         self.assertEqual(resource.HEAD(), '')


=== Zope3/src/zope/app/publisher/browser/tests/test_icondirective.py 1.8 => 1.9 ===
--- Zope3/src/zope/app/publisher/browser/tests/test_icondirective.py:1.8	Sun Aug  3 13:50:24 2003
+++ Zope3/src/zope/app/publisher/browser/tests/test_icondirective.py	Mon Aug 11 10:58:13 2003
@@ -69,7 +69,7 @@
 
         import zope.app.publisher.browser.tests as p
         path = os.path.split(p.__file__)[0]
-        path = os.path.join(path, 'test.gif')
+        path = os.path.join(path, 'testfiles', 'test.gif')
 
         xmlconfig(StringIO(template % (
             """
@@ -100,7 +100,7 @@
 
         import zope.app.publisher.browser.tests as p
         path = os.path.split(p.__file__)[0]
-        path = os.path.join(path, 'test.gif')
+        path = os.path.join(path, 'testfiles', 'test.gif')
 
         xmlconfig(StringIO(template % (
             """
@@ -133,7 +133,7 @@
 
         import zope.app.publisher.browser.tests as p
         path = os.path.split(p.__file__)[0]
-        path = os.path.join(path, 'test.gif')
+        path = os.path.join(path, 'testfiles', 'test.gif')
 
         config = StringIO(template % (
             """


=== Zope3/src/zope/app/publisher/browser/tests/testi18nfileresource.py 1.4 => 1.5 ===
--- Zope3/src/zope/app/publisher/browser/tests/testi18nfileresource.py:1.4	Thu May  1 15:35:28 2003
+++ Zope3/src/zope/app/publisher/browser/tests/testi18nfileresource.py	Mon Aug 11 10:58:13 2003
@@ -68,8 +68,8 @@
 
 
     def _createDict(self, filename1='test.pt', filename2='test2.pt'):
-        path1 = os.path.join(test_directory, filename1)
-        path2 = os.path.join(test_directory, filename2)
+        path1 = os.path.join(test_directory, 'testfiles', filename1)
+        path2 = os.path.join(test_directory, 'testfiles', filename2)
         return { 'en': File(path1),
                  'fr': File(path2) }
 
@@ -87,7 +87,7 @@
     def testFileGET(self):
 
         # case 1: no language preference, should get en
-        path = os.path.join(test_directory, 'test.txt')
+        path = os.path.join(test_directory, 'testfiles', 'test.txt')
 
         resource = I18nFileResourceFactory(self._createDict('test.txt'), 'en')\
                                           (TestRequest())
@@ -109,7 +109,7 @@
         self.assertEqual(response.getHeader('Content-Type'), 'text/plain')
 
         # case 3: prefer fr, have it, should get fr
-        path = os.path.join(test_directory, 'test2.pt')
+        path = os.path.join(test_directory, 'testfiles', 'test2.pt')
         resource = I18nFileResourceFactory(
                         self._createDict('test.pt', 'test2.pt'), 'en')\
                         (TestRequest(HTTP_ACCEPT_LANGUAGE='fr'))

=== Removed File Zope3/src/zope/app/publisher/browser/tests/test.gif ===

=== Removed File Zope3/src/zope/app/publisher/browser/tests/test.pt ===

=== Removed File Zope3/src/zope/app/publisher/browser/tests/test.txt ===

=== Removed File Zope3/src/zope/app/publisher/browser/tests/test2.pt ===

=== Removed File Zope3/src/zope/app/publisher/browser/tests/test3.pt ===

=== Removed File Zope3/src/zope/app/publisher/browser/tests/testusage.pt ===




More information about the Zope3-Checkins mailing list