def make_app(controller_klass=None, environ=None, config_options=None, with_errors=False): """Creates a `TestApp` instance.""" if controller_klass is None: controller_klass = TGController tg.config['renderers'] = default_config['renderers'] tg.config['rendering_engines_options'] = default_config['rendering_engines_options'] config = default_config.copy() config['application_wrappers'] = [ I18NApplicationWrapper, IdentityApplicationWrapper, CacheApplicationWrapper, SessionApplicationWrapper ] if with_errors: config['errorpage.enabled'] = True config['errorpage.status_codes'] = [403, 404] config['application_wrappers'].append(ErrorPageApplicationWrapper) config['session.enabled'] = True config['session.data_dir'] = session_dir config['cache.enabled'] = True config['cache.cache_dir'] = cache_dir if config_options is not None: config.update(config_options) app = TGApp(config=config) app.controller_classes['root'] = ControllerWrap(controller_klass) app = FakeRoutes(app) app = RegistryManager(app) return TestApp(app)
def test_application_test_mode_detection(self): class FakeRegistry(object): def register(self, *args, **kw): pass a = TGApp() assert False == a.setup_app_env({'paste.registry':FakeRegistry()}, None) assert True == a.setup_app_env({'paste.registry':FakeRegistry(), 'paste.testing_variables':{}}, None)
def make_app(controller_klass, environ={}, with_errors=False): """Creates a ``TestApp`` instance.""" # The basic middleware: app = TGApp(config=default_config) app.controller_classes['root'] = ControllerWrap(controller_klass) app = FakeRoutes(app) if with_errors: app = ErrorHandler(app, {}, debug=False) app = StatusCodeRedirect(app, [403, 404, 500]) app = RegistryManager(app) app = SessionMiddleware(app, {}, data_dir=session_dir) app = CacheMiddleware(app, {}, data_dir=os.path.join(data_dir, 'cache')) # Setting repoze.who up: from repoze.who.plugins.auth_tkt import AuthTktCookiePlugin cookie = AuthTktCookiePlugin('secret', 'authtkt') identifiers = [('cookie', cookie)] app = setup_auth(app, TGAuthMetadata(), identifiers=identifiers, skip_authentication=True, authenticators=[], challengers=[]) return TestApp(app)
def _resolve_mountpoint(self, app_id): tgapp = self.tgapp if tgapp is None: tgapp = TGApp() root = tgapp.find_controller('root') try: route, name = app_id.rsplit('.', 1) mountpoint = attrgetter(route)(root).__class__ except ValueError: mountpoint, name = root, app_id return mountpoint, name
def make_app(controller_klass, environ={}, with_errors=False): """Creates a ``TestApp`` instance.""" # The basic middleware: app = TGApp(config=default_config) app.controller_classes['root'] = ControllerWrap(controller_klass) app = FakeRoutes(app) if with_errors: app = ErrorHandler(app, {}, debug=False) app = StatusCodeRedirect(app, [403, 404, 500]) app = RegistryManager(app) app = SessionMiddleware(app, {}, data_dir=session_dir) app = CacheMiddleware(app, {}, data_dir=os.path.join(data_dir, 'cache')) # Setting repoze.who up: from repoze.who.plugins.auth_tkt import AuthTktCookiePlugin cookie = AuthTktCookiePlugin('secret', 'authtkt') identifiers = [('cookie', cookie)] app = setup_auth(app, TestAuthMetadata(), identifiers=identifiers, skip_authentication=True, authenticators=[], challengers=[]) # As setup_auth with skip_authentication sets empty authenticators always # we must manually append it after creating the middleware. app.api_factory.authenticators.append(('cookie', cookie)) return TestApp(app)
def test_application_test_mode_detection(self): class FakeRegistry(object): def register(self, *args, **kw): pass a = TGApp() testmode, __ = a.setup_app_env({'paste.registry': FakeRegistry()}) assert testmode is False testmode, __ = a.setup_app_env({ 'paste.registry': FakeRegistry(), 'paste.testing_variables': {} }) assert testmode is True
def mount_controllers(self, app): root_controller = TGApp().find_controller('root') app_id = self.options['appid'] setattr(root_controller, app_id, self.controllers.RootController()) return app
def test_enable_routes(self): if PY3: raise SkipTest() conf = AppConfig(minimal=True) conf.enable_routes = True app = conf.make_wsgi_app() a = TGApp() assert a.enable_routes == True config.pop('routes.map') config.pop('enable_routes')
def make_app(controller_klass=None, environ=None): """Creates a `TestApp` instance.""" if controller_klass is None: controller_klass = TGController tg.config['renderers'] = default_config['renderers'] app = TGApp(config=default_config) app.controller_classes['root'] = ControllerWrap(controller_klass) app = FakeRoutes(app) app = RegistryManager(app) app = beaker.middleware.SessionMiddleware(app, {}, data_dir=session_dir) app = CacheMiddleware(app, {}, data_dir=os.path.join(data_dir, 'cache')) return TestApp(app)
def _retrieve_root(self): env = self.state.document.settings.env tgapp = env.config.tgjsonautodoc_app app = loadapp('config:'+tgapp, name='main', relative_to=os.getcwd()) return TGApp().find_controller('root')()