[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Publisher/Browser/tests - test.pt:1.1.2.1 testDirectives.py:1.1.2.2
Jim Fulton
jim@zope.com
Sun, 2 Jun 2002 10:35:23 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/Publisher/Browser/tests
In directory cvs.zope.org:/tmp/cvs-serv29793/lib/python/Zope/App/Publisher/Browser/tests
Modified Files:
Tag: Zope3InWonderland-branch
testDirectives.py
Added Files:
Tag: Zope3InWonderland-branch
test.pt
Log Message:
- Added template attribute to allow views to be created from a
template source file.
- Added beginnings of a Zope debugger. This required seperating site
and server configuration.
- Added the ability to specify a config file package in the
zopeConfigure directive. Made "config.zcml" a default for the file
attribute in the include directive.
- Fixed mapply to unwrap proxied objects. This was necessary once
views became wrapped in proxies. We need to investigate why they
weren't being wrapped before.
- I updated enough system page templates and zcml directives so that:
- Zope now starts. :)
- The root folder contents listing can be viewed.
Many more templates and zcml files need to be updated to reflect the
way views are now handled.
=== Added File Zope3/lib/python/Zope/App/Publisher/Browser/tests/test.pt ===
<html><body><p>test</p></body></html>
=== Zope3/lib/python/Zope/App/Publisher/Browser/tests/testDirectives.py 1.1.2.1 => 1.1.2.2 ===
</zopeConfigure>"""
+request = Request(IBrowserPresentation)
+
class Ob:
__implements__ = IC
+ob = Ob()
+
class Test(PlacelessSetup, unittest.TestCase):
def setUp(self):
@@ -51,9 +55,7 @@
xmlconfig(open(defs_path))
def testView(self):
-
- ob = Ob()
- self.assertEqual(queryView(ob, 'test', Request(IBrowserPresentation)),
+ self.assertEqual(queryView(ob, 'test', request),
None)
xmlconfig(StringIO(template % (
@@ -65,13 +67,11 @@
)))
self.assertEqual(
- queryView(ob, 'test', Request(IBrowserPresentation)).__class__,
+ queryView(ob, 'test', request).__class__,
V1)
def testDefaultView(self):
-
- ob = Ob()
- self.assertEqual(queryView(ob, 'test', Request(IBrowserPresentation),
+ self.assertEqual(queryView(ob, 'test', request,
None), None)
xmlconfig(StringIO(template % (
@@ -83,16 +83,14 @@
)))
self.assertEqual(queryView(ob, 'test',
- Request(IBrowserPresentation), None
+ request, None
).__class__, V1)
- self.assertEqual(getDefaultViewName(ob, Request(IBrowserPresentation)
+ self.assertEqual(getDefaultViewName(ob, request
), 'test')
def testSKinView(self):
-
- ob = Ob()
- self.assertEqual(queryView(ob, 'test', Request(IBrowserPresentation),
+ self.assertEqual(queryView(ob, 'test', request,
None), None)
xmlconfig(StringIO(template % (
@@ -109,7 +107,7 @@
)))
self.assertEqual(
- queryView(ob, 'test', Request(IBrowserPresentation)).__class__,
+ queryView(ob, 'test', request).__class__,
V1)
self.assertEqual(
queryView(ob, 'test',
@@ -117,9 +115,7 @@
VZMI)
def testResource(self):
-
- ob = Ob()
- self.assertEqual(queryResource(ob, 'test', Request(IBrowserPresentation),
+ self.assertEqual(queryResource(ob, 'test', request,
None),
None)
@@ -131,14 +127,12 @@
)))
self.assertEqual(
- queryResource(ob, 'test', Request(IBrowserPresentation)).__class__,
+ queryResource(ob, 'test', request).__class__,
R1)
def testSkinResource(self):
-
- ob = Ob()
self.assertEqual(
- queryResource(ob, 'test', Request(IBrowserPresentation), None),
+ queryResource(ob, 'test', request, None),
None)
xmlconfig(StringIO(template % (
@@ -153,7 +147,7 @@
)))
self.assertEqual(
- queryResource(ob, 'test', Request(IBrowserPresentation)).__class__,
+ queryResource(ob, 'test', request).__class__,
R1)
self.assertEqual(
queryResource(ob, 'test',
@@ -173,7 +167,7 @@
"""
))
- v = getView(Ob(), 'test', Request(IBrowserPresentation))
+ v = getView(ob, 'test', request)
self.assertEqual(v.index(), 'V1 here')
self.assertRaises(Exception, getattr, v, 'action')
@@ -189,7 +183,7 @@
"""
))
- v = getView(Ob(), 'test', Request(IBrowserPresentation))
+ v = getView(ob, 'test', request)
self.assertEqual(v.action(), 'done')
self.assertRaises(Exception, getattr, v, 'index')
@@ -206,7 +200,7 @@
"""
))
- v = getView(Ob(), 'test', Request(IBrowserPresentation))
+ v = getView(ob, 'test', request)
self.assertEqual(v.index(), 'V1 here')
self.assertEqual(v.action(), 'done')
@@ -223,24 +217,10 @@
"""
))
- v = getView(Ob(), 'test', Request(IBrowserPresentation))
+ v = getView(ob, 'test', request)
self.assertEqual(v.index(), 'V1 here')
self.assertEqual(v.action(), 'done')
- def testIncompleteProtectedView(self):
- self.assertRaises(
- ConfigurationError,
- xmlconfig,
- StringIO(template %
- """
- <browser:view name="test"
- factory="Zope.ComponentArchitecture.tests.TestViews.V1"
- for="Zope.ComponentArchitecture.tests.TestViews.IC"
- permission_id="Zope.Public"
- />
- """
- ))
-
def testIncompleteProtectedViewNoPermission(self):
self.assertRaises(
ConfigurationError,
@@ -257,9 +237,7 @@
def testPageViews(self):
-
- ob = Ob()
- self.assertEqual(queryView(ob, 'test', Request(IBrowserPresentation)),
+ self.assertEqual(queryView(ob, 'test', request),
None)
xmlconfig(StringIO(template %
@@ -274,41 +252,13 @@
"""
))
- v = getView(Ob(), 'index.html', Request(IBrowserPresentation))
+ v = getView(ob, 'index.html', request)
self.assertEqual(v(), 'V1 here')
- v = getView(Ob(), 'action.html', Request(IBrowserPresentation))
+ v = getView(ob, 'action.html', request)
self.assertEqual(v(), 'done')
- def testDefaultPageViews(self):
-
- ob = Ob()
- self.assertEqual(queryView(ob, 'test', Request(IBrowserPresentation)),
- None)
-
- xmlconfig(StringIO(template %
- """
- <browser:view
- factory="Zope.ComponentArchitecture.tests.TestViews.V1"
- for="Zope.ComponentArchitecture.tests.TestViews.IC">
-
- <browser:defaultPage name="index.html" attribute="index" />
- <browser:page name="action.html" attribute="action" />
- </browser:view>
- """
- ))
-
- v = getView(Ob(), 'index.html', Request(IBrowserPresentation))
- self.assertEqual(v(), 'V1 here')
- v = getView(Ob(), 'action.html', Request(IBrowserPresentation))
- self.assertEqual(v(), 'done')
- self.assertEqual(getDefaultViewName(Ob(),
- Request(IBrowserPresentation)),
- 'index.html')
-
def testPageViewsWithName(self):
-
- ob = Ob()
- self.assertEqual(queryView(ob, 'test', Request(IBrowserPresentation)),
+ self.assertEqual(queryView(ob, 'test', request),
None)
xmlconfig(StringIO(template %
@@ -323,19 +273,17 @@
"""
))
- v = getView(Ob(), 'index.html', Request(IBrowserPresentation))
+ v = getView(ob, 'index.html', request)
self.assertEqual(v(), 'V1 here')
- v = getView(Ob(), 'action.html', Request(IBrowserPresentation))
+ v = getView(ob, 'action.html', request)
self.assertEqual(v(), 'done')
- v = getView(Ob(), 'test', Request(IBrowserPresentation))
+ v = getView(ob, 'test', request)
self.assertEqual(v.index(), 'V1 here')
self.assertEqual(v.action(), 'done')
def testProtectedPageViews(self):
-
- ob = Ob()
- self.assertEqual(queryView(ob, 'test', Request(IBrowserPresentation)),
+ self.assertEqual(queryView(ob, 'test', request),
None)
xmlconfig(StringIO(template %
@@ -360,19 +308,17 @@
"""
))
+ # Need to "log someone in" to turn on checks
from Zope.Security.SecurityManagement import newSecurityManager
newSecurityManager('someuser')
- v = getView(Ob(), 'index.html', Request(IBrowserPresentation))
+ v = getView(ob, 'index.html', request)
self.assertRaises(Exception, v)
- v = getView(Ob(), 'action.html', Request(IBrowserPresentation))
+ v = getView(ob, 'action.html', request)
self.assertEqual(v(), 'done')
def testSkinnedPageView(self):
-
- ob = Ob()
- self.assertEqual(queryView(ob, 'test', Request(IBrowserPresentation)),
- None)
+ self.assertEqual(queryView(ob, 'test', request), None)
xmlconfig(StringIO(template %
"""
@@ -387,18 +333,14 @@
"""
))
- v = getView(Ob(), 'index.html', Request(IBrowserPresentation))
+ v = getView(ob, 'index.html', request)
self.assertEqual(v(), 'V1 here')
- v = getView(Ob(), 'index.html',
+ v = getView(ob, 'index.html',
Request(IBrowserPresentation, "skinny"))
self.assertEqual(v(), 'done')
def testPageResource(self):
-
- ob = Ob()
- self.assertEqual(queryResource(ob, 'test',
- Request(IBrowserPresentation)),
- None)
+ self.assertEqual(queryResource(ob, 'test', request), None)
xmlconfig(StringIO(template %
"""
@@ -411,10 +353,121 @@
"""
))
- v = getResource(Ob(), 'index.html', Request(IBrowserPresentation))
+ v = getResource(ob, 'index.html', request)
self.assertEqual(v(), 'R1 here')
- v = getResource(Ob(), 'action.html', Request(IBrowserPresentation))
+ v = getResource(ob, 'action.html', request)
self.assertEqual(v(), 'R done')
+
+ def testtemplate(self):
+ path = os.path.join(os.path.split(defs_path)[0], 'tests', 'test.pt')
+
+ self.assertEqual(queryView(ob, 'test', request),
+ None)
+
+ xmlconfig(StringIO(template %
+ """
+ <browser:view
+ name="index.html"
+ template="%s"
+ for="Zope.ComponentArchitecture.tests.TestViews.IC" />
+ """ % path
+ ))
+
+ v = getView(ob, 'index.html', request)
+ self.assertEqual(v().strip(), '<html><body><p>test</p></body></html>')
+
+ def testProtectedtemplate(self):
+ path = os.path.join(os.path.split(defs_path)[0], 'tests', 'test.pt')
+
+ self.assertEqual(queryView(ob, 'test', request),
+ None)
+
+ xmlconfig(StringIO(template %
+ """
+ <directives namespace="http://namespaces.zope.org/security">
+ <directive name="permission"
+ attributes="permission_id, title, description"
+ handler="Zope.App.Security.metaConfigure.definePermission" />
+ </directives>
+
+ <security:permission permission_id="XXX" title="xxx" />
+
+ <browser:view
+ name="xxx.html"
+ template="%s"
+ permission_id="XXX"
+ for="Zope.ComponentArchitecture.tests.TestViews.IC" />
+ """ % path
+ ))
+
+ xmlconfig(StringIO(template %
+ """
+ <browser:view
+ name="index.html"
+ template="%s"
+ permission_id="Zope.Public"
+ for="Zope.ComponentArchitecture.tests.TestViews.IC" />
+ """ % path
+ ))
+
+ # Need to "log someone in" to turn on checks
+ from Zope.Security.SecurityManagement import newSecurityManager
+ newSecurityManager('someuser')
+
+ v = getView(ob, 'xxx.html', request)
+ self.assertRaises(Exception, v)
+
+ v = getView(ob, 'index.html', request)
+ self.assertEqual(v().strip(), '<html><body><p>test</p></body></html>')
+
+
+ def testtemplateNoName(self):
+ path = os.path.join(os.path.split(defs_path)[0], 'tests', 'test.pt')
+ self.assertRaises(
+ ConfigurationError,
+ xmlconfig,
+ StringIO(template %
+ """
+ <browser:view
+ template="%s"
+ for="Zope.ComponentArchitecture.tests.TestViews.IC"
+ />
+ """ % path
+ ))
+
+ def testtemplateAndFactory(self):
+ path = os.path.join(os.path.split(defs_path)[0], 'tests', 'test.pt')
+ self.assertRaises(
+ ConfigurationError,
+ xmlconfig,
+ StringIO(template %
+ """
+ <browser:view
+ name="index.html"
+ template="%s"
+ for="Zope.ComponentArchitecture.tests.TestViews.IC"
+ factory="Zope.ComponentArchitecture.tests.TestViews.V1">
+ />
+ """ % path
+ ))
+
+ def testtemplateAndPage(self):
+ path = os.path.join(os.path.split(defs_path)[0], 'tests', '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():