def __init__(self): self.instancehome = os.environ.get("INSTANCE_HOME") configfile = os.environ.get("CONFIG_FILE") if configfile is None and self.instancehome is not None: configfile = os.path.join(self.instancehome, "etc", "zope.conf") if configfile is None: raise RuntimeError("CONFIG_FILE env not set") print "CONFIG_FILE=", configfile print "INSTANCE_HOME=", self.instancehome self.configfile = configfile try: from Zope2 import configure except ImportError: from Zope import configure configure(configfile) try: import Zope2 app = Zope2.app() except ImportError: import Zope app = Zope.app() from Testing.makerequest import makerequest self.app = makerequest(app) try: self._make_permissive() print "Permissive security installed" except: print "Permissive security NOT installed" self._pwd = self.portal or self.app try: from zope.component import getSiteManager from zope.component import getGlobalSiteManager try: from zope.app.component.hooks import setSite except ImportError: from zope.component.hooks import setSite if self.portal is not None: setSite(self.portal) gsm = getGlobalSiteManager() sm = getSiteManager() if sm is gsm: print "ERROR SETTING SITE!" except: # XXX: What exceptions is this supposed to catch? pass
def __init__(self): self.instancehome = os.environ.get("INSTANCE_HOME") configfile = os.environ.get("CONFIG_FILE") if configfile is None and self.instancehome is not None: configfile = os.path.join(self.instancehome, "etc", "zope.conf") if configfile is None: raise RuntimeError("CONFIG_FILE env not set") print "CONFIG_FILE=", configfile print "INSTANCE_HOME=", self.instancehome self.configfile = configfile try: from Zope2 import configure except ImportError: from Zope import configure configure(configfile) try: import Zope2 app = Zope2.app() except ImportError: import Zope app = Zope.app() from Testing.makerequest import makerequest self.app = makerequest(app) try: self._make_permissive() print "Permissive security installed" except: print "Permissive security NOT installed" self._pwd = self.portal or self.app try: from zope.component import getSiteManager from zope.component import getGlobalSiteManager from zope.app.component.hooks import setSite if self.portal is not None: setSite(self.portal) gsm = getGlobalSiteManager() sm = getSiteManager() if sm is gsm: print "ERROR SETTING SITE!" except: pass
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 process(): """Read in zope.conf configuration file. This is a hack but there doesn't seem to be a better way. """ _prefix = os.environ.get('INSTANCE_HOME') if not _prefix: try: __file__ except NameError: # Test was called directly, so no __file__ global exists. _prefix = abspath(os.curdir) else: # Test was called by another test. _prefix = abspath(dirname(__file__)) _prefix = join(_prefix, '..', '..', '..') _config = join(_prefix, 'etc', 'zope.conf') if exists(_config): from Zope2 import configure configure(_config)
try: os.mkdir(TEMPNAME) os.mkdir(TEMPPRODUCTS) except OSError, why: if why == errno.EEXIST: # already exists pass old_argv = sys.argv sys.argv = [sys.argv[0]] try: fname = os.path.join(TEMPNAME, 'zope.conf') from Zope2 import configure f = open(fname, 'w') f.write('instancehome %s\nzserver-threads 100\n' % TEMPNAME) f.flush() f.close() configure(fname) new_config = getConfiguration() self.assertEqual(new_config.zserver_threads, 100) finally: sys.argv = old_argv try: os.unlink(fname) except: pass setConfiguration(old_config) def test_suite(): return unittest.makeSuite(ZopeStarterTestCase)