本文整理汇总了Python中tg.configuration.AppConfig.add_tosca_middleware方法的典型用法代码示例。如果您正苦于以下问题:Python AppConfig.add_tosca_middleware方法的具体用法?Python AppConfig.add_tosca_middleware怎么用?Python AppConfig.add_tosca_middleware使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tg.configuration.AppConfig
的用法示例。
在下文中一共展示了AppConfig.add_tosca_middleware方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from tg.configuration import AppConfig [as 别名]
# 或者: from tg.configuration.AppConfig import add_tosca_middleware [as 别名]
#.........这里部分代码省略.........
'cookie_secret':'12345',
'authenticators':[('default', None)]}
self.config.setup_auth()
self.config.add_auth_middleware(None, True)
authenticators = [x[0] for x in self.config['sa_auth']['authenticators']]
assert len(authenticators) == 1
self.config['sa_auth'] = {}
self.config.auth_backend = None
def test_tgauthmetadata_loginpwd(self):
who_authenticator = _AuthMetadataAuthenticator(ApplicationAuthMetadataWithAuthentication(), using_password=True)
assert who_authenticator.authenticate({}, {}) == None
def test_tgauthmetadata_nologinpwd(self):
who_authenticator = _AuthMetadataAuthenticator(ApplicationAuthMetadataWithAuthentication(), using_password=False)
assert who_authenticator.authenticate({}, {}) == 1
def test_toscawidgets_recource_variant(self):
if PY3: raise SkipTest()
resultingconfig = {}
def fake_make_middleware(app, twconfig):
resultingconfig.update(twconfig)
return app
import tw.api
prev_tw_make_middleware = tw.api.make_middleware
tw.api.make_middleware = fake_make_middleware
config['toscawidgets.framework.resource_variant'] = 'min'
self.config.add_tosca_middleware(None)
config.pop('toscawidgets.framework.resource_variant', None)
tw.api.make_middleware = prev_tw_make_middleware
assert resultingconfig['toscawidgets.framework.default_view'] == self.config.default_renderer
assert resultingconfig['toscawidgets.framework.translator'] == tg.i18n.ugettext
assert resultingconfig['toscawidgets.middleware.inject_resources'] == True
assert tw.api.resources.registry.ACTIVE_VARIANT == 'min'
def test_config_hooks(self):
# Reset milestone so that registered hooks
milestones._reset_all()
class RootController(TGController):
@expose()
def test(self):
return 'HI!'
visited_hooks = []
def before_config_hook(app):
visited_hooks.append('before_config')
return app
def after_config_hook(app):
visited_hooks.append('after_config')
return app
conf = AppConfig(minimal=True, root_controller=RootController())
conf.register_hook('before_config', before_config_hook)
conf.register_hook('after_config', after_config_hook)
app = conf.make_wsgi_app()
app = TestApp(app)
assert 'HI!' in app.get('/test')