[Zope-Checkins] CVS: Zope3/lib/python/Zope/Publisher/Browser/tests - TestViews.py:1.1.2.2.14.1 testAttributePublisher.py:1.1.2.12.14.1 testBrowserRequest.py:1.1.4.6.14.1 testDirectives.py:1.1.2.5.8.1
Jim Fulton
jim@zope.com
Wed, 29 May 2002 11:10:24 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/Publisher/Browser/tests
In directory cvs.zope.org:/tmp/cvs-serv12181/lib/python/Zope/Publisher/Browser/tests
Modified Files:
Tag: Zope3InWonderland-branch
TestViews.py testAttributePublisher.py testBrowserRequest.py
testDirectives.py
Log Message:
- Added permission_id attribute to adapter and utility directives.
- Got rid of old getView, getResource, and getDefaultViewName.
Renamed getRequestView to getView (and so on).
Changed view interface to use context, rather than getContext.
Introduced notion of presentation types (e.g. IBrowserPresentation,
which is cleaner than IBrowserPublisher).
- Began converting to get/queryFoo, which is much nicer.
- Many formatting fixups.
=== Zope3/lib/python/Zope/Publisher/Browser/tests/TestViews.py 1.1.2.2 => 1.1.2.2.14.1 ===
__implements__ = IBrowserPublisher
- def __init__(self,context):
+ def __init__(self, context, request):
self._context = context
class VZMI(V1):
@@ -32,10 +32,7 @@
class R1:
__implements__ = IBrowserPublisher
-
-r1 = R1()
+ def __init__(self, request): self.request = request
class RZMI(R1):
pass
-
-rZMI = RZMI()
=== Zope3/lib/python/Zope/Publisher/Browser/tests/testAttributePublisher.py 1.1.2.12 => 1.1.2.12.14.1 ===
import unittest, sys
+from Zope.Publisher.Browser.BrowserView import BrowserView
from Zope.Publisher.Browser.AttributePublisher import AttributePublisher
from Zope.Publisher.Browser.IBrowserPublisher import IBrowserPublisher
from Interface.Verify import verifyClass
from Interface.Implements import instancesOfObjectImplements
-class Presentation(AttributePublisher):
+class Presentation(BrowserView, AttributePublisher):
index = 'index'
action = 'action'
foo = 'foo'
class TestAttributePublisher(unittest.TestCase):
def setUp(self):
- self.pres = Presentation()
-
- def testImplementsIBrowserPublisher(self):
- self.failUnless(IBrowserPublisher.isImplementedBy(self.pres))
+ self.pres = Presentation(None, None)
def testInterfacesVerify(self):
for interface in instancesOfObjectImplements(Presentation):
=== Zope3/lib/python/Zope/Publisher/Browser/tests/testBrowserRequest.py 1.1.4.6 => 1.1.4.6.14.1 ===
from Zope.Publisher.DefaultPublication import DefaultPublication
from Zope.Publisher.Browser.IBrowserPublisher import IBrowserPublisher
-from Zope.Publisher.Browser.AttributePublisher import AttributePublisher
from StringIO import StringIO
@@ -107,15 +106,15 @@
"\r\n"
"'5', 6")
- def testIViewRequest(self):
+ def testIPresentationRequest(self):
''' test the IView request'''
r = self._createRequest()
- self.failUnless( r.getViewType() is IBrowserPublisher)
- self.assertEqual( r.getViewSkin(), '')
+ self.failUnless( r.getPresentationType() is IBrowserPublisher)
+ self.assertEqual( r.getPresentationSkin(), '')
r.setViewSkin( 'morefoo' )
- self.assertEqual( r.getViewSkin(), 'morefoo')
+ self.assertEqual( r.getPresentationSkin(), 'morefoo')
def testNoDefault(self):
request = self._createRequest()
=== Zope3/lib/python/Zope/Publisher/Browser/tests/testDirectives.py 1.1.2.5 => 1.1.2.5.8.1 ===
#
##############################################################################
-import unittest, sys
-from Zope.Configuration.xmlconfig import xmlconfig
-from Zope.Publisher.Browser.IBrowserPublisher import IBrowserPublisher
-from Zope.Publisher.Browser.tests.TestViews import IC, V1, VZMI, R1, RZMI
-from Zope.ComponentArchitecture import getView, getResource
-from Zope.ComponentArchitecture import getDefaultViewName
-from Zope.ComponentArchitecture.tests.PlacelessSetup import PlacelessSetup
-from cStringIO import StringIO
-
-template = """<zopeConfigure
- xmlns='http://namespaces.zope.org/zope'
- xmlns:browser='http://namespaces.zope.org/browser'>
- %s
- </zopeConfigure>"""
-
-class Ob:
- __implements__ = IC
-
-class Test(PlacelessSetup, unittest.TestCase):
-
- # XXX: tests for other directives needed
-
- def testView(self):
-
- ob = Ob()
- self.assertEqual(getView(ob, 'test', IBrowserPublisher, None), None)
-
- xmlconfig(StringIO(template % (
- """
- <directive name="view"
- attributes="component, name, for, layer"
- handler="Zope.Publisher.Browser.metaConfigure.view"
- namespace="http://namespaces.zope.org/browser" />
- <browser:view name="test"
- factory="Zope.Publisher.Browser.tests.TestViews.V1"
- for="Zope.Publisher.Browser.tests.TestViews.IC" />
- """
- )))
-
- self.assertEqual(getView(ob, 'test', IBrowserPublisher, None
- ).__class__, V1)
-
- def testDefaultView(self):
-
- ob = Ob()
- self.assertEqual(getView(ob, 'test', IBrowserPublisher, None), None)
-
- xmlconfig(StringIO(template % (
- """
- <directive name="defaultView"
- attributes="component, name, for, layer"
- handler="Zope.Publisher.Browser.metaConfigure.defaultView"
- namespace="http://namespaces.zope.org/browser" />
- <browser:defaultView name="test"
- factory="Zope.Publisher.Browser.tests.TestViews.V1"
- for="Zope.Publisher.Browser.tests.TestViews.IC" />
- """
- )))
-
- self.assertEqual(getView(ob, 'test', IBrowserPublisher, None
- ).__class__, V1)
- self.assertEqual(getDefaultViewName(ob, IBrowserPublisher
- ), 'test')
-
-
-
- def testSKinView(self):
-
- ob = Ob()
- self.assertEqual(getView(ob, 'test', IBrowserPublisher, None), None)
-
- xmlconfig(StringIO(template % (
- """
- <directive name="view"
- attributes="component, name, for, layer"
- handler="Zope.Publisher.Browser.metaConfigure.view"
- namespace="http://namespaces.zope.org/browser" />
- <directive name="skin" attributes="name, layers"
- handler="Zope.Publisher.Browser.metaConfigure.skin"
- namespace="http://namespaces.zope.org/browser" />
- <browser:skin name="zmi" layers="zmi," />
- <browser:view name="test"
- factory="Zope.Publisher.Browser.tests.TestViews.VZMI"
- layer="zmi"
- for="Zope.Publisher.Browser.tests.TestViews.IC" />
- <browser:view name="test"
- factory="Zope.Publisher.Browser.tests.TestViews.V1"
- for="Zope.Publisher.Browser.tests.TestViews.IC" />
- """
- )))
-
- self.assertEqual(getView(ob, 'test', IBrowserPublisher, None
- ).__class__, V1)
- self.assertEqual(getView(ob, 'test', IBrowserPublisher, None,
- skin='zmi').__class__,
- VZMI)
-
- def testResource(self):
-
- ob = Ob()
- self.assertEqual(getResource(ob, 'test', IBrowserPublisher, None),
- None)
-
- xmlconfig(StringIO(template % (
- """
- <directive name="resource"
- attributes="component, name, layer"
- handler="Zope.Publisher.Browser.metaConfigure.resource"
- namespace="http://namespaces.zope.org/browser" />
- <browser:resource name="test"
- component="Zope.Publisher.Browser.tests.TestViews.r1" />
- """
- )))
-
- self.assertEqual(
- getResource(ob, 'test', IBrowserPublisher, None).__class__,
- R1)
-
- def testSkinResource(self):
-
- ob = Ob()
- self.assertEqual(
- getResource(ob, 'test', IBrowserPublisher, None),
- None)
-
- xmlconfig(StringIO(template % (
- """
- <directive name="resource" attributes="component, name, layer"
- handler="Zope.Publisher.Browser.metaConfigure.resource"
- namespace="http://namespaces.zope.org/browser" />
- <directive name="skin" attributes="name, layers"
- handler="Zope.Publisher.Browser.metaConfigure.skin"
- namespace="http://namespaces.zope.org/browser" />
- <browser:skin name="zmi" layers="zmi," />
- <browser:resource name="test"
- component="Zope.Publisher.Browser.tests.TestViews.rZMI"
- layer="zmi" />
- <browser:resource name="test"
- component="Zope.Publisher.Browser.tests.TestViews.r1" />
- """
- )))
-
- self.assertEqual(
- getResource(ob, 'test', IBrowserPublisher, None).__class__,
- R1)
- self.assertEqual(
- getResource(ob, 'test', IBrowserPublisher, None,
- skin='zmi').__class__,
- RZMI)
-
-def test_suite():
- loader=unittest.TestLoader()
- return loader.loadTestsFromTestCase(Test)
-
-if __name__=='__main__':
- unittest.TextTestRunner().run(test_suite())
+import unittest, sys
+from Zope.Configuration.xmlconfig import xmlconfig
+from Zope.Publisher.Browser.IBrowserPublisher import IBrowserPublisher
+from Zope.Publisher.Browser.tests.TestViews import IC, V1, VZMI, R1, RZMI
+from Zope.ComponentArchitecture import queryView, queryResource
+from Zope.ComponentArchitecture import getDefaultViewName
+from Zope.ComponentArchitecture.tests.PlacelessSetup import PlacelessSetup
+from cStringIO import StringIO
+
+from Zope.ComponentArchitecture.tests.Request import Request
+
+template = """<zopeConfigure
+ xmlns='http://namespaces.zope.org/zope'
+ xmlns:browser='http://namespaces.zope.org/browser'>
+ %s
+ </zopeConfigure>"""
+
+class Ob:
+ __implements__ = IC
+
+class Test(PlacelessSetup, unittest.TestCase):
+
+ # XXX: tests for other directives needed
+
+ def testView(self):
+
+ ob = Ob()
+ self.assertEqual(queryView(ob, 'test', Request(IBrowserPublisher), None), None)
+
+ xmlconfig(StringIO(template % (
+ """
+ <directive name="view"
+ attributes="component, name, for, layer"
+ handler="Zope.Publisher.Browser.metaConfigure.view"
+ namespace="http://namespaces.zope.org/browser" />
+ <browser:view name="test"
+ factory="Zope.Publisher.Browser.tests.TestViews.V1"
+ for="Zope.Publisher.Browser.tests.TestViews.IC" />
+ """
+ )))
+
+ self.assertEqual(queryView(ob, 'test', Request(IBrowserPublisher), None
+ ).__class__, V1)
+
+ def testDefaultView(self):
+
+ ob = Ob()
+ self.assertEqual(queryView(ob, 'test', Request(IBrowserPublisher),
+ None), None)
+
+ xmlconfig(StringIO(template % (
+ """
+ <directive name="defaultView"
+ attributes="component, name, for, layer"
+ handler="Zope.Publisher.Browser.metaConfigure.defaultView"
+ namespace="http://namespaces.zope.org/browser" />
+ <browser:defaultView name="test"
+ factory="Zope.Publisher.Browser.tests.TestViews.V1"
+ for="Zope.Publisher.Browser.tests.TestViews.IC" />
+ """
+ )))
+
+ self.assertEqual(queryView(ob, 'test', Request(IBrowserPublisher), None
+ ).__class__, V1)
+ self.assertEqual(getDefaultViewName(ob, Request(IBrowserPublisher)
+ ), 'test')
+
+
+
+ def testSKinView(self):
+
+ ob = Ob()
+ self.assertEqual(queryView(ob, 'test', Request(IBrowserPublisher), None), None)
+
+ xmlconfig(StringIO(template % (
+ """
+ <directive name="view"
+ attributes="component, name, for, layer"
+ handler="Zope.Publisher.Browser.metaConfigure.view"
+ namespace="http://namespaces.zope.org/browser" />
+ <directive name="skin" attributes="name, layers"
+ handler="Zope.Publisher.Browser.metaConfigure.skin"
+ namespace="http://namespaces.zope.org/browser" />
+ <browser:skin name="zmi" layers="zmi," />
+ <browser:view name="test"
+ factory="Zope.Publisher.Browser.tests.TestViews.VZMI"
+ layer="zmi"
+ for="Zope.Publisher.Browser.tests.TestViews.IC" />
+ <browser:view name="test"
+ factory="Zope.Publisher.Browser.tests.TestViews.V1"
+ for="Zope.Publisher.Browser.tests.TestViews.IC" />
+ """
+ )))
+
+ self.assertEqual(queryView(ob, 'test', Request(IBrowserPublisher), None
+ ).__class__, V1)
+ self.assertEqual(queryView(ob, 'test',
+ Request(IBrowserPublisher, 'zmi'), None
+ ).__class__,
+ VZMI)
+
+ def testResource(self):
+
+ ob = Ob()
+ self.assertEqual(queryResource(ob, 'test', Request(IBrowserPublisher),
+ None),
+ None)
+
+ xmlconfig(StringIO(template % (
+ """
+ <directive name="resource"
+ attributes="component, name, layer"
+ handler="Zope.Publisher.Browser.metaConfigure.resource"
+ namespace="http://namespaces.zope.org/browser" />
+ <browser:resource name="test"
+ factory="Zope.Publisher.Browser.tests.TestViews.R1" />
+ """
+ )))
+
+ self.assertEqual(
+ queryResource(ob, 'test', Request(IBrowserPublisher), None).__class__,
+ R1)
+
+ def testSkinResource(self):
+
+ ob = Ob()
+ self.assertEqual(
+ queryResource(ob, 'test', Request(IBrowserPublisher), None),
+ None)
+
+ xmlconfig(StringIO(template % (
+ """
+ <directive name="resource" attributes="component, name, layer"
+ handler="Zope.Publisher.Browser.metaConfigure.resource"
+ namespace="http://namespaces.zope.org/browser" />
+ <directive name="skin" attributes="name, layers"
+ handler="Zope.Publisher.Browser.metaConfigure.skin"
+ namespace="http://namespaces.zope.org/browser" />
+ <browser:skin name="zmi" layers="zmi," />
+ <browser:resource name="test"
+ factory="Zope.Publisher.Browser.tests.TestViews.RZMI"
+ layer="zmi" />
+ <browser:resource name="test"
+ factory="Zope.Publisher.Browser.tests.TestViews.R1" />
+ """
+ )))
+
+ self.assertEqual(
+ queryResource(ob, 'test', Request(IBrowserPublisher),
+ None).__class__,
+ R1)
+ self.assertEqual(
+ queryResource(ob, 'test', Request(IBrowserPublisher, 'zmi'),
+ None).__class__,
+ RZMI)
+
+def test_suite():
+ loader=unittest.TestLoader()
+ return loader.loadTestsFromTestCase(Test)
+
+if __name__=='__main__':
+ unittest.TextTestRunner().run(test_suite())