def testZopeRunConfigure(self): old_config = getConfiguration() try: os.mkdir(TEMPNAME) os.mkdir(TEMPPRODUCTS) except OSError as 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 ZServer.Zope2.Startup.run 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 Exception: pass setConfiguration(old_config)
def init_config(self): config = getConfiguration() if not hasattr(config, 'product_config'): config.product_config = {} config.product_config['expired-users'] = self.expired_users_config() setConfiguration(config)
def init_config(self, dsn): config = getConfiguration() if not hasattr(config, 'product_config'): config.product_config = {} config.product_config['seantis.reservation'] = dict(dsn=dsn) setConfiguration(config)
def configure(self, text): # We have to create a directory of our own since the existence # of the directory is checked. This handles this in a # platform-independent way. schema = self.schema sio = cStringIO.StringIO(text.replace("<<INSTANCE_HOME>>", TEMPNAME)) conf, handler = ZConfig.loadConfigFile(schema, sio) self.assertEqual(conf.instancehome, TEMPNAME) setConfiguration(conf)
def load_config_text_and_start_servers(self, zope_conf_text): from App.config import setConfiguration self.zope_conf = self.load_config_text(zope_conf_text) starter = self.get_starter(self.zope_conf) setConfiguration(self.zope_conf) # do the job the 'handler' would have done (call prepare) for server in self.zope_conf.servers: server.prepare('', None, 'Zope2', {}, None) starter.setupServers() return self.zope_conf
def zetup(configfile_name): from Zope.Startup.options import ZopeOptions from Zope.Startup import handlers as h from App import config opts = ZopeOptions() opts.configfile = configfile_name opts.realize(args=[]) h.handleConfig(opts.configroot, opts.confighandlers) config.setConfiguration(opts.configroot) from Zope.Startup import dropPrivileges dropPrivileges(opts.configroot)
def test_in_debug_mode(self): cfg = getConfiguration() cfg.debug_mode = False setConfiguration(cfg) self.assertFalse(tools.in_debug_mode()) cfg.debug_mode = True setConfiguration(cfg) self.assertTrue(tools.in_debug_mode())
def configure(self, text): # We have to create a directory of our own since the existence # of the directory is checked. This handles this in a # platform-independent way. config_path = os.path.join(TEMPNAME, 'zope.conf') with open(config_path, 'w') as fd: fd.write(text.replace(u"<<INSTANCE_HOME>>", TEMPNAME)) options = ZopeWSGIOptions(config_path)() config = options.configroot self.assertEqual(config.instancehome, TEMPNAME) setConfiguration(config)
def configure(self, config): # We have to create a directory of our own since the existence # of the directory is checked. This handles this in a # platform-independent way. config_path = os.path.join(self.TEMPDIR, 'zope.conf') with open(config_path, 'w') as fd: fd.write(config.format(instance_home=self.TEMPDIR)) options = ZopeWSGIOptions(config_path)() config = options.configroot self.assertEqual(config.instancehome, self.TEMPDIR) setConfiguration(config)
def configure(self, text): # We have to create a directory of our own since the existence # of the directory is checked. This handles this in a # platform-independent way. schema = self.schema text = text.replace("<<INSTANCE_HOME>>", TEMPNAME) text = text.replace("<<PRODUCTS>>", TEMPPRODUCTS) text = text.replace("<<PRODUCTS2>>", TEMPPRODUCTS2) sio = cStringIO.StringIO(text) conf, handler = ZConfig.loadConfigFile(schema, sio) from Zope2.Startup.handlers import handleConfig handleConfig(conf, handler) self.assertEqual(conf.instancehome, TEMPNAME) setConfiguration(conf)
def make_wsgi_app(global_config, zope_conf): from App.config import setConfiguration from Zope2.Startup import get_starter from Zope2.Startup.handlers import handleConfig from Zope2.Startup.options import ZopeOptions from ZPublisher.WSGIPublisher import publish_module starter = get_starter() opts = ZopeOptions() opts.configfile = zope_conf opts.realize(args=(), progname='Zope2WSGI', raise_getopt_errs=False) handleConfig(opts.configroot, opts.confighandlers) setConfiguration(opts.configroot) starter.setConfiguration(opts.configroot) starter.prepare() return publish_module
def make_wsgi_app(global_config, zope_conf): from App.config import setConfiguration from Zope2.Startup import get_wsgi_starter from Zope2.Startup.handlers import handleWSGIConfig from Zope2.Startup.options import ZopeWSGIOptions from ZPublisher.WSGIPublisher import publish_module starter = get_wsgi_starter() opts = ZopeWSGIOptions(configfile=zope_conf)() if 'debug_mode' in global_config: if global_config['debug_mode'] in ('true', 'on', '1'): opts.configroot.debug_mode = True handleWSGIConfig(opts.configroot, opts.confighandlers) setConfiguration(opts.configroot) starter.setConfiguration(opts.configroot) starter.prepare() return publish_module
def setUpZope(self, app, configurationContext): # Set product configuration cfg = getConfiguration() cfg.product_config = { 'collective.gitresource': { os.environ.get('ZSERVER_HOST', 'localhost:'): '{0:s}:{1:s}'.format(SITE_OWNER_NAME, SITE_OWNER_PASSWORD) } } if HAS_REDIS: cfg.product_config['collective.gitresource'].update({ 'redis.host': 'localhost', 'redis.port': '6379', 'redis.db': '0' }) setConfiguration(cfg) import plone.app.theming self.loadZCML(package=plone.app.theming) import collective.gitresource self.loadZCML(package=collective.gitresource)
def tearDown(self): setConfiguration(self.stored_app_config) shutil.rmtree(self.instancedir)
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)
def tearDown(self): setConfiguration(self.original_config) shutil.rmtree(self.TEMPDIR) Products.__path__ = [d for d in Products.__path__ if os.path.exists(d)]