Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
f4783984
Commit
f4783984
authored
May 22, 2007
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #2327: Don't require wrapped context / view to render template.
parent
34404140
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
4 deletions
+62
-4
doc/CHANGES.txt
doc/CHANGES.txt
+5
-0
lib/python/Products/Five/browser/pagetemplatefile.py
lib/python/Products/Five/browser/pagetemplatefile.py
+7
-2
lib/python/Products/Five/browser/tests/test_pages.py
lib/python/Products/Five/browser/tests/test_pages.py
+50
-2
No files found.
doc/CHANGES.txt
View file @
f4783984
...
@@ -97,6 +97,11 @@ Zope Changes
...
@@ -97,6 +97,11 @@ Zope Changes
Bugs Fixed
Bugs Fixed
- Relaxed requirements for context of
Products.Five.browser.pagetemplatefile.ZopeTwoPageTemplateFile,
to reduce barriers for testing renderability of views which use them.
(http://www.zope.org/Collectors/Zope/2327)
- Collector #2304: fixed markup issue in ptEdit.zpt
- Collector #2304: fixed markup issue in ptEdit.zpt
- Collector #2260: fixed bug in Examples package
- Collector #2260: fixed bug in Examples package
...
...
lib/python/Products/Five/browser/pagetemplatefile.py
View file @
f4783984
...
@@ -17,6 +17,7 @@ $Id$
...
@@ -17,6 +17,7 @@ $Id$
"""
"""
import
os
,
sys
import
os
,
sys
from
Acquisition
import
aq_inner
from
Globals
import
package_home
from
Globals
import
package_home
from
Products.PageTemplates.PageTemplateFile
import
PageTemplateFile
from
Products.PageTemplates.PageTemplateFile
import
PageTemplateFile
from
Products.PageTemplates.Expressions
import
SecureModuleImporter
from
Products.PageTemplates.Expressions
import
SecureModuleImporter
...
@@ -65,14 +66,18 @@ class ZopeTwoPageTemplateFile(PageTemplateFile):
...
@@ -65,14 +66,18 @@ class ZopeTwoPageTemplateFile(PageTemplateFile):
try
:
try
:
root
=
self
.
getPhysicalRoot
()
root
=
self
.
getPhysicalRoot
()
except
AttributeError
:
except
AttributeError
:
root
=
self
.
context
.
getPhysicalRoot
()
try
:
root
=
self
.
context
.
getPhysicalRoot
()
except
AttributeError
:
root
=
None
# Even if the context isn't a view (when would that be exaclty?),
# Even if the context isn't a view (when would that be exaclty?),
# there shouldn't be any dange in applying a view, because it
# there shouldn't be any dange in applying a view, because it
# won't be used. However assuming that a lack of getPhysicalRoot
# won't be used. However assuming that a lack of getPhysicalRoot
# implies a missing view causes problems.
# implies a missing view causes problems.
view
=
self
.
_getContext
()
view
=
self
.
_getContext
()
here
=
self
.
context
.
aq_inner
here
=
aq_inner
(
self
.
context
)
request
=
getattr
(
root
,
'REQUEST'
,
None
)
request
=
getattr
(
root
,
'REQUEST'
,
None
)
c
=
{
'template'
:
self
,
c
=
{
'template'
:
self
,
...
...
lib/python/Products/Five/browser/tests/test_pages.py
View file @
f4783984
...
@@ -26,8 +26,8 @@ def test_ViewAcquisitionWrapping():
...
@@ -26,8 +26,8 @@ def test_ViewAcquisitionWrapping():
>>> zcml.load_config("configure.zcml", Products.Five)
>>> zcml.load_config("configure.zcml", Products.Five)
>>> zcml.load_config('pages.zcml', package=Products.Five.browser.tests)
>>> zcml.load_config('pages.zcml', package=Products.Five.browser.tests)
>>> from Products.Five.tests.testing
.simplecontent import manage_addSimpleContent
>>> from Products.Five.tests.testing
import simplecontent as sc
>>> manage_addSimpleContent(self.folder, 'testoid', 'Testoid')
>>>
sc.
manage_addSimpleContent(self.folder, 'testoid', 'Testoid')
>>> uf = self.folder.acl_users
>>> uf = self.folder.acl_users
>>> uf._doAddUser('manager', 'r00t', ['Manager'], [])
>>> uf._doAddUser('manager', 'r00t', ['Manager'], [])
>>> self.login('manager')
>>> self.login('manager')
...
@@ -60,6 +60,54 @@ def test_ViewAcquisitionWrapping():
...
@@ -60,6 +60,54 @@ def test_ViewAcquisitionWrapping():
>>> tearDown()
>>> tearDown()
"""
"""
def
test_view_with_unwrapped_context
():
"""
It may be desirable when writing tests for views themselves to
provide dummy contexts which are not wrapped.
>>> import Products.Five.browser.tests
>>> from Products.Five import zcml
>>> zcml.load_config("configure.zcml", Products.Five)
>>> zcml.load_config('pages.zcml', package=Products.Five.browser.tests)
>>> from Products.Five.tests.testing import simplecontent as sc
>>> from zope.interface import Interface
>>> from zope.interface import implements
>>> from zope.component import queryMultiAdapter
>>> class Unwrapped:
... implements(sc.ISimpleContent)
>>> unwrapped = Unwrapped()
Simple views should work fine without having their contexts wrapped:
>>> eagle = queryMultiAdapter((unwrapped, self.app.REQUEST),
... Interface, 'eagle.txt')
>>> eagle is not None
True
>>> from Products.Five.browser.tests.pages import SimpleView
>>> isinstance(eagle, SimpleView)
True
>>> eagle()
u'The eagle has landed'
We also want to be able to render the file-based ZPT without requiring
that the context be wrapped:
>>> falcon = queryMultiAdapter((unwrapped, self.app.REQUEST),
... Interface, 'falcon.html')
>>> falcon is not None
True
>>> from Products.Five.browser.tests.pages import SimpleView
>>> isinstance(falcon, SimpleView)
True
>>> print falcon()
<p>The falcon has taken flight</p>
Clean up:
>>> from zope.app.testing.placelesssetup import tearDown
>>> tearDown()
"""
def
test_suite
():
def
test_suite
():
import
unittest
import
unittest
from
Testing.ZopeTestCase
import
installProduct
,
ZopeDocTestSuite
from
Testing.ZopeTestCase
import
installProduct
,
ZopeDocTestSuite
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment