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