[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Publisher/Browser/tests - testIconDirective.py:1.1

Jim Fulton jim@zope.com
Tue, 18 Jun 2002 16:33:34 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/Publisher/Browser/tests
In directory cvs.zope.org:/tmp/cvs-serv8329/lib/python/Zope/App/Publisher/Browser/tests

Added Files:
	testIconDirective.py 
Log Message:
Changed 

  <zmi:icon for=".IFoo." file="splat.gif" />

to:

  <browser:icon name="zmi_icon" for=".IFoo." file="splat.gif" />



=== Added File Zope3/lib/python/Zope/App/Publisher/Browser/tests/testIconDirective.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: testIconDirective.py,v 1.1 2002/06/18 20:33:33 jim Exp $
"""
import os
from StringIO import StringIO
from unittest import TestCase, TestSuite, main, makeSuite

from Zope.Exceptions import Forbidden
from Zope.Proxy.ProxyIntrospection import removeAllProxies
from Zope.ComponentArchitecture.tests.PlacelessSetup import PlacelessSetup
from Zope.Configuration.xmlconfig import xmlconfig
from Zope.ComponentArchitecture.tests.Request import Request
from Zope.ComponentArchitecture.tests.TestViews import IC
from Zope.Publisher.Browser.IBrowserPresentation import IBrowserPresentation
from Zope.ComponentArchitecture import queryView, getView, getResource
from Zope.Security.Proxy import ProxyFactory

import Zope.App.Publisher.Browser as p
defs_path = os.path.join(os.path.split(p.__file__)[0], 'meta.zcml')

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()

class Test(PlacelessSetup, TestCase):

    def setUp(self):
        PlacelessSetup.setUp(self)
        xmlconfig(open(defs_path))

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

        package_directory = os.path.split(defs_path)[0]
        path = os.path.join(package_directory, "tests", '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)
        resource = ProxyFactory(resource)

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

        
        
     

def test_suite():
    return TestSuite((
        makeSuite(Test),
        ))

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