[Checkins] SVN: grokcore.view/branches/zca-only/ Updated for the use of infrae.testbrowser
Souheil CHELFOUH
souheil at chelfouh.com
Mon Mar 28 08:57:14 EDT 2011
Log message for revision 121140:
Updated for the use of infrae.testbrowser
Corrected code for redirect and the new response type.
Changed:
U grokcore.view/branches/zca-only/buildout.cfg
U grokcore.view/branches/zca-only/setup.py
U grokcore.view/branches/zca-only/src/grokcore/view/components.py
U grokcore.view/branches/zca-only/src/grokcore/view/ftesting.zcml
U grokcore.view/branches/zca-only/src/grokcore/view/ftests/test_functional.py
U grokcore.view/branches/zca-only/src/grokcore/view/ftests/url/redirect.py
U grokcore.view/branches/zca-only/src/grokcore/view/ftests/view/macros.py
U grokcore.view/branches/zca-only/src/grokcore/view/ftests/view/view.py
U grokcore.view/branches/zca-only/src/grokcore/view/tests/template/pluggability.py
U grokcore.view/branches/zca-only/src/grokcore/view/tests/view/interfacereg.py
U grokcore.view/branches/zca-only/src/grokcore/view/tests/view/update.py
U grokcore.view/branches/zca-only/src/grokcore/view/tests/view/update_redirect.py
U grokcore.view/branches/zca-only/src/grokcore/view/tests/view/view.py
-=-
Modified: grokcore.view/branches/zca-only/buildout.cfg
===================================================================
--- grokcore.view/branches/zca-only/buildout.cfg 2011-03-28 11:02:24 UTC (rev 121139)
+++ grokcore.view/branches/zca-only/buildout.cfg 2011-03-28 12:57:13 UTC (rev 121140)
@@ -8,15 +8,15 @@
extensions = mr.developer buildout.dumppickedversions
always-checkout = true
auto-checkout = cromlech.io
- cromlech.bootstrap
- cromlech.publication
cromlech.request
+ cromlech.dawnlight
+ dawnlight
[sources]
cromlech.io = git gitosis at devel.dolmen-project.org:cromlech.io.git
-cromlech.bootstrap = git gitosis at devel.dolmen-project.org:cromlech.bootstrap.git
-cromlech.publication = git gitosis at devel.dolmen-project.org:cromlech.publication.git
+cromlech.dawnlight = git gitosis at devel.dolmen-project.org:cromlech.dawnlight.git
cromlech.request = git gitosis at devel.dolmen-project.org:cromlech.request.git
+dawnlight = hg https://trollfot@bitbucket.org/trollfot/dawnlight
[versions]
grokcore.view =
Modified: grokcore.view/branches/zca-only/setup.py
===================================================================
--- grokcore.view/branches/zca-only/setup.py 2011-03-28 11:02:24 UTC (rev 121139)
+++ grokcore.view/branches/zca-only/setup.py 2011-03-28 12:57:13 UTC (rev 121140)
@@ -31,8 +31,7 @@
'zope.site',
'zope.publisher',
'infrae.testbrowser',
- 'cromlech.publication',
- 'cromlech.bootstrap',
+ 'cromlech.dawnlight',
'cromlech.request',
]
Modified: grokcore.view/branches/zca-only/src/grokcore/view/components.py
===================================================================
--- grokcore.view/branches/zca-only/src/grokcore/view/components.py 2011-03-28 11:02:24 UTC (rev 121139)
+++ grokcore.view/branches/zca-only/src/grokcore/view/components.py 2011-03-28 12:57:13 UTC (rev 121140)
@@ -35,19 +35,6 @@
charset = 'utf-8'
- @apply
- def body():
- def setBody(self, value):
- if isinstance(value, unicode):
- webob.Response.unicode_body.fset(self, value)
- else:
- webob.Response.body.fset(self, value)
-
- def getBody(self):
- return webob.Response.body.fget(self)
-
- return property(getBody, setBody)
-
def getStatus(self, as_int=True):
"""returns the status of the response
"""
@@ -142,8 +129,8 @@
def __init__(self, context, request):
self.context = context
self.request = request
- self.response = self.responseFactory()
-
+ self.response = None
+
self.__name__ = getattr(self, '__view_name__', None)
if getattr(self, 'module_info', None) is not None:
@@ -160,9 +147,10 @@
return None
template = getattr(self, 'template', None)
if template is not None:
- self.response.body = self._render_template()
+ result = self._render_template()
+ self.response.write(result)
else:
- self.response.body = self.render()
+ self.response.write(self.render() or u'')
return self.response
def _render_template(self):
@@ -192,7 +180,7 @@
filled in from the request (in that case they **must** be
present in the request).
"""
- pass
+ self.response = self.responseFactory()
def render(self, **kwargs):
"""A view can either be rendered by an associated template, or
Modified: grokcore.view/branches/zca-only/src/grokcore/view/ftesting.zcml
===================================================================
--- grokcore.view/branches/zca-only/src/grokcore/view/ftesting.zcml 2011-03-28 11:02:24 UTC (rev 121139)
+++ grokcore.view/branches/zca-only/src/grokcore/view/ftesting.zcml 2011-03-28 12:57:13 UTC (rev 121140)
@@ -6,8 +6,8 @@
package="grokcore.view">
<include package="zope.component" file="meta.zcml" />
+ <include package="zope.security" file="meta.zcml" />
<include package="zope.securitypolicy" file="meta.zcml" />
- <include package="zope.principalregistry" file="meta.zcml" />
<include package="grokcore.view" file="meta.zcml" />
<include package="zope.security" />
@@ -17,27 +17,11 @@
<include package="zope.traversing" />
<include package="zope.container" />
<include package="zope.location" />
- <include package="zope.principalregistry" />
+ <include package="zope.traversing" />
- <include package="cromlech.bootstrap" />
- <include package="cromlech.publication" file="publish.zcml" />
- <include package="cromlech.publication" file="traverse.zcml" />
- <include package="cromlech.request" file="webob.zcml" />
-
+ <include package="cromlech.dawnlight" />
<include package="grokcore.view" />
+
<grok:grok package="grokcore.view.ftests" />
- <securityPolicy
- component="zope.securitypolicy.zopepolicy.ZopeSecurityPolicy"
- />
-
- <unauthenticatedGroup
- id="zope.Anybody"
- title="Unauthenticated Users" />
-
- <grant
- permission="zope.View"
- principal="zope.Anybody"
- />
-
</configure>
Modified: grokcore.view/branches/zca-only/src/grokcore/view/ftests/test_functional.py
===================================================================
--- grokcore.view/branches/zca-only/src/grokcore/view/ftests/test_functional.py 2011-03-28 11:02:24 UTC (rev 121139)
+++ grokcore.view/branches/zca-only/src/grokcore/view/ftests/test_functional.py 2011-03-28 12:57:13 UTC (rev 121140)
@@ -11,11 +11,12 @@
import webob.dec
import transaction
-from cromlech.bootstrap.testlayer import ZODBLayer
-from cromlech.bootstrap.helper import Bootstrapper
+from cromlech.dawnlight.publish import DawnlightPublisher
from cromlech.io.interfaces import IRequest, IPublisher
-
-from persistent.interfaces import IPersistent
+from zope.component.testlayer import ZCMLFileLayer
+from cromlech.dawnlight import IDawnlightApplication
+import zope.component
+from zope.component import hooks
from pkg_resources import resource_listdir
from zope.component import getMultiAdapter
from zope.event import notify
@@ -27,6 +28,8 @@
from zope.security.interfaces import IGroupAwarePrincipal
from zope.security.testing import Participation
from zope.security.management import newInteraction, endInteraction
+from zope.component.interfaces import ISite
+from zope.site.site import LocalSiteManager
class IUnauthenticatedPrincipal(IGroupAwarePrincipal):
@@ -48,63 +51,60 @@
'Unauthenticated principal',
'The default unauthenticated principal.')
-ROOT = 'grok'
- at grokcore.component.implementer(IRootFolder)
- at grokcore.component.adapter(IPersistent, types.BooleanType)
-def test_root(db_root, creation=False):
- print "Creation of ROOT : %s" % creation
- folder = db_root.get(ROOT, None)
- if folder is None and creation is True:
- folder = rootFolder()
- notify(ObjectCreatedEvent(folder))
- db_root[ROOT] = folder
- return folder
+class Interaction(object):
+ def __init__(self, user):
+ self.user = user
+ def __enter__(self):
+ participation = Participation(self.user)
+ newInteraction(participation)
+ return participation
-def getUser(wsgiapp, app, request):
- request.setPrincipal(unauthenticated_principal)
- return unauthenticated_principal
+ def __exit__(self, type, value, traceback):
+ endInteraction()
-class Interaction(object):
+class SitePublisher(object):
- def __init__(self, user, request):
-
+ def __init__(self, request, app, site):
+ self.app = app
+ self.request = request
+ self.site = site
def __enter__(self):
- participation = Participation(unauthenticated_principal)
- newInteraction(participation)
- return participation
+ publisher = DawnlightPublisher(self.request, self.app)
+ if not ISite.providedBy(self.site):
+ site_manager = LocalSiteManager(self.site)
+ self.site.setSiteManager(site_manager)
+
+ zope.component.hooks.setSite(self.site)
+ return publisher
+
def __exit__(self, type, value, traceback):
- endInteraction()
- if traceback is not None:
- logger.warn(value)
+ zope.component.hooks.setSite()
+SITE = rootFolder()
+
class WSGIApplication(object):
+ implements(IDawnlightApplication)
- def __init__(self, db):
- self.db = db
+ def __init__(self, user):
+ self.user = user
@webob.dec.wsgify
- def __call__(self, webob_req):
-
- request = IRequest(webob_req)
-
- with Bootstrapper(self.db) as root, app:
- with transaction:
- user = setUser(self, app, request)
- with Interaction(user) as participation:
- response = getMultiAdapter(
- (request, root, )
-
+ def __call__(self, req):
+ request = getMultiAdapter((req, self), IRequest)
+ with Interaction(self.user) as participation:
+ with SitePublisher(request, self, SITE) as publisher:
+ response = publisher.publish(SITE, handle_errors=False)
return response
-class BrowserLayer(ZODBLayer):
+class BrowserLayer(ZCMLFileLayer):
"""This create a test layer with a test database and register a wsgi
application to use that test database.
@@ -114,13 +114,20 @@
"""
def testSetUp(self):
- ZODBLayer.testSetUp(self)
- self.application = WSGIApplication(self.db)
+ ZCMLFileLayer.testSetUp(self)
+ zope.component.hooks.setHooks()
+ self.application = WSGIApplication
- def getApplication(self):
- return self.application
+ def getRootFolder(self):
+ return SITE
+ def getApplication(self, user=unauthenticated_principal):
+ return self.application(user)
+ def testTearDown(self):
+ SITE.data.clear()
+
+
FunctionalLayer = BrowserLayer(grokcore.view)
Modified: grokcore.view/branches/zca-only/src/grokcore/view/ftests/url/redirect.py
===================================================================
--- grokcore.view/branches/zca-only/src/grokcore/view/ftests/url/redirect.py 2011-03-28 11:02:24 UTC (rev 121139)
+++ grokcore.view/branches/zca-only/src/grokcore/view/ftests/url/redirect.py 2011-03-28 12:57:13 UTC (rev 121140)
@@ -14,12 +14,12 @@
>>> browser.open('http://localhost/manfred')
>>> browser.url
- 'http://localhost/manfred/another'
+ '/manfred'
- >>> response = browser.open('http://localhost/manfred/trustedredirect')
- >>> response.status_code
+ >>> status = browser.open('http://localhost/manfred/trustedredirect')
+ >>> browser.status_code
302
- >>> response.location
+ >>> browser.location
'http://www.google.com/ncr'
>>> browser.open('http://localhost/manfred/redirectwithstatus')
@@ -27,26 +27,36 @@
...
HTTPError: HTTP Error 418: Unknown
>>> browser.url
- 'http://localhost/manfred/redirectwithstatus'
+ '/manfred/redirectwithstatus'
"""
import grokcore.view as grok
+
class Mammoth(grok.Context):
pass
+
class Index(grok.View):
def render(self):
self.redirect(self.url('another'))
+
class TrustedRedirect(grok.View):
- def render(self):
+
+ def update(self):
+ super(TrustedRedirect, self).update()
self.redirect('http://www.google.com/ncr', trusted=True)
+ def render(self):
+ return self.response
+
+
class RedirectWithStatus(grok.View):
def render(self):
self.redirect(self.url(), status=418)
+
class Another(grok.View):
def render(self):
return "Another view"
Modified: grokcore.view/branches/zca-only/src/grokcore/view/ftests/view/macros.py
===================================================================
--- grokcore.view/branches/zca-only/src/grokcore/view/ftests/view/macros.py 2011-03-28 11:02:24 UTC (rev 121139)
+++ grokcore.view/branches/zca-only/src/grokcore/view/ftests/view/macros.py 2011-03-28 12:57:13 UTC (rev 121140)
@@ -7,7 +7,7 @@
>>> browser = Browser(application)
>>> browser.options.handle_errors = False
- >>> browser.open("http://localhost/manfred/@@painting")
+ >>> status = browser.open("http://localhost/manfred/painting")
>>> print browser.contents
<html>
<body>
@@ -20,14 +20,14 @@
Views without a template do not support macros:
- >>> browser.open("http://localhost/manfred/@@dancing")
+ >>> status = browser.open("http://localhost/manfred/dancing")
Traceback (most recent call last):
AttributeError: 'DancingHall' object has no attribute 'template'
If the view has an attribute with the same name as a macro, the macro
shadows the view. XXX This should probably generate a warning at runtime.
- >>> browser.open("http://localhost/manfred/@@grilldish")
+ >>> status = browser.open("http://localhost/manfred/grilldish")
>>> print browser.contents
<html>
Curry
@@ -40,7 +40,7 @@
>>> saved_warn = warnings.warn
>>> warnings.warn = warn
- >>> browser.open("http://localhost/manfred/@@burnt")
+ >>> status = browser.open("http://localhost/manfred/burnt")
From grok.testing's warn():
... DeprecationWarning: Calling macros directly on the view is deprecated. Please use context/@@viewname/macros/macroname
...
@@ -58,7 +58,7 @@
>>> before = open(template_file, 'r').read()
>>> changed = before.replace('GROK', 'GROK RELOADED')
>>> open(template_file, 'w').write(changed)
- >>> browser.open("http://localhost/manfred/@@painting")
+ >>> status = browser.open("http://localhost/manfred/painting")
>>> print browser.contents
<html>
<body>
Modified: grokcore.view/branches/zca-only/src/grokcore/view/ftests/view/view.py
===================================================================
--- grokcore.view/branches/zca-only/src/grokcore/view/ftests/view/view.py 2011-03-28 11:02:24 UTC (rev 121139)
+++ grokcore.view/branches/zca-only/src/grokcore/view/ftests/view/view.py 2011-03-28 12:57:13 UTC (rev 121140)
@@ -8,7 +8,7 @@
>>> browser = Browser(application)
>>> browser.options.handle_errors = False
- >>> browser.open("http://localhost/manfred/@@painting")
+ >>> status = browser.open("http://localhost/manfred/@@painting")
>>> print browser.contents
<html>
<body>
Modified: grokcore.view/branches/zca-only/src/grokcore/view/tests/template/pluggability.py
===================================================================
--- grokcore.view/branches/zca-only/src/grokcore/view/tests/template/pluggability.py 2011-03-28 11:02:24 UTC (rev 121139)
+++ grokcore.view/branches/zca-only/src/grokcore/view/tests/template/pluggability.py 2011-03-28 12:57:13 UTC (rev 121140)
@@ -52,7 +52,9 @@
def namespace(self, view):
# I'll override the default namespace here for testing:
- return {'middle_text': 'is in'}
+ ns = {'middle_text': 'is in'}
+ ns.update(view.namespace())
+ return ns
def render(self, view):
return self._template.render(**self.namespace(view))
Modified: grokcore.view/branches/zca-only/src/grokcore/view/tests/view/interfacereg.py
===================================================================
--- grokcore.view/branches/zca-only/src/grokcore/view/tests/view/interfacereg.py 2011-03-28 11:02:24 UTC (rev 121139)
+++ grokcore.view/branches/zca-only/src/grokcore/view/tests/view/interfacereg.py 2011-03-28 12:57:13 UTC (rev 121140)
@@ -16,27 +16,27 @@
defaults to the lowercase of the class:
>>> view = component.getMultiAdapter((manfred, request), name='cavepainting')
- >>> view()
- 'a chalk cave painting'
+ >>> print str(view())
+ a chalk cave painting
It is also possible to look up the same view by also including the interface:
>>> view = component.getMultiAdapter(
... (manfred, request), interface=IChalk, name='cavepainting')
- >>> print view()
+ >>> print str(view())
a chalk cave painting
The name can be set to '', in which case it is an 'unnamed' view:
>>> view = component.getMultiAdapter((manfred, request), interface=IRealist)
- >>> print view()
+ >>> print str(view())
a realist cave painting
Multipl IPaintStyles can now be looked up by interface, rather than name:
>>> view = component.getMultiAdapter(
... (manfred, request), interface=IImpressionist)
- >>> print view()
+ >>> print str(view())
an impressionist cave painting
"""
Modified: grokcore.view/branches/zca-only/src/grokcore/view/tests/view/update.py
===================================================================
--- grokcore.view/branches/zca-only/src/grokcore/view/tests/view/update.py 2011-03-28 11:02:24 UTC (rev 121139)
+++ grokcore.view/branches/zca-only/src/grokcore/view/tests/view/update.py 2011-03-28 12:57:13 UTC (rev 121140)
@@ -5,34 +5,32 @@
>>> grok.testing.grok(__name__)
-We need to set up a default ITraversable adapter so that TALES
-expressions can resolve paths:
+ >>> from zope.publisher.browser import TestRequest
+ >>> from zope.component import getMultiAdapter
- >>> from zope import component
- >>> from zope.traversing.adapters import DefaultTraversable
- >>> component.provideAdapter(DefaultTraversable, (None,))
-
>>> manfred = Mammoth()
- >>> from zope.publisher.browser import TestRequest
>>> request = TestRequest()
- >>> view = component.getMultiAdapter((manfred, request), name='cavepainting')
- >>> print view()
+ >>> view = getMultiAdapter((manfred, request), name='cavepainting')
+ >>> print str(view())
<html>
<body>
<h1>red</h1>
<h1>red</h1>
</body>
</html>
-
+
"""
import grokcore.view as grok
+
class Mammoth(grok.Context):
pass
+
class CavePainting(grok.View):
def update(self):
+ super(CavePainting, self).update()
self.color = "red"
Modified: grokcore.view/branches/zca-only/src/grokcore/view/tests/view/update_redirect.py
===================================================================
--- grokcore.view/branches/zca-only/src/grokcore/view/tests/view/update_redirect.py 2011-03-28 11:02:24 UTC (rev 121139)
+++ grokcore.view/branches/zca-only/src/grokcore/view/tests/view/update_redirect.py 2011-03-28 12:57:13 UTC (rev 121140)
@@ -26,6 +26,7 @@
class CavePainting(grok.View):
def update(self):
+ super(CavePainting, self).update()
self.redirect('somewhere-else')
Modified: grokcore.view/branches/zca-only/src/grokcore/view/tests/view/view.py
===================================================================
--- grokcore.view/branches/zca-only/src/grokcore/view/tests/view/view.py 2011-03-28 11:02:24 UTC (rev 121139)
+++ grokcore.view/branches/zca-only/src/grokcore/view/tests/view/view.py 2011-03-28 12:57:13 UTC (rev 121140)
@@ -9,8 +9,8 @@
>>> request = TestRequest()
>>> from zope import component
>>> view = component.getMultiAdapter((manfred, request), name='cavepainting')
- >>> view()
- 'A cave painting of a mammoth'
+ >>> print str(view())
+ A cave painting of a mammoth
>>> view.context is manfred
True
@@ -25,8 +25,8 @@
Look up a view with a name explicitly set with ``grok.name``:
>>> view = component.getMultiAdapter((manfred, request), name='meal')
- >>> view()
- 'Mammoth burger'
+ >>> print str(view())
+ Mammoth burger
There's no view 'food':
More information about the checkins
mailing list