Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
41e02756
Commit
41e02756
authored
Mar 15, 2007
by
Stefan H. Holek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merged r73183:73184 from 2.10 branch.
Use a decorator to save and restore thread-local state.
parent
76c7ed48
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
35 deletions
+22
-35
lib/python/Testing/ZopeTestCase/functional.py
lib/python/Testing/ZopeTestCase/functional.py
+20
-17
lib/python/Testing/ZopeTestCase/zopedoctest/functional.py
lib/python/Testing/ZopeTestCase/zopedoctest/functional.py
+2
-18
No files found.
lib/python/Testing/ZopeTestCase/functional.py
View file @
41e02756
...
...
@@ -25,6 +25,25 @@ import interfaces
from
zope.interface
import
implements
def
savestate
(
func
):
'''Decorator saving thread local state before executing func
and restoring it afterwards.
'''
from
AccessControl.SecurityManagement
import
getSecurityManager
from
AccessControl.SecurityManagement
import
setSecurityManager
from
zope.app.component.hooks
import
getSite
from
zope.app.component.hooks
import
setSite
def
wrapped_func
(
*
args
,
**
kw
):
sm
,
site
=
getSecurityManager
(),
getSite
()
try
:
return
func
(
*
args
,
**
kw
)
finally
:
setSecurityManager
(
sm
)
setSite
(
site
)
return
wrapped_func
class
Functional
(
sandbox
.
Sandboxed
):
'''Derive from this class and an xTestCase to get functional
testing support::
...
...
@@ -35,25 +54,15 @@ class Functional(sandbox.Sandboxed):
implements
(
interfaces
.
IFunctional
)
@
savestate
def
publish
(
self
,
path
,
basic
=
None
,
env
=
None
,
extra
=
None
,
request_method
=
'GET'
,
stdin
=
None
,
handle_errors
=
True
):
'''Publishes the object at 'path' returning a response object.'''
from
zope.app.component.hooks
import
setSite
,
getSite
from
StringIO
import
StringIO
from
ZPublisher.Response
import
Response
from
ZPublisher.Test
import
publish_module
from
AccessControl.SecurityManagement
import
getSecurityManager
from
AccessControl.SecurityManagement
import
setSecurityManager
# Save current security manager
sm
=
getSecurityManager
()
# And we need to store the old site
old_site
=
getSite
()
setSite
(
None
)
# Commit the sandbox for good measure
transaction
.
commit
()
...
...
@@ -93,12 +102,6 @@ class Functional(sandbox.Sandboxed):
debug
=
not
handle_errors
,
)
# Restore security manager
setSecurityManager
(
sm
)
# And we need to restore the site again
setSite
(
old_site
)
return
ResponseWrapper
(
response
,
outstream
,
path
)
...
...
lib/python/Testing/ZopeTestCase/zopedoctest/functional.py
View file @
41e02756
...
...
@@ -31,6 +31,7 @@ from Testing.ZopeTestCase import user_role
from
Testing.ZopeTestCase
import
standard_permissions
from
Testing.ZopeTestCase.sandbox
import
AppZapper
from
Testing.ZopeTestCase.functional
import
ResponseWrapper
from
Testing.ZopeTestCase.functional
import
savestate
class
HTTPHeaderOutput
:
...
...
@@ -110,6 +111,7 @@ def sync():
getRootFolder()._p_jar.sync()
@savestate
def http(request_string, handle_errors=True):
"""Execute an HTTP request string via the publisher
...
...
@@ -117,19 +119,9 @@ def http(request_string, handle_errors=True):
"""
import urllib
import rfc822
from zope.app.component.hooks import setSite, getSite
from cStringIO import StringIO
from ZPublisher.Response import Response
from ZPublisher.Test import publish_module
from AccessControl.SecurityManagement import getSecurityManager
from AccessControl.SecurityManagement import setSecurityManager
# Save current Security Manager
old_sm = getSecurityManager()
# And we need to store the old site
old_site = getSite()
setSite(None)
# Commit work done by previous python code.
transaction.commit()
...
...
@@ -194,14 +186,6 @@ def http(request_string, handle_errors=True):
header_output.appendResponseHeaders(response._cookie_list())
header_output.appendResponseHeaders(response.accumulated_headers.splitlines())
# Restore previous security manager, which may have been changed
# by calling the publish method above
setSecurityManager(old_sm)
# And we need to restore the site again
setSite(old_site)
# Sync connection
sync()
return DocResponseWrapper(response, outstream, path, header_output)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment