[Zope3-checkins] CVS: Zope3/src/zope/app/publisher/browser/tests - __init__.py:1.1.2.1 test.gif:1.1.2.1 test.pt:1.1.2.1 test.txt:1.1.2.1 test2.pt:1.1.2.1 test3.pt:1.1.2.1 test_directives.py:1.1.2.1 test_fileresource.py:1.1.2.1 test_globalbrowsermenuservice.py:1.1.2.1 test_globalbrowsermenuservicedirectives.py:1.1.2.1 test_icondirective.py:1.1.2.1 test_resources.py:1.1.2.1 testi18nfileresource.py:1.1.2.1

Jim Fulton jim@zope.com
Mon, 23 Dec 2002 14:32:07 -0500


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

Added Files:
      Tag: NameGeddon-branch
	__init__.py test.gif test.pt test.txt test2.pt test3.pt 
	test_directives.py test_fileresource.py 
	test_globalbrowsermenuservice.py 
	test_globalbrowsermenuservicedirectives.py 
	test_icondirective.py test_resources.py 
	testi18nfileresource.py 
Log Message:
Initial renaming before debugging

=== Added File Zope3/src/zope/app/publisher/browser/tests/__init__.py ===
#
# This file is necessary to make this directory a package.


=== Added File Zope3/src/zope/app/publisher/browser/tests/test.gif ===
  <Binary-ish file>

=== Added File Zope3/src/zope/app/publisher/browser/tests/test.pt ===
<html><body><p>test</p></body></html>


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


=== Added File Zope3/src/zope/app/publisher/browser/tests/test2.pt ===
<html><body><p tal:content="view/data">test</p></body></html>


=== Added File Zope3/src/zope/app/publisher/browser/tests/test3.pt ===
<html><body><p tal:content="view/action">test</p></body></html>


=== Added File Zope3/src/zope/app/publisher/browser/tests/test_directives.py === (592/692 lines abridged)
##############################################################################
#
# 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.
# 
##############################################################################

import os
import unittest
from cStringIO import StringIO

from zope.configuration.xmlconfig import xmlconfig, XMLConfig
from zope.configuration.exceptions import ConfigurationError
from zope.component.tests.test_views import IC, V1, VZMI, R1, RZMI
from zope.component import getView, queryView, queryResource
from zope.component import getDefaultViewName, getResource
from zope.app.tests.placelesssetup import PlacelessSetup
from zope.security.proxy import ProxyFactory
from zope.proxy.introspection import removeAllProxies
import zope.configuration

from zope.component.tests.request import Request

from zope.publisher.interfaces.browser import IBrowserPresentation

from zope.app.publisher.browser.i18nfileresource import I18nFileResource

import Zope.App.Publisher.Browser

tests_path = os.path.join(
    os.path.split(Zope.App.Publisher.Browser.__file__)[0],
    'tests')

template = """<zopeConfigure
   xmlns='http://namespaces.zope.org/zope'
   xmlns:browser='http://namespaces.zope.org/browser'>
   %s
   </zopeConfigure>"""

request = Request(IBrowserPresentation)

class VT(V1, object):
    def publishTraverse(self, request, name):

[-=- -=- -=- 592 lines omitted -=- -=- -=-]

        #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>')
        

    def testtemplateNoName(self):
        path = os.path.join(tests_path, 'test.pt')
        self.assertRaises(
            ConfigurationError,
            xmlconfig,
            StringIO(template %
            """
            <browser:view
                  template="%s"
                  for="Zope.ComponentArchitecture.tests.TestViews.IC" 
                  /> 
            """ % path
            ))

    def testtemplateAndPage(self):
        path = os.path.join(tests_path, 'test.pt')
        self.assertRaises(
            ConfigurationError,
            xmlconfig,
            StringIO(template %
            """
            <browser:view
                  name="index.html"
                  template="%s"
                  for="Zope.ComponentArchitecture.tests.TestViews.IC" 
                  >
               <browser:page name="foo.html" attribute="index" />
            </browser:view>
            """ % path
            ))


    
def test_suite():
    loader=unittest.TestLoader()
    return loader.loadTestsFromTestCase(Test)

if __name__=='__main__':
    unittest.TextTestRunner().run(test_suite())


=== Added File Zope3/src/zope/app/publisher/browser/tests/test_fileresource.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: test_fileresource.py,v 1.1.2.1 2002/12/23 19:32:04 jim Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite

import os

from zope.exceptions import NotFoundError

from zope.app.tests.placelesssetup import PlacelessSetup
from zope.component.resource import provideResource
from zope.component.adapter import provideAdapter
from zope.proxy.introspection import removeAllProxies

from zope.interfaces.i18n import IUserPreferredCharsets

from zope.publisher.http import IHTTPRequest
from zope.publisher.http import HTTPCharsets
from zope.publisher.browser import TestRequest

from zope.app.publisher.browser.fileresource import FileResourceFactory
from zope.app.publisher.browser.fileresource import ImageResourceFactory
import Zope.App.Publisher.Browser.tests as p        

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

class Test(PlacelessSetup, TestCase):

    def setUp(self):
        PlacelessSetup.setUp(self)
        provideAdapter(IHTTPRequest, IUserPreferredCharsets, HTTPCharsets)    

    def testNoTraversal(self):

        path = os.path.join(test_directory, 'test.txt')
        resource = FileResourceFactory(path)(TestRequest())
        resource = removeAllProxies(resource)
        self.assertRaises(NotFoundError,
                          resource.publishTraverse,
                          resource.request,
                          '_testData')

    def testFileGET(self):

        path = os.path.join(test_directory, 'test.txt')

        resource = FileResourceFactory(path)(TestRequest())
        resource = removeAllProxies(resource)
        self.assertEqual(resource.GET(), open(path, 'rb').read())

        response = resource.request.response
        self.assertEqual(response.getHeader('Content-Type'), 'text/plain')

    def testFileHEAD(self):

        path = os.path.join(test_directory, 'test.txt')
        resource = FileResourceFactory(path)(TestRequest())
        resource = removeAllProxies(resource)

        self.assertEqual(resource.HEAD(), '')

        response = resource.request.response
        self.assertEqual(response.getHeader('Content-Type'), 'text/plain')

    def testImageGET(self):

        path = os.path.join(test_directory, 'test.gif')

        resource = ImageResourceFactory(path)(TestRequest())
        resource = removeAllProxies(resource)

        self.assertEqual(resource.GET(), open(path, 'rb').read())

        response = resource.request.response
        self.assertEqual(response.getHeader('Content-Type'), 'image/gif')

    def testImageHEAD(self):

        path = os.path.join(test_directory, 'test.gif')
        resource = ImageResourceFactory(path)(TestRequest())
        resource = removeAllProxies(resource)

        self.assertEqual(resource.HEAD(), '')

        response = resource.request.response
        self.assertEqual(response.getHeader('Content-Type'), 'image/gif')
                         
        

def test_suite():
    return makeSuite(Test)

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


=== Added File Zope3/src/zope/app/publisher/browser/tests/test_globalbrowsermenuservice.py ===
##############################################################################
#
# Copyright (c) 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.
#
##############################################################################
"""XXX short summary goes here.

XXX longer description goes here.

$Id: test_globalbrowsermenuservice.py,v 1.1.2.1 2002/12/23 19:32:04 jim Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from zope.publisher.interfaces.browser import IBrowserPublisher
from zope.exceptions import Forbidden, Unauthorized, DuplicationError
from zope.interface import Interface
from zope.publisher.browser import TestRequest
from zope.app.tests.placelesssetup import PlacelessSetup

class I1(Interface): pass
class I11(I1): pass
class I12(I1): pass
class I111(I11): pass

class X:
    __implements__ = IBrowserPublisher, I111

    def f(self): pass

    def browserDefault(self, r): return self, ()
    def publishTraverse(self, request, name):
        if name[:1] == 'f':
            raise Forbidden, name
        if name[:1] == 'u':
            raise Unauthorized, name
        return self.f


class Test(PlacelessSetup, TestCase):

    def __reg(self):
        from zope.app.publisher.browser.globalbrowsermenuservice \
             import GlobalBrowserMenuService
        
        r = GlobalBrowserMenuService()
        return r
    
    def testDup(self):
        r = self.__reg()
        r.menu('test_id', 'test menu')
        self.assertRaises(DuplicationError, r.menu, 'test_id', 'test menu')
        
    def test(self):
        r = self.__reg()
        r.menu('test_id', 'test menu')
        r.menuItem('test_id', Interface, 'a1', 't1', 'd1')
        r.menuItem('test_id', I1, 'a2', 't2', 'd2')
        r.menuItem('test_id', I11, 'a3', 't3', 'd3', 'context')
        r.menuItem('test_id', I11, 'a4', 't4', 'd4', 'not:context')
        r.menuItem('test_id', I111, 'a5', 't5', 'd5')
        r.menuItem('test_id', I111, 'a6', 't6', 'd6')
        r.menuItem('test_id', I111, 'f7', 't7', 'd7')
        r.menuItem('test_id', I111, 'u8', 't8', 'd8')
        r.menuItem('test_id', I12, 'a9', 't9', 'd9')

        menu = r.getMenu('test_id', X(), TestRequest())

        def d(n):
            return {'action': "a%s" % n,
                    'title':  "t%s" % n,
                    'description':  "d%s" % n,
                    'selected': ''
                    }

        self.assertEqual(list(menu), [d(5), d(6), d(3), d(2), d(1)])
        
    def test_no_dups(self):
        r = self.__reg()
        r.menu('test_id', 'test menu')
        r.menuItem('test_id', Interface, 'a1', 't1', 'd1')
        r.menuItem('test_id', Interface, 'a12', 't2', 'd12')
        r.menuItem('test_id', I1, 'a2', 't2', 'd2')
        r.menuItem('test_id', I1, 'a23', 't3', 'd23')
        r.menuItem('test_id', I1, 'a24', 't4', 'd24')
        r.menuItem('test_id', I11, 'a3', 't3', 'd3', 'context')
        r.menuItem('test_id', I11, 'a4', 't4', 'd4', 'not:context')
        r.menuItem('test_id', I111, 'a5', 't5', 'd5')
        r.menuItem('test_id', I111, 'a6', 't6', 'd6')
        r.menuItem('test_id', I111, 'f7', 't7', 'd7')
        r.menuItem('test_id', I111, 'u8', 't8', 'd8')
        r.menuItem('test_id', I12, 'a9', 't9', 'd9')

        menu = r.getMenu('test_id', X(), TestRequest())

        def d(n):
            return {'action': "a%s" % n,
                    'title':  "t%s" % n,
                    'description':  "d%s" % n,
                    'selected': ''}
        
        self.assertEqual(list(menu), [d(5), d(6), d(3), d(2), d(1)])
        
    def testEmpty(self):
        r = self.__reg()
        r.menu('test_id', 'test menu')
        menu = r.getMenu('test_id', X(), TestRequest())        
        self.assertEqual(list(menu), [])


def test_suite():
    return makeSuite(Test)

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


=== Added File Zope3/src/zope/app/publisher/browser/tests/test_globalbrowsermenuservicedirectives.py ===
##############################################################################
#
# Copyright (c) 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.
#
##############################################################################
"""XXX short summary goes here.

XXX longer description goes here.

$Id: test_globalbrowsermenuservicedirectives.py,v 1.1.2.1 2002/12/23 19:32:04 jim Exp $
"""

from StringIO import StringIO
from unittest import TestCase, TestSuite, main, makeSuite

from zope.configuration.xmlconfig import xmlconfig, XMLConfig
from zope.publisher.interfaces.browser import IBrowserPublisher
from zope.publisher.browser import TestRequest
from zope.app.tests.placelesssetup import PlacelessSetup
import zope.configuration

import Zope.App.Publisher.Browser

template = """<zopeConfigure
   xmlns='http://namespaces.zope.org/zope'
   xmlns:browser='http://namespaces.zope.org/browser'>
   %s
   </zopeConfigure>"""

class Test(PlacelessSetup, TestCase):

    def setUp(self):
        PlacelessSetup.setUp(self)
        XMLConfig('metameta.zcml', Zope.Configuration)()
        XMLConfig('meta.zcml', Zope.App.Publisher.Browser)()
        
    def test(self):
        from zope.app.publisher.browser.globalbrowsermenuservice \
             import globalBrowserMenuService
        
        xmlconfig(StringIO(template % (
            """
            <browser:menu id="test_id" title="test menu" />

            <browser:menuItems menu="test_id" for="Interface.Interface">
              <browser:menuItem action="a1" title="t1" />
            </browser:menuItems>

            <browser:menuItems menu="test_id"
              for="
           Zope.App.Publisher.Browser.tests.testGlobalBrowserMenuService.I1
              ">
              <browser:menuItem action="a2" title="t2" />
            </browser:menuItems>

            <browser:menuItems menu="test_id"
              for="
           Zope.App.Publisher.Browser.tests.testGlobalBrowserMenuService.I11
              ">
              <browser:menuItem action="a3" title="t3" filter="context" />
              <browser:menuItem action="a4" title="t4" filter="not:context" />
            </browser:menuItems>

            <browser:menuItems menu="test_id"
              for="
           Zope.App.Publisher.Browser.tests.testGlobalBrowserMenuService.I111
              ">
              <browser:menuItem action="a5" title="t5" />
              <browser:menuItem action="a6" title="t6" />
              <browser:menuItem action="f7" title="t7" />
              <browser:menuItem action="u8" title="t8" />
            </browser:menuItems>

            <browser:menuItems menu="test_id"
              for="
           Zope.App.Publisher.Browser.tests.testGlobalBrowserMenuService.I12
              ">
              <browser:menuItem action="a9" title="t9" />
            </browser:menuItems>
            """)))


        from zope.app.publisher.browser.tests.test_globalbrowsermenuservice \
             import X

        menu = globalBrowserMenuService.getMenu('test_id', X(), TestRequest())

        def d(n):
            return {'action': "a%s" % n,
                    'title':  "t%s" % n,
                    'description':  "",
                    'selected': ''
                    }
        
        self.assertEqual(list(menu), [d(5), d(6), d(3), d(2), d(1)])

        first = globalBrowserMenuService.getFirstMenuItem(
            'test_id', X(), TestRequest())

        self.assertEqual(first, d(5))

def test_suite():
    return makeSuite(Test)

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


=== Added File Zope3/src/zope/app/publisher/browser/tests/test_icondirective.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: test_icondirective.py,v 1.1.2.1 2002/12/23 19:32:04 jim Exp $
"""
import os
from StringIO import StringIO
from unittest import TestCase, main, makeSuite

from zope.exceptions import Forbidden
from zope.proxy.introspection import removeAllProxies
from zope.app.tests.placelesssetup import PlacelessSetup
from zope.configuration.xmlconfig import xmlconfig, XMLConfig
from zope.component.tests.request import Request
from zope.component.tests.test_views import IC
from zope.publisher.interfaces.browser import IBrowserPresentation
from zope.component import queryView, getView, getResource
from zope.security.proxy import ProxyFactory
from zope.configuration.exceptions import ConfigurationError
import zope.configuration

import Zope.App.Publisher.Browser

template = """<zopeConfigure
   xmlns='http://namespaces.zope.org/zope'
   xmlns:browser='http://namespaces.zope.org/browser'
   >
   %s
   </zopeConfigure>"""


request = Request(IBrowserPresentation)

class Ob:
    __implements__ = IC

ob = Ob()

def defineCheckers():
    # define the appropriate checker for a FileResource for these tests
    from zope.app.security.protectclass import protectName
    from zope.app.publisher.browser.fileresource import FileResource
    protectName(FileResource, '__call__', 'Zope.Public')


class Test(PlacelessSetup, TestCase):

    def setUp(self):
        PlacelessSetup.setUp(self)
        XMLConfig('metameta.zcml', Zope.Configuration)()
        XMLConfig('meta.zcml', Zope.App.Publisher.Browser)()
        defineCheckers()

    def test(self):
        self.assertEqual(queryView(ob, 'zmi_icon', request), None)

        import Zope.App.Publisher.Browser.tests as p
        path = os.path.split(p.__file__)[0]
        path = os.path.join(path, 'test.gif')
        
        xmlconfig(StringIO(template % (
            """
            <browser:icon name="zmi_icon"
                      for="Zope.ComponentArchitecture.tests.TestViews.IC"
                      file="%s" /> 
            """ % path
            )))

        view = getView(ob, 'zmi_icon', request)
        rname = 'Zope-ComponentArchitecture-tests-TestViews-IC-zmi_icon.gif'
        self.assertEqual(
            view(),
            '<img src="/@@/%s" alt="IC" width="16" height="16" border="0" />'
            % rname)

        resource = getResource(ob, rname, request)
        
        # Resources come ready-wrapped from the factory
        #resource = ProxyFactory(resource)

        self.assertRaises(Forbidden, getattr, resource, '_testData')
        resource = removeAllProxies(resource)
        self.assertEqual(resource._testData(), open(path, 'rb').read())

    def testResource(self):
        self.assertEqual(queryView(ob, 'zmi_icon', request), None)

        import Zope.App.Publisher.Browser.tests as p
        path = os.path.split(p.__file__)[0]
        path = os.path.join(path, 'test.gif')
        
        xmlconfig(StringIO(template % (
            """
            <browser:resource name="zmi_icon_res"
                      image="%s" /> 
            <browser:icon name="zmi_icon"
                      for="Zope.ComponentArchitecture.tests.TestViews.IC"
                      resource="zmi_icon_res" /> 
            """ % path
            )))
 
        view = getView(ob, 'zmi_icon', request)
        rname = "zmi_icon_res"
        self.assertEqual(
            view(),
            '<img src="/@@/%s" alt="IC" width="16" height="16" border="0" />'
            % rname)

        resource = getResource(ob, rname, request)

        # Resources come ready-wrapped from the factory
        #resource = ProxyFactory(resource)

        self.assertRaises(Forbidden, getattr, resource, '_testData')
        resource = removeAllProxies(resource)
        self.assertEqual(resource._testData(), open(path, 'rb').read())

    def testResourceErrors(self):
        self.assertEqual(queryView(ob, 'zmi_icon', request), None)

        import Zope.App.Publisher.Browser.tests as p
        path = os.path.split(p.__file__)[0]
        path = os.path.join(path, 'test.gif')

        config = StringIO(template % (
            """
            <browser:resource name="zmi_icon_res"
                      image="%s" /> 
            <browser:icon name="zmi_icon"
                      for="Zope.ComponentArchitecture.tests.TestViews.IC"
                      file="%s"
                      resource="zmi_icon_res" /> 
            """ % (path, path)
            ))
        self.assertRaises(ConfigurationError, xmlconfig, config)

        config = StringIO(template % (
            """
            <browser:icon name="zmi_icon"
                      for="Zope.ComponentArchitecture.tests.TestViews.IC"
                      /> 
            """
            ))
        self.assertRaises(ConfigurationError, xmlconfig, config)


def test_suite():
    return makeSuite(Test)

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


=== Added File Zope3/src/zope/app/publisher/browser/tests/test_resources.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: test_resources.py,v 1.1.2.1 2002/12/23 19:32:04 jim Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite

from zope.app.tests.placelesssetup import PlacelessSetup
from zope.component.resource import provideResource
from zope.component.adapter import provideAdapter

from zope.interfaces.i18n import IUserPreferredCharsets

from zope.publisher.http import IHTTPRequest
from zope.publisher.http import HTTPCharsets
from zope.publisher.browser import TestRequest
from zope.publisher.interfaces.browser import IBrowserView

class Test(PlacelessSetup, TestCase):

    def setUp(self):
        PlacelessSetup.setUp(self)
        provideAdapter(IHTTPRequest, IUserPreferredCharsets, HTTPCharsets)    


    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 testNotFound(self):
        from zope.app.publisher.browser.resources import Resources
        from zope.exceptions import NotFoundError
        request = TestRequest()
        view = Resources(None, request)
        self.assertRaises(NotFoundError, 
                          view.publishTraverse, 
                          request, 'test'
                          )
    
        

def test_suite():
    return makeSuite(Test)

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


=== Added File Zope3/src/zope/app/publisher/browser/tests/testi18nfileresource.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: testi18nfileresource.py,v 1.1.2.1 2002/12/23 19:32:04 jim Exp $
"""

from unittest import TestSuite, main, makeSuite

import os

from zope.exceptions import NotFoundError

from zope.app.tests.placelesssetup import PlacelessSetup
from zope.component.resource import provideResource
from zope.component.adapter import provideAdapter

from zope.interfaces.i18n import IUserPreferredCharsets
from zope.interfaces.i18n import IUserPreferredLanguages

from zope.publisher.http import IHTTPRequest
from zope.publisher.http import HTTPCharsets
from zope.publisher.browser import BrowserLanguages
from zope.publisher.browser import TestRequest

from zope.app.publisher.browser.i18nfileresource import I18nFileResource, \
     I18nFileResourceFactory
from zope.app.publisher.fileresource import File, Image
import Zope.App.Publisher.Browser.tests as p

from zope.app.component.metaconfigure import \
     provideService, managerHandler
from zope.interfaces.i18n import INegotiator
from zope.i18n.negotiator import negotiator

from zope.i18n.tests.testii18naware import TestII18nAware

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


class Test(PlacelessSetup, TestII18nAware):

    def setUp(self):
        PlacelessSetup.setUp(self)
        TestII18nAware.setUp(self)
        provideAdapter(IHTTPRequest, IUserPreferredCharsets, HTTPCharsets)
        provideAdapter(IHTTPRequest, IUserPreferredLanguages, BrowserLanguages)
        # Setup the negotiator service registry entry
        managerHandler('defineService', 'LanguageNegotiation', INegotiator)
        provideService('LanguageNegotiation', negotiator, 'Zope.Public')


    def _createObject(self):
        obj = I18nFileResource({'en':None, 'lt':None, 'fr':None},
                               TestRequest(), 'fr')
        return obj


    def _createDict(self, filename1='test.pt', filename2='test2.pt'):
        path1 = os.path.join(test_directory, filename1)
        path2 = os.path.join(test_directory, filename2)
        return { 'en': File(path1),
                 'fr': File(path2) }


    def testNoTraversal(self):

        resource = I18nFileResourceFactory(self._createDict(), 'en')\
                                          (TestRequest())

        self.assertRaises(NotFoundError,
                          resource.publishTraverse,
                          resource.request,
                          '_testData')

    def testFileGET(self):

        # case 1: no language preference, should get en
        path = os.path.join(test_directory, 'test.txt')

        resource = I18nFileResourceFactory(self._createDict('test.txt'), 'en')\
                                          (TestRequest())


        self.assertEqual(resource.GET(), open(path, 'rb').read())

        response = resource.request.response
        self.assertEqual(response.getHeader('Content-Type'), 'text/plain')

        # case 2: prefer lt, have only en and fr, should get en
        resource = I18nFileResourceFactory(
                        self._createDict('test.txt'), 'en')\
                        (TestRequest(HTTP_ACCEPT_LANGUAGE='lt'))

        self.assertEqual(resource.GET(), open(path, 'rb').read())

        response = resource.request.response
        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')
        resource = I18nFileResourceFactory(
                        self._createDict('test.pt', 'test2.pt'), 'en')\
                        (TestRequest(HTTP_ACCEPT_LANGUAGE='fr'))

        self.assertEqual(resource.GET(), open(path, 'rb').read())

        response = resource.request.response
        self.assertEqual(response.getHeader('Content-Type'), 'text/html')


    def testFileHEAD(self):

        # case 1: no language preference, should get en
        resource = I18nFileResourceFactory(self._createDict('test.txt'), 'en')\
                                          (TestRequest())

        self.assertEqual(resource.HEAD(), '')

        response = resource.request.response
        self.assertEqual(response.getHeader('Content-Type'), 'text/plain')

        # case 2: prefer lt, have only en and fr, should get en
        resource = I18nFileResourceFactory(
                        self._createDict('test.txt'), 'en')\
                        (TestRequest(HTTP_ACCEPT_LANGUAGE='lt'))

        self.assertEqual(resource.HEAD(), '')

        response = resource.request.response
        self.assertEqual(response.getHeader('Content-Type'), 'text/plain')

        # case 3: prefer fr, have it, should get fr
        resource = I18nFileResourceFactory(
                        self._createDict('test.pt', 'test2.pt'), 'en')\
                        (TestRequest(HTTP_ACCEPT_LANGUAGE='fr'))

        self.assertEqual(resource.HEAD(), '')

        response = resource.request.response
        self.assertEqual(response.getHeader('Content-Type'), 'text/html')


def test_suite():
    return makeSuite(Test)

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