[Checkins] SVN: five.customerize/trunk/src/five/customerize/ Add
tests for TTW access of customerized view
Alec Mitchell
apm13 at columbia.edu
Sat Oct 28 20:14:14 EDT 2006
Log message for revision 70957:
Add tests for TTW access of customerized view
Changed:
A five.customerize/trunk/src/five/customerize/browser.txt
U five.customerize/trunk/src/five/customerize/configure.zcml
U five.customerize/trunk/src/five/customerize/tests.py
U five.customerize/trunk/src/five/customerize/zpt.py
U five.customerize/trunk/src/five/customerize/zpt.txt
-=-
Added: five.customerize/trunk/src/five/customerize/browser.txt
===================================================================
--- five.customerize/trunk/src/five/customerize/browser.txt 2006-10-28 23:20:50 UTC (rev 70956)
+++ five.customerize/trunk/src/five/customerize/browser.txt 2006-10-29 00:14:12 UTC (rev 70957)
@@ -0,0 +1,77 @@
+Viewing TTWTemplates TTW
+========================
+
+Set Up
+------
+
+ >>> import Products.Five
+ >>> import five.customerize
+ >>> from Products.Five.zcml import load_config
+ >>> load_config('configure.zcml', package=Products.Five)
+ >>> load_config('configure.zcml', package=five.customerize)
+
+Enable local component lookup hooks:
+
+ >>> from zope.app.component.hooks import setHooks
+ >>> setHooks()
+
+
+Making a site
+-------------
+
+ >>> uf = app.acl_users
+ >>> uf._doAddUser('manager', 'r00t', ['Manager'], [])
+
+Create the test browser we'll be using:
+
+ >>> from Products.Five.testbrowser import Browser
+ >>> browser = Browser()
+ >>> browser.addHeader('Authorization', 'Basic manager:r00t')
+
+Make a folder to use as a local site for component registration:
+
+ >>> browser.open('http://localhost/manage_addProduct/OFSP/folderAdd')
+ >>> browser.getControl(name='id').value = 'folder'
+ >>> browser.getControl('Add').click()
+ >>> browser.getLink('folder').click()
+
+We can turn it into a site by using the ``components.html`` view:
+
+ >>> browser.open('http://localhost/folder/components.html')
+ >>> browser.getControl('Make site').click()
+
+Create and a TTWTemplate instance as a view in our site manager:
+XXX: We should be able to do this TTW
+
+ >>> from zope.interface import Interface
+ >>> from OFS.interfaces import IObjectManager
+ >>> from zope.publisher.interfaces.browser import IDefaultBrowserLayer
+ >>> from five.customerize.zpt import TTWTemplate
+ >>> template = TTWTemplate('ttwtemplate', 'hello')
+ >>> t_id = app.folder._setObject('ttwtemplate', template)
+ >>> sm = app.folder.getSiteManager()
+ >>> sm.registerAdapter(template, (IObjectManager, IDefaultBrowserLayer),
+ ... Interface, name="myttwtemplate.html")
+ >>> import transaction
+ >>> transaction.commit()
+
+Let's see if we can view it
+
+ >>> browser.handleErrors = False
+ >>> browser.open('http://localhost/folder/myttwtemplate.html')
+ >>> print browser.contents
+ hello
+
+Now we edit our view template TTW:
+
+ >>> browser.open('http://localhost/folder/ttwtemplate/pt_editForm')
+ >>> browser.getControl(name='text:text').value = '''\
+ ... <span tal:replace="context/getId"/>
+ ... <span tal:replace="request/foo"/>
+ ... <span tal:replace="python:repr(view)"/>'''
+ >>> browser.getControl('Save Changes').click()
+ >>> browser.open('http://localhost/folder/myttwtemplate.html?foo=bar')
+ >>> print browser.contents
+ folder
+ bar
+ None
Modified: five.customerize/trunk/src/five/customerize/configure.zcml
===================================================================
--- five.customerize/trunk/src/five/customerize/configure.zcml 2006-10-28 23:20:50 UTC (rev 70956)
+++ five.customerize/trunk/src/five/customerize/configure.zcml 2006-10-29 00:14:12 UTC (rev 70957)
@@ -1,4 +1,14 @@
<configure xmlns="http://namespaces.zope.org/zope"
- xmlns:five="http://namespaces.zope.org/five">
+ xmlns:five="http://namespaces.zope.org/five"
+ i18n_domain="five.customerize">
+ <permission id="five.AddTTWTemplate"
+ title="Five: Add TTW Template"
+ />
+
+ <five:registerClass class=".zpt.TTWTemplate"
+ meta_type="TTW Template"
+ permission="five.AddTTWTemplate"
+ />
+
</configure>
\ No newline at end of file
Modified: five.customerize/trunk/src/five/customerize/tests.py
===================================================================
--- five.customerize/trunk/src/five/customerize/tests.py 2006-10-28 23:20:50 UTC (rev 70956)
+++ five.customerize/trunk/src/five/customerize/tests.py 2006-10-29 00:14:12 UTC (rev 70957)
@@ -1,5 +1,6 @@
import unittest
from Testing.ZopeTestCase import ZopeDocFileSuite
+from Testing.ZopeTestCase import FunctionalDocFileSuite
from zope.traversing.adapters import DefaultTraversable
import zope.component.testing
@@ -13,6 +14,7 @@
return unittest.TestSuite([
ZopeDocFileSuite('zpt.txt', package="five.customerize",
setUp=setUp, tearDown=zope.component.testing.tearDown),
+ FunctionalDocFileSuite('browser.txt', package="five.customerize")
])
if __name__ == '__main__':
Modified: five.customerize/trunk/src/five/customerize/zpt.py
===================================================================
--- five.customerize/trunk/src/five/customerize/zpt.py 2006-10-28 23:20:50 UTC (rev 70956)
+++ five.customerize/trunk/src/five/customerize/zpt.py 2006-10-29 00:14:12 UTC (rev 70957)
@@ -31,7 +31,8 @@
bound_names = {'view': view,
'request': self.request,
'context': self.context}
- return self.template._exec(bound_names, args, kwargs)
+ template = self.template.__of__(self.context)
+ return template._exec(bound_names, args, kwargs)
def __of__(self, obj):
return self
Modified: five.customerize/trunk/src/five/customerize/zpt.txt
===================================================================
--- five.customerize/trunk/src/five/customerize/zpt.txt 2006-10-28 23:20:50 UTC (rev 70956)
+++ five.customerize/trunk/src/five/customerize/zpt.txt 2006-10-29 00:14:12 UTC (rev 70957)
@@ -7,11 +7,11 @@
>>> from five.customerize.zpt import TTWTemplate
>>> template = TTWTemplate('test_template', '<html></html>')
>>> template = template.__of__(app)
- >>> renderer = template(None, None)
+ >>> renderer = template(self.folder, None)
>>> print renderer()
<html></html>
-We now add some more complex tal expressions to our template, and
+We now add some more complex TAL expressions to our template, and
ensure that it obtains the passed in request and context for rendering:
>>> template.pt_edit('''\
@@ -24,3 +24,4 @@
test_folder_1_
bar
None
+
More information about the Checkins
mailing list