def get_plone_site(): import Zope2 app = Zope2.app() from Testing.ZopeTestCase import utils utils._Z2HOST = HOST path = PLONE.split('/') app = utils.makerequest(app) app.REQUEST['PARENTS'] = [app] app.REQUEST.other['VirtualRootPhysicalPath'] = path from zope.globalrequest import setRequest setRequest(app.REQUEST) from AccessControl.SpecialUsers import system as user from AccessControl.SecurityManagement import newSecurityManager newSecurityManager(None, user) _site = app[path[-1]] site = _site.__of__(app) from zope.site.hooks import setSite setSite(site) return site
def get_plone_site(PLONE): import Zope2 app = Zope2.app() from Testing.ZopeTestCase import utils utils._Z2HOST = HOST path = PLONE.split('/') app = utils.makerequest(app) app.REQUEST['PARENTS'] = [app] app.REQUEST.other['VirtualRootPhysicalPath'] = path from zope.globalrequest import setRequest setRequest(app.REQUEST) from AccessControl.SpecialUsers import system as user from AccessControl.SecurityManagement import newSecurityManager newSecurityManager(None, user) _site = app[path[-1]] site = _site.__of__(app) from zope.site.hooks import setSite setSite(site) return site
def getPortal(self): """Returns the portal object, i.e. the "fixture root". Rewrap the portal in an independant request for this test. """ if self.portal is not None: return self.portal from Products.ERP5.ERP5Site import getSite site = getSite() # reconstruct the acquistion chain with an independant request. # RequestContainer -> Application -> Site from Testing.ZopeTestCase.utils import makerequest portal = getattr(makerequest(site.aq_parent), site.getId()) # Make the various get_request patches return this request. # This is for ERP5TypeTestCase patch from Testing.ZopeTestCase.connections import registry if registry: registry._conns[-1] = portal # This is for Localizer patch from Products.Localizer import patches request = portal.REQUEST with patches._requests_lock: patches._requests[thread.get_ident()] = request # Make live tests run under the same server URL than the host instance. if _request_server_url: request['SERVER_URL'] = _request_server_url request._resetURLS() self.portal = portal return portal
def run_it(module): cwd = os.getcwd() conf_path = None lookup_paths = [ '/opt/plone/parts/client1/etc/zope.conf', os.path.join(cwd, 'parts/instance/etc/zope.conf'), os.path.join(cwd, 'parts/client1/etc/zope.conf'), ] for path in lookup_paths: if os.path.exists(path): conf_path = path break if conf_path is None: raise Exception('Could not find zope.conf in {}'.format(lookup_paths)) from Zope2 import configure configure(conf_path) import Zope2 app = Zope2.app() from Testing.ZopeTestCase.utils import makerequest app = makerequest(app) app.REQUEST['PARENTS'] = [app] from zope.globalrequest import setRequest setRequest(app.REQUEST) from AccessControl.SpecialUsers import system as user from AccessControl.SecurityManagement import newSecurityManager newSecurityManager(None, user) from zope.dottedname.resolve import resolve mod = resolve('castle.cms.cron.' + module) mod.run(app)
def afterSetUp(self): from plone.app.z3cform.interfaces import IPloneFormLayer from plone.z3cform.z2 import switch_on self.form = self.folder[self.folder.invokeFactory('FormFolder', 'form')] self.request = makerequest(self.app).REQUEST self.request.SESSION = Session() self.wizard = DummyWizard(self.form, self.request) switch_on(self.wizard, request_layer=IPloneFormLayer) self.session = self.request.SESSION[self.wizard.sessionKey] = {} self.step = SignersStep(self.form, self.request, self.wizard)
def get_zope_site(): import Zope2 app = Zope2.app() from Testing.ZopeTestCase import utils utils._Z2HOST = HOST app = utils.makerequest(app) app.REQUEST['PARENTS'] = [app] from zope.globalrequest import setRequest setRequest(app.REQUEST) from AccessControl.SpecialUsers import system as user from AccessControl.SecurityManagement import newSecurityManager newSecurityManager(None, user) # We need the AUTHENTICATED_USER in the REQUEST for manage_as_owner decorator app.REQUEST['AUTHENTICATED_USER'] = user return app
def run_it(module): from Zope2 import configure configure('/opt/plone/parts/client1/etc/zope.conf') import Zope2 app = Zope2.app() from Testing.ZopeTestCase.utils import makerequest app = makerequest(app) app.REQUEST['PARENTS'] = [app] from zope.globalrequest import setRequest setRequest(app.REQUEST) from AccessControl.SpecialUsers import system as user from AccessControl.SecurityManagement import newSecurityManager newSecurityManager(None, user) from zope.dottedname.resolve import resolve mod = resolve('castle.cms.cron.' + module) mod.run(app)
def setup_and_run(): conf_path = os.getenv("ZOPE_CONF_PATH", "parts/instance/zope.conf") if conf_path is None or not os.path.exists(conf_path): raise Exception('Could not find zope.conf at {}'.format(conf_path)) from Zope2 import configure configure(conf_path) import Zope2 app = Zope2.app() from Testing.ZopeTestCase.utils import makerequest app = makerequest(app) app.REQUEST['PARENTS'] = [app] from zope.globalrequest import setRequest setRequest(app.REQUEST) from AccessControl.SpecialUsers import system as user from AccessControl.SecurityManagement import newSecurityManager newSecurityManager(None, user) run(app)
def getPortal(self): """Returns the portal object, i.e. the "fixture root". Rewrap the portal in an independant request for this test. """ if self.portal is not None: return self.portal # _module_cache_set is used to keep a reference to the code of modules # before they get reloaded. As we will use another request we need to # make sure that we still have a reference to _module_cache_set so that # it does not get garbage collected. module_cache_set = getattr(get_request(), '_module_cache_set', None) from Products.ERP5.ERP5Site import getSite site = getSite() # reconstruct the acquistion chain with an independant request. # RequestContainer -> Application -> Site from Testing.ZopeTestCase.utils import makerequest portal = getattr(makerequest(site.aq_parent), site.getId()) if module_cache_set: portal.REQUEST._module_cache_set = module_cache_set # Make the various get_request patches return this request. # This is for ERP5TypeTestCase patch from Testing.ZopeTestCase.connections import registry if registry: registry._conns[-1] = portal # This is for Localizer patch from Products.Localizer import patches request = portal.REQUEST with patches._requests_lock: patches._requests[thread.get_ident()] = request # Make live tests run under the same server URL than the host instance. if _request_server_url: request['SERVER_URL'] = _request_server_url request._resetURLS() self.portal = portal return portal
##### end of config from AccessControl.SecurityManagement import newSecurityManager import sys try: site_id = sys.argv[1] except IndexError: site_id = SITE_ID try: input_path = sys.argv[2] except IndexError: input_path = DATA_SOURCE_FILE # ugly hack to satisfy the translation service from Testing.ZopeTestCase.utils import makerequest app = makerequest(app) data = open(input_path, 'r') site = app[site_id] registration_tool = site.portal_registration membership_tool = site.portal_membership print "Adding members from '%s'." % input_path for line in data.readlines(): # ignore empty lines and comments if not line.strip() or line.startswith('#'): continue try: id, fullname, email = line.split(',') except ValueError, message: print "Cannot parse line '%s'; ignoring it." % line.strip()