[Zope3-checkins] CVS: Zope3/src/zope/app/publisher/browser/tests - test_directives.py:1.6
Jim Fulton
jim@zope.com
Mon, 30 Dec 2002 18:33:47 -0500
Update of /cvs-repository/Zope3/src/zope/app/publisher/browser/tests
In directory cvs.zope.org:/tmp/cvs-serv16088/tests
Modified Files:
test_directives.py
Log Message:
Added a new directive, page, to be udes when creating simple one-page
views. This directive uses:
- Uses a class attribute rather than a factory
- requires that a permission be specified, but allows the permission
to be "*", to apply to all objects.
- Alloes a menu id and title to be specified so that you don't need to
use a separate menuItem directive.
=== Zope3/src/zope/app/publisher/browser/tests/test_directives.py 1.5 => 1.6 ===
--- Zope3/src/zope/app/publisher/browser/tests/test_directives.py:1.5 Sat Dec 28 12:49:30 2002
+++ Zope3/src/zope/app/publisher/browser/tests/test_directives.py Mon Dec 30 18:33:46 2002
@@ -33,6 +33,9 @@
from zope.app.publisher.browser.i18nfileresource import I18nFileResource
import zope.app.publisher.browser
+from zope.component.service import serviceManager
+from zope.app.interfaces.security import IPermissionService
+from zope.app.security.registries.permissionregistry import permissionRegistry
tests_path = os.path.join(
os.path.split(zope.app.publisher.browser.__file__)[0],
@@ -71,21 +74,23 @@
provideAdapter(None, ITraversable, DefaultTraversable)
- def testView(self):
+ def testPage(self):
self.assertEqual(queryView(ob, 'test', request),
None)
xmlconfig(StringIO(template % (
"""
- <browser:view name="test"
- factory="zope.component.tests.views.V1"
- for="zope.component.tests.views.IC" />
+ <browser:page name="test"
+ class="zope.component.tests.views.V1"
+ for="zope.component.tests.views.IC"
+ permission="zope.Public"
+ attribute="index"
+ />
"""
)))
- self.assertEqual(
- queryView(ob, 'test', request).__class__,
- V1)
+ v = queryView(ob, 'test', request)
+ self.assert_(issubclass(v.__class__, V1))
def testDefaultView(self):
self.assertEqual(queryView(ob, 'test', request,
@@ -94,42 +99,41 @@
xmlconfig(StringIO(template % (
"""
<browser:defaultView name="test"
- factory="zope.component.tests.views.V1"
- for="zope.component.tests.views.IC" />
+ for="zope.component.tests.views.IC" />
"""
)))
- self.assertEqual(queryView(ob, 'test',
- request, None
- ).__class__, V1)
self.assertEqual(getDefaultViewName(ob, request
), 'test')
- def testSkinView(self):
+ def testSkinPage(self):
self.assertEqual(queryView(ob, 'test', request,
None), None)
xmlconfig(StringIO(template % (
"""
<browser:skin name="zmi" layers="zmi default" />
- <browser:view name="test"
- factory="zope.component.tests.views.VZMI"
+ <browser:page name="test"
+ class="zope.component.tests.views.VZMI"
layer="zmi"
- for="zope.component.tests.views.IC" />
- <browser:view name="test"
- factory="zope.component.tests.views.V1"
- for="zope.component.tests.views.IC" />
+ for="zope.component.tests.views.IC"
+ permission="zope.Public"
+ attribute="index"
+ />
+ <browser:page name="test"
+ class="zope.component.tests.views.V1"
+ for="zope.component.tests.views.IC"
+ permission="zope.Public"
+ attribute="index"
+ />
"""
)))
- self.assertEqual(
- queryView(ob, 'test', request).__class__,
- V1)
- self.assertEqual(
- queryView(ob, 'test',
- Request(IBrowserPresentation, 'zmi')).__class__,
- VZMI)
+ v = queryView(ob, 'test', request)
+ self.assert_(issubclass(v.__class__, V1))
+ v = queryView(ob, 'test', Request(IBrowserPresentation, 'zmi'))
+ self.assert_(issubclass(v.__class__, VZMI))
def testI18nResource(self):
self.assertEqual(queryResource(ob, 'test', request,
@@ -177,11 +181,12 @@
))
self.assertRaises(ConfigurationError, xmlconfig, config)
- def testInterfaceProtectedView(self):
+ def testInterfaceProtectedPage(self):
xmlconfig(StringIO(template %
"""
- <browser:view name="test"
- factory="zope.component.tests.views.V1"
+ <browser:page name="test"
+ class="zope.component.tests.views.V1"
+ attribute="index"
for="zope.component.tests.views.IC"
permission="zope.Public"
allowed_interface="zope.component.tests.views.IV"
@@ -194,12 +199,13 @@
self.assertEqual(v.index(), 'V1 here')
self.assertRaises(Exception, getattr, v, 'action')
- def testAttributeProtectedView(self):
+ def testAttributeProtectedPage(self):
xmlconfig(StringIO(template %
"""
- <browser:view name="test"
- factory="zope.component.tests.views.V1"
+ <browser:page name="test"
+ class="zope.component.tests.views.V1"
for="zope.component.tests.views.IC"
+ attribute="action"
permission="zope.Public"
allowed_attributes="action"
/>
@@ -211,15 +217,16 @@
self.assertEqual(v.action(), 'done')
self.assertRaises(Exception, getattr, v, 'index')
- def testInterfaceAndAttributeProtectedView(self):
+ def testInterfaceAndAttributeProtectedPage(self):
xmlconfig(StringIO(template %
"""
- <browser:view name="test"
- factory="zope.component.tests.views.V1"
+ <browser:page name="test"
+ class="zope.component.tests.views.V1"
for="zope.component.tests.views.IC"
permission="zope.Public"
+ attribute="index"
allowed_attributes="action"
- allowed_interface="zope.component.tests.views.IV"
+ allowed_interface="zope.component.tests.views.IV"
/>
"""
))
@@ -228,15 +235,16 @@
self.assertEqual(v.index(), 'V1 here')
self.assertEqual(v.action(), 'done')
- def testDuplicatedInterfaceAndAttributeProtectedView(self):
+ def testDuplicatedInterfaceAndAttributeProtectedPage(self):
xmlconfig(StringIO(template %
"""
- <browser:view name="test"
- factory="zope.component.tests.views.V1"
+ <browser:page name="test"
+ class="zope.component.tests.views.V1"
for="zope.component.tests.views.IC"
+ attribute="index"
permission="zope.Public"
allowed_attributes="action index"
- allowed_interface="zope.component.tests.views.IV"
+ allowed_interface="zope.component.tests.views.IV"
/>
"""
))
@@ -245,15 +253,16 @@
self.assertEqual(v.index(), 'V1 here')
self.assertEqual(v.action(), 'done')
- def testIncompleteProtectedViewNoPermission(self):
+ def testIncompleteProtectedPageNoPermission(self):
self.assertRaises(
ConfigurationError,
xmlconfig,
StringIO(template %
"""
- <browser:view name="test"
- factory="zope.component.tests.views.V1"
+ <browser:page name="test"
+ class="zope.component.tests.views.V1"
for="zope.component.tests.views.IC"
+ attribute="index"
allowed_attributes="action index"
/>
"""
@@ -530,7 +539,7 @@
r = removeAllProxies(r)
self.assertEqual(r._testData(), open(path, 'rb').read())
- def testtemplate(self):
+ def test_template_page(self):
path = os.path.join(tests_path, 'test.pt')
self.assertEqual(queryView(ob, 'index.html', request),
@@ -538,9 +547,10 @@
xmlconfig(StringIO(template %
"""
- <browser:view
+ <browser:page
name="index.html"
template="%s"
+ permission="zope.Public"
for="zope.component.tests.views.IC" />
""" % path
))
@@ -556,9 +566,10 @@
xmlconfig(StringIO(template %
"""
- <browser:view
+ <browser:page
name="index.html"
template="%s"
+ permission="zope.Public"
class="zope.app.publisher.browser.tests.templateclass."
for="zope.component.tests.views.IC" />
""" % path
@@ -568,6 +579,10 @@
self.assertEqual(v().strip(), '<html><body><p>42</p></body></html>')
def testProtectedtemplate(self):
+
+ serviceManager.defineService('Permissions', IPermissionService)
+ serviceManager.provideService('Permissions', permissionRegistry)
+
path = os.path.join(tests_path, 'test.pt')
self.assertEqual(queryView(ob, 'test', request),
@@ -584,7 +599,7 @@
<permission id="XXX" title="xxx" />
- <browser:view
+ <browser:page
name="xxx.html"
template="%s"
permission="XXX"
@@ -623,7 +638,7 @@
xmlconfig,
StringIO(template %
"""
- <browser:view
+ <browser:page
template="%s"
for="zope.component.tests.views.IC"
/>