[Zope-Checkins] CVS: Zope3/lib/python/Zope/ComponentArchitecture/tests - testViewDefinitions.py:1.1.2.1

Jim Fulton jim@zope.com
Sun, 24 Mar 2002 16:09:37 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/ComponentArchitecture/tests
In directory cvs.zope.org:/tmp/cvs-serv21372/tests

Added Files:
      Tag: Zope-3x-branch
	testViewDefinitions.py 
Log Message:
Added an API to viewService to query view definitions. This is useful
for browsing tools.



=== Added File Zope3/lib/python/Zope/ComponentArchitecture/tests/testViewDefinitions.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: testViewDefinitions.py,v 1.1.2.1 2002/03/24 21:09:36 jim Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
from Zope.ComponentArchitecture.tests.TestViews \
     import IC, IV, V1

class IC1(IC): "Content interface 1"
class IC2(IC): "Content interface 1"

class ViewType(IV): "Custom view type"

class BaseTestViewDefinitions:

    def setUp(self):
        viewService = self._Test__new()

        for name in ('foo', 'bar', 'baz'):
            for forinterface in IC, IC1:
                for layer in ('', 'l1'):
                    class C(V1): pass
                    C.name = name
                    C.__used_for__ = forinterface
                    C.layer = layer
                
                    viewService.provideView(forinterface, name, IV, C,
                                            layer=layer)
        
        for name in ('foo', 'bar', 'baz'):
            for layer in ('', 'l1'):
                class C(V1): pass
                C.name = name
                C.__used_for__ = IC2
                C.layer = layer
                C.__implements__ = ViewType
                viewService.provideView(IC2, name, IV, C,
                                        layer=layer)
        
        for name in ('foo', 'bar', 'baz'):
            for layer in ('l2', 'l3'):
                class C(V1): pass
                C.name = name
                C.__used_for__ = IC
                C.layer = layer
                C.__implements__ = ViewType
                viewService.provideView(IC, name, IV, C,
                                        layer=layer)

        
        
    def testAll(self):
        viewService = self._Test__new()
        defs = viewService.getViewDefinitions()
        self.assertEqual(len(defs), 24)
            

    def testForC1(self):
        viewService = self._Test__new()
        defs = viewService.getViewDefinitions(used_for=IC1)
        self.assertEqual(len(defs), 12)
        for d in defs:
            self.failUnless(IC1.extends(d['used_for'], 0), d)

    def testForC2(self):
        viewService = self._Test__new()
        defs = viewService.getViewDefinitions(used_for=IC2)
        self.assertEqual(len(defs), 12)
        for d in defs:
            self.failUnless(IC2.extends(d['used_for'], 0), d)

class Test(BaseTestViewDefinitions, CleanUp, TestCase):

    def _Test__new(self):
        from Zope.ComponentArchitecture.ViewService import viewService
        return viewService



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

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