本文整理汇总了Python中tipfy.Tipfy.get_test_handler方法的典型用法代码示例。如果您正苦于以下问题:Python Tipfy.get_test_handler方法的具体用法?Python Tipfy.get_test_handler怎么用?Python Tipfy.get_test_handler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tipfy.Tipfy
的用法示例。
在下文中一共展示了Tipfy.get_test_handler方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_name_prefix
# 需要导入模块: from tipfy import Tipfy [as 别名]
# 或者: from tipfy.Tipfy import get_test_handler [as 别名]
def test_name_prefix(self):
class DummyHandler(RequestHandler):
def get(self, **kwargs):
return ''
rules = [
NamePrefix('company-', [
Rule('/', name='home', handler=DummyHandler),
Rule('/about', name='about', handler=DummyHandler),
Rule('/contact', name='contact', handler=DummyHandler),
]),
]
app = Tipfy(rules)
with app.get_test_handler('/') as handler:
self.assertEqual(handler.url_for('company-home'), '/')
self.assertEqual(handler.url_for('company-about'), '/about')
self.assertEqual(handler.url_for('company-contact'), '/contact')
with app.get_test_handler('/') as handler:
self.assertEqual(handler.request.rule.name, 'company-home')
with app.get_test_handler('/about') as handler:
self.assertEqual(handler.request.rule.name, 'company-about')
with app.get_test_handler('/contact') as handler:
self.assertEqual(handler.request.rule.name, 'company-contact')
示例2: test_get_config
# 需要导入模块: from tipfy import Tipfy [as 别名]
# 或者: from tipfy.Tipfy import get_test_handler [as 别名]
def test_get_config(self):
app = Tipfy(rules=[
Rule('/', name='home', handler=AllMethodsHandler),
], config = {
'foo': {
'bar': 'baz',
}
})
with app.get_test_handler('/') as handler:
self.assertEqual(handler.get_config('foo', 'bar'), 'baz')
示例3: test_store_instances
# 需要导入模块: from tipfy import Tipfy [as 别名]
# 或者: from tipfy.Tipfy import get_test_handler [as 别名]
def test_store_instances(self):
from tipfy.appengine.auth import AuthStore
from tipfy.i18n import I18nStore
from tipfy.sessions import SecureCookieSession
app = Tipfy(rules=[
Rule('/', name='home', handler=AllMethodsHandler),
], config={
'tipfy.sessions': {
'secret_key': 'secret',
},
})
with app.get_test_handler('/') as handler:
self.assertEqual(isinstance(handler.session, SecureCookieSession), True)
self.assertEqual(isinstance(handler.auth, AuthStore), True)
self.assertEqual(isinstance(handler.i18n, I18nStore), True)
示例4: test_url_for
# 需要导入模块: from tipfy import Tipfy [as 别名]
# 或者: from tipfy.Tipfy import get_test_handler [as 别名]
def test_url_for(self):
app = Tipfy(rules=[
Rule('/', name='home', handler=AllMethodsHandler),
Rule('/about', name='about', handler='handlers.About'),
Rule('/contact', name='contact', handler='handlers.Contact'),
])
with app.get_test_handler('/') as handler:
self.assertEqual(handler.url_for('home'), '/')
self.assertEqual(handler.url_for('about'), '/about')
self.assertEqual(handler.url_for('contact'), '/contact')
# Extras
self.assertEqual(handler.url_for('about', _anchor='history'), '/about#history')
self.assertEqual(handler.url_for('about', _full=True), 'http://localhost/about')
self.assertEqual(handler.url_for('about', _netloc='www.google.com'), 'http://www.google.com/about')
self.assertEqual(handler.url_for('about', _scheme='https'), 'https://localhost/about')