[Checkins] SVN: grokcore.view/branches/zca-only/src/grokcore/view/ftest Added custom cromlech bits.
Souheil CHELFOUH
souheil at chelfouh.com
Fri Mar 18 11:52:35 EDT 2011
Log message for revision 121037:
Added custom cromlech bits.
Changed tests to fit the adaptations
Changed:
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/url/url.py
U grokcore.view/branches/zca-only/src/grokcore/view/ftests/url/url_function.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/macros_templates/layout.pt
-=-
Modified: grokcore.view/branches/zca-only/src/grokcore/view/ftesting.zcml
===================================================================
--- grokcore.view/branches/zca-only/src/grokcore/view/ftesting.zcml 2011-03-18 15:38:19 UTC (rev 121036)
+++ grokcore.view/branches/zca-only/src/grokcore/view/ftesting.zcml 2011-03-18 15:52:35 UTC (rev 121037)
@@ -5,12 +5,20 @@
i18n_domain="grokcore.view"
package="grokcore.view">
+ <include package="zope.component" 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" />
+ <include package="zope.annotation" />
<include package="zope.securitypolicy" />
+ <include package="zope.site" />
+ <include package="zope.traversing" />
+ <include package="zope.container" />
+ <include package="zope.location" />
+ <include package="zope.principalregistry" />
- <include package="zope.component" file="meta.zcml" />
- <include package="grokcore.view" file="meta.zcml" />
-
<include package="cromlech.bootstrap" />
<include package="cromlech.publication" file="publish.zcml" />
<include package="cromlech.publication" file="traverse.zcml" />
@@ -19,4 +27,17 @@
<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-18 15:38:19 UTC (rev 121036)
+++ grokcore.view/branches/zca-only/src/grokcore/view/ftests/test_functional.py 2011-03-18 15:52:35 UTC (rev 121037)
@@ -7,9 +7,12 @@
import re
import types
import unittest
+import webob
import webob.dec
+import transaction
from cromlech.bootstrap.testlayer import ZODBLayer
+from cromlech.bootstrap.helper import Bootstrapper
from persistent.interfaces import IPersistent
from pkg_resources import resource_listdir
from zope.component import getMultiAdapter
@@ -19,13 +22,37 @@
from zope.publisher.publish import publish
from zope.site.interfaces import IRootFolder
from zope.site.folder import rootFolder
+from zope.interface import implements, Interface
+from zope.security.interfaces import IGroupAwarePrincipal
+from zope.security.testing import Participation
+from zope.security.management import newInteraction, endInteraction
+class IUnauthenticatedPrincipal(IGroupAwarePrincipal):
+ pass
+
+
+class UnauthenticatedPrincipal(object):
+ implements(IUnauthenticatedPrincipal)
+
+ def __init__(self, id, title, description):
+ self.id = id
+ self.title = title
+ self.description = description
+ self.groups = ["zope.Anybody"]
+
+
+unauthenticated_principal = UnauthenticatedPrincipal(
+ 'test.unauthenticated',
+ 'Unauthenticated principal',
+ 'The default unauthenticated principal.')
+
ROOT = 'grok'
@grokcore.component.implementer(IRootFolder)
@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()
@@ -34,6 +61,28 @@
return folder
+
+def getUser(wsgiapp, app, request):
+ request.setPrincipal(unauthenticated_principal)
+ return unauthenticated_principal
+
+
+class Interaction(object):
+
+ def __init__(self, user, request):
+
+
+ def __enter__(self):
+ participation = Participation(unauthenticated_principal)
+ newInteraction(participation)
+ return participation
+
+ def __exit__(self, type, value, traceback):
+ endInteraction()
+ if traceback is not None:
+ logger.warn(value)
+
+
class WSGIApplication(object):
def __init__(self, db):
@@ -42,20 +91,14 @@
@webob.dec.wsgify
def __call__(self, webob_req):
- # We want an interaction here
- # XXXX
-
- # We get a valid zope request
request = IRequest(webob_req)
- # Here, we keep the zope compatibility. It will go away
- request.setPublication(getMultiAdapter(
- (request, self.db), IPublication))
+ with Bootstrapper(self.db) as root, app:
+ with transaction:
+ user = setUser(self, app, request)
+ with Interaction(user) as participation:
+ response = publish(request, root=app, handle_errors=False)
- # publishing
- response = publish(request)
-
- # Return the WSGI server response
return response
@@ -107,6 +150,6 @@
def test_suite():
suite = unittest.TestSuite()
- for name in ['view', 'staticdir', 'url']:
+ for name in ['view', 'url']:
suite.addTest(suiteFromPackage(name))
return suite
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-18 15:38:19 UTC (rev 121036)
+++ grokcore.view/branches/zca-only/src/grokcore/view/ftests/url/redirect.py 2011-03-18 15:52:35 UTC (rev 121037)
@@ -1,25 +1,27 @@
"""
Views have a redirect() method to easily create redirects:
- >>> getRootFolder()['manfred'] = manfred = Mammoth()
+ >>> root = getRootFolder()
+ >>> root['manfred'] = manfred = Mammoth()
Since the index view redirects to mammoth, we expect to see the URL
point to mammoth:
- >>> from zope.app.wsgi.testlayer import Browser, http
- >>> browser = Browser()
- >>> browser.handleErrors = False
+ >>> from infrae.testbrowser.browser import Browser
+ >>> application = getApplication()
+ >>> browser = Browser(application)
+ >>> browser.options.handle_errors = False
+
>>> browser.open('http://localhost/manfred')
>>> browser.url
'http://localhost/manfred/another'
- >>> response = http('GET /manfred/trustedredirect HTTP/1.0')
- >>> response.getStatus()
+ >>> response = browser.open('http://localhost/manfred/trustedredirect')
+ >>> response.status_code
302
- >>> response.getHeader('location')
+ >>> response.location
'http://www.google.com/ncr'
-
>>> browser.open('http://localhost/manfred/redirectwithstatus')
Traceback (most recent call last):
...
Modified: grokcore.view/branches/zca-only/src/grokcore/view/ftests/url/url.py
===================================================================
--- grokcore.view/branches/zca-only/src/grokcore/view/ftests/url/url.py 2011-03-18 15:38:19 UTC (rev 121036)
+++ grokcore.view/branches/zca-only/src/grokcore/view/ftests/url/url.py 2011-03-18 15:52:35 UTC (rev 121037)
@@ -2,23 +2,28 @@
"""
Views have a method that can be used to construct URLs:
+ >>> root = getRootFolder()
>>> from zope.site.folder import Folder
>>> herd = Folder()
- >>> getRootFolder()['herd'] = herd
+ >>> root['herd'] = herd
>>> manfred = Mammoth()
>>> herd['manfred'] = manfred
The views in this test implement self.url():
- >>> from zope.app.wsgi.testlayer import Browser
- >>> browser = Browser()
- >>> browser.handleErrors = False
+ >>> from infrae.testbrowser.browser import Browser
+ >>> application = getApplication()
+ >>> browser = Browser(application)
+ >>> browser.options.handle_errors = False
+
>>> browser.open("http://localhost/herd/manfred/index")
>>> print browser.contents
http://localhost/herd/manfred/index
+
>>> browser.open("http://localhost/herd/manfred/another")
>>> print browser.contents
http://localhost/herd/manfred/another
+
>>> browser.open("http://localhost/herd/manfred/yetanother")
>>> print browser.contents
http://localhost/herd/manfred/yetanother
@@ -26,15 +31,20 @@
We get the views manually so we can do a greater variety of url() calls:
>>> from zope import component
- >>> from zope.publisher.browser import TestRequest
- >>> request = TestRequest()
+ >>> from webob import Request
+ >>> request = Request.blank('/')
+
>>> index_view = component.getMultiAdapter((manfred, request), name='index')
>>> index_view.url()
'http://127.0.0.1/herd/manfred/index'
+
+
>>> another_view = component.getMultiAdapter((manfred, request),
... name='another')
>>> another_view.url()
'http://127.0.0.1/herd/manfred/another'
+
+
>>> yet_another_view = component.getMultiAdapter((manfred, request),
... name='yetanother')
>>> yet_another_view.url()
Modified: grokcore.view/branches/zca-only/src/grokcore/view/ftests/url/url_function.py
===================================================================
--- grokcore.view/branches/zca-only/src/grokcore/view/ftests/url/url_function.py 2011-03-18 15:38:19 UTC (rev 121036)
+++ grokcore.view/branches/zca-only/src/grokcore/view/ftests/url/url_function.py 2011-03-18 15:52:35 UTC (rev 121037)
@@ -6,16 +6,20 @@
>>> from grokcore.view import url
>>> from zope.site.folder import Folder
+
+ >>> root = getRootFolder()
>>> herd = Folder()
- >>> getRootFolder()['herd'] = herd
+ >>> root['herd'] = herd
>>> manfred = Mammoth()
>>> herd['manfred'] = manfred
Now let's use url on some things::
- >>> from zope.app.wsgi.testlayer import Browser
- >>> browser = Browser()
- >>> browser.handleErrors = False
+ >>> from infrae.testbrowser.browser import Browser
+ >>> application = getApplication()
+ >>> browser = Browser(application)
+ >>> browser.options.handle_errors = False
+
>>> browser.open("http://localhost/herd/manfred/index")
>>> print browser.contents
http://localhost/herd/manfred/index
@@ -26,8 +30,8 @@
We get the views manually so we can do a greater variety of url() calls:
>>> from zope import component
- >>> from zope.publisher.browser import TestRequest
- >>> request = TestRequest()
+ >>> from webob import Request
+ >>> request = Request.blank('/')
>>> index_view = component.getMultiAdapter((manfred, request), name='index')
>>> url(request, index_view)
'http://127.0.0.1/herd/manfred/index'
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-18 15:38:19 UTC (rev 121036)
+++ grokcore.view/branches/zca-only/src/grokcore/view/ftests/view/macros.py 2011-03-18 15:52:35 UTC (rev 121037)
@@ -1,13 +1,13 @@
"""
>>> root = getRootFolder()
- >>> application = getApplication()
>>> root["manfred"] = Mammoth()
+ >>> application = getApplication()
>>> from infrae.testbrowser.browser import Browser
>>> browser = Browser(application)
>>> browser.options.handle_errors = False
- >>> browser("http://localhost/manfred/@@painting")
+ >>> browser.open("http://localhost/manfred/@@painting")
>>> print browser.contents
<html>
<body>
@@ -20,14 +20,14 @@
Views without a template do not support macros:
- >>> browser("http://localhost/manfred/@@dancing")
+ >>> 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("http://localhost/manfred/@@grilldish")
+ >>> browser.open("http://localhost/manfred/@@grilldish")
>>> print browser.contents
<html>
Curry
@@ -40,7 +40,7 @@
>>> saved_warn = warnings.warn
>>> warnings.warn = warn
- >>> browser("http://localhost/manfred/@@burnt")
+ >>> 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("http://localhost/manfred/@@painting")
+ >>> browser.open("http://localhost/manfred/@@painting")
>>> print browser.contents
<html>
<body>
Modified: grokcore.view/branches/zca-only/src/grokcore/view/ftests/view/macros_templates/layout.pt
===================================================================
--- grokcore.view/branches/zca-only/src/grokcore/view/ftests/view/macros_templates/layout.pt 2011-03-18 15:38:19 UTC (rev 121036)
+++ grokcore.view/branches/zca-only/src/grokcore/view/ftests/view/macros_templates/layout.pt 2011-03-18 15:52:35 UTC (rev 121037)
@@ -1,6 +1,6 @@
<html metal:define-macro="main">
<body>
-<h1>GROK MACRO!</h1>
+<h1>GROK RELOADED MACRO!</h1>
<div metal:define-slot="slot">
</div>
</body>
More information about the checkins
mailing list