Commit 12042f18 authored by Tres Seaver's avatar Tres Seaver

Fix DTML bindings to work with 'zope.publisher' 4.x.

'zope.publisher.publish.unwrapMethod' was not recognizing the faux-callable
nature of DTMLMethod.  Add a '__code__' attr to help it find us.

Neaten / normalize functest scaffolding.
parent 18b98b1c
......@@ -64,7 +64,7 @@ class DTMLMethod(RestrictedDTML,
# Documents masquerade as functions:
class func_code:
pass
func_code = func_code()
func_code = __code__ = func_code()
func_code.co_varnames = 'self', 'REQUEST', 'RESPONSE'
func_code.co_argcount = 3
......
......@@ -30,6 +30,14 @@ from DocumentTemplate.permissions import change_dtml_documents
from StringIO import StringIO
from urllib import urlencode
REDIRECT_DTML = '''\
<dtml-call "RESPONSE.redirect('%s')">'''
SET_COOKIE_DTML = '''\
<dtml-call "RESPONSE.setCookie('foo', 'Bar', path='/')">'''
CHANGE_TITLE_DTML = '''\
<dtml-call "manage_changeProperties(title=REQUEST.get('title'))">'''
class TestFunctional(ZopeTestCase.FunctionalTestCase):
......@@ -45,16 +53,14 @@ class TestFunctional(ZopeTestCase.FunctionalTestCase):
self.folder.secret_html.manage_permission(view, ['Owner'])
# A method redirecting to the Zope root
redirect = '''<dtml-call "RESPONSE.redirect('%s')">''' % self.app.absolute_url()
self.folder.addDTMLMethod('redirect', file=redirect)
self.folder.addDTMLMethod(
'redirect', file=REDIRECT_DTML % self.app.absolute_url())
# A method setting a cookie
set_cookie = '''<dtml-call "RESPONSE.setCookie('foo', 'Bar', path='/')">'''
self.folder.addDTMLMethod('set_cookie', file=set_cookie)
self.folder.addDTMLMethod('set_cookie', file=SET_COOKIE_DTML)
# A method changing the title property of an object
change_title = '''<dtml-call "manage_changeProperties(title=REQUEST.get('title'))">'''
self.folder.addDTMLMethod('change_title', file=change_title)
self.folder.addDTMLMethod('change_title', file=CHANGE_TITLE_DTML)
def testPublishFolder(self):
response = self.publish(self.folder_path)
......@@ -71,14 +77,16 @@ class TestFunctional(ZopeTestCase.FunctionalTestCase):
self.assertEqual(response.getStatus(), 401)
def testBasicAuth(self):
response = self.publish(self.folder_path+'/secret_html', self.basic_auth)
response = self.publish(self.folder_path+'/secret_html',
self.basic_auth)
self.assertEqual(response.getStatus(), 200)
self.assertEqual(response.getBody(), 'secret')
def testRedirect(self):
response = self.publish(self.folder_path+'/redirect')
self.assertEqual(response.getStatus(), 302)
self.assertEqual(response.getHeader('Location'), self.app.absolute_url())
self.assertEqual(response.getHeader('Location'),
self.app.absolute_url())
def testCookie(self):
response = self.publish(self.folder_path+'/set_cookie')
......@@ -90,9 +98,9 @@ class TestFunctional(ZopeTestCase.FunctionalTestCase):
# Change the title of a document
self.setPermissions([manage_properties])
path = self.folder_path + '/index_html/change_title?title=Foo'
# Note that we must pass basic auth info
response = self.publish(self.folder_path+'/index_html/change_title?title=Foo',
self.basic_auth)
response = self.publish(path, self.basic_auth)
self.assertEqual(response.getStatus(), 200)
self.assertEqual(self.folder.index_html.title_or_id(), 'Foo')
......@@ -179,4 +187,3 @@ def test_suite():
suite = TestSuite()
suite.addTest(makeSuite(TestFunctional))
return suite
......@@ -138,7 +138,7 @@ Test setting cookies
HTTP/1.1 200 OK
Content-Length: 0
...
Set-Cookie: cookie_test="OK"
Set-Cookie: foo="Bar"; Path=/
<BLANKLINE>
Test reading cookies
......
......@@ -88,6 +88,10 @@ class HTTPHeaderOutputTests(unittest.TestCase):
'Content-Type: text/html'
)
SHOW_COOKIES_DTML = '''\
<dtml-in "REQUEST.cookies.keys()">
<dtml-var sequence-item>: <dtml-var "REQUEST.cookies[_['sequence-item']]">
</dtml-in>'''
def setUp(self):
'''This method will run after the test_class' setUp.
......@@ -104,18 +108,16 @@ def setUp(self):
>>> foo
1
'''
from Testing.ZopeTestCase.testFunctional import CHANGE_TITLE_DTML
from Testing.ZopeTestCase.testFunctional import SET_COOKIE_DTML
self.folder.addDTMLDocument('index_html', file='index')
change_title = '''<dtml-call "manage_changeProperties(title=REQUEST.get('title'))">'''
self.folder.addDTMLMethod('change_title', file=change_title)
self.folder.addDTMLMethod('change_title', file=CHANGE_TITLE_DTML)
set_cookie = '''<dtml-call "REQUEST.RESPONSE.setCookie('cookie_test', 'OK')">'''
self.folder.addDTMLMethod('set_cookie', file=set_cookie)
self.folder.addDTMLMethod('set_cookie', file=SET_COOKIE_DTML)
show_cookies = '''<dtml-in "REQUEST.cookies.keys()">
<dtml-var sequence-item>: <dtml-var "REQUEST.cookies[_['sequence-item']]">
</dtml-in>'''
self.folder.addDTMLMethod('show_cookies', file=show_cookies)
self.folder.addDTMLMethod('show_cookies', file=SHOW_COOKIES_DTML)
self.globs['foo'] = 1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment