Commit f12f5b49 authored by Hanno Schlichting's avatar Hanno Schlichting

Small cleanup

parent 79e9fa21
...@@ -16,27 +16,28 @@ ...@@ -16,27 +16,28 @@
Based on Plone's RestrictedPythonTestCase, with kind permission by the Based on Plone's RestrictedPythonTestCase, with kind permission by the
Plone developers. Plone developers.
""" """
from AccessControl import Unauthorized from AccessControl import Unauthorized
from Products.PythonScripts.PythonScript import manage_addPythonScript
def addPythonScript(folder, id, params='', body=''): def addPythonScript(folder, id, params='', body=''):
"""Add a PythonScript to folder.""" """Add a PythonScript to folder."""
# clean up any 'ps' that's already here.. # clean up any 'ps' that's already here..
try: if id in folder:
folder._getOb(id) del folder[id]
folder.manage_delObjects([id]) manage_addPythonScript(folder, id)
except AttributeError:
pass # it's okay, no 'ps' exists yet
factory = folder.manage_addProduct['PythonScripts']
factory.manage_addPythonScript(id)
folder[id].ZPythonScript_edit(params, body) folder[id].ZPythonScript_edit(params, body)
def checkRestricted(folder, psbody): def checkRestricted(folder, psbody):
"""Perform a check by running restricted Python code.""" """Perform a check by running restricted Python code."""
addPythonScript(folder, 'ps', body=psbody) addPythonScript(folder, 'ps', body=psbody)
try: try:
folder.ps() folder.ps()
except Unauthorized, e: except Unauthorized, e:
raise AssertionError, e raise AssertionError(e)
def checkUnauthorized(folder, psbody): def checkUnauthorized(folder, psbody):
"""Perform a check by running restricted Python code. Expect to """Perform a check by running restricted Python code. Expect to
...@@ -47,4 +48,4 @@ def checkUnauthorized(folder, psbody): ...@@ -47,4 +48,4 @@ def checkUnauthorized(folder, psbody):
except Unauthorized: except Unauthorized:
pass pass
else: else:
raise AssertionError, "Authorized but shouldn't be" raise AssertionError("Authorized but shouldn't be")
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