def test_execute(self): from Acquisition import Implicit from Testing.makerequest import makerequest from plone.app.z3cform.csrf import AuthenticatedButtonActions from plone.protect import createToken class DummyForm(object): enableCSRFProtection = True class DummyAction(object): def isExecuted(self): return True def execute(self): self.called = True form = DummyForm() request = makerequest(Implicit()).REQUEST request.form['_authenticator'] = createToken() actions = AuthenticatedButtonActions(form, request, None) actions._data['foo'] = action = DummyAction() actions._data_keys = ['foo'] actions._data_values = [action] actions.execute()
def test_makerequest(self): # The argument must support acquisition. self.assertRaises(AttributeError, makerequest, object()) # After the call, it will have a REQUEST attribute. item = Implicit() self.assertFalse(hasattr(item, 'REQUEST')) item = makerequest(item) self.assertTrue(hasattr(item, 'REQUEST'))
def __init__(self, namespace): self.namespace = namespace Implicit.__init__(self)
def __getattr__(self, name): try: return getattr(self._organization, name) except AttributeError: return Implicit.__getattr__(self, name)