本文整理汇总了Python中bedrock.redirects.middleware.RedirectsMiddleware.process_request方法的典型用法代码示例。如果您正苦于以下问题:Python RedirectsMiddleware.process_request方法的具体用法?Python RedirectsMiddleware.process_request怎么用?Python RedirectsMiddleware.process_request使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bedrock.redirects.middleware.RedirectsMiddleware
的用法示例。
在下文中一共展示了RedirectsMiddleware.process_request方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_no_redirect
# 需要导入模块: from bedrock.redirects.middleware import RedirectsMiddleware [as 别名]
# 或者: from bedrock.redirects.middleware.RedirectsMiddleware import process_request [as 别名]
def test_no_redirect(self):
"""Should be able to skip redirects."""
resolver = get_resolver([no_redirect(r"^iam/the/walrus/$"), redirect(r"^iam/the/.*/$", "/coo/coo/cachoo/")])
middleware = RedirectsMiddleware(resolver)
resp = middleware.process_request(self.rf.get("/iam/the/walrus/"))
self.assertIsNone(resp)
# including locale
middleware = RedirectsMiddleware(resolver)
resp = middleware.process_request(self.rf.get("/pt-BR/iam/the/walrus/"))
self.assertIsNone(resp)
resp = middleware.process_request(self.rf.get("/iam/the/marmot/"))
eq_(resp.status_code, 301)
eq_(resp["Location"], "/coo/coo/cachoo/")
示例2: test_locale_value_capture_no_locale
# 需要导入模块: from bedrock.redirects.middleware import RedirectsMiddleware [as 别名]
# 或者: from bedrock.redirects.middleware.RedirectsMiddleware import process_request [as 别名]
def test_locale_value_capture_no_locale(self):
"""
Should get locale value in kwargs and not break if no locale in URL.
"""
resolver = get_resolver([redirect(r"^iam/the/(?P<name>.+)/$", "/donnie/the/{name}/")])
middleware = RedirectsMiddleware(resolver)
resp = middleware.process_request(self.rf.get("/iam/the/walrus/"))
eq_(resp.status_code, 301)
eq_(resp["Location"], "/donnie/the/walrus/")
示例3: test_locale_value_capture
# 需要导入模块: from bedrock.redirects.middleware import RedirectsMiddleware [as 别名]
# 或者: from bedrock.redirects.middleware.RedirectsMiddleware import process_request [as 别名]
def test_locale_value_capture(self):
"""
Should prepend locale value automatically.
"""
resolver = get_resolver([redirect(r"^iam/the/(?P<name>.+)/$", "/donnie/the/{name}/")])
middleware = RedirectsMiddleware(resolver)
resp = middleware.process_request(self.rf.get("/pt-BR/iam/the/walrus/"))
eq_(resp.status_code, 301)
eq_(resp["Location"], "/pt-BR/donnie/the/walrus/")
示例4: test_value_capture_and_substitution
# 需要导入模块: from bedrock.redirects.middleware import RedirectsMiddleware [as 别名]
# 或者: from bedrock.redirects.middleware.RedirectsMiddleware import process_request [as 别名]
def test_value_capture_and_substitution(self):
"""
Should be able to capture info from URL and use in redirection.
"""
resolver = get_resolver([redirect(r"^iam/the/(?P<name>.+)/$", "/donnie/the/{name}/")])
middleware = RedirectsMiddleware(resolver)
resp = middleware.process_request(self.rf.get("/iam/the/walrus/"))
eq_(resp.status_code, 301)
eq_(resp["Location"], "/donnie/the/walrus/")
示例5: test_locale_value_capture_ignore_locale
# 需要导入模块: from bedrock.redirects.middleware import RedirectsMiddleware [as 别名]
# 或者: from bedrock.redirects.middleware.RedirectsMiddleware import process_request [as 别名]
def test_locale_value_capture_ignore_locale(self):
"""
Should be able to ignore the original locale.
"""
resolver = get_resolver([redirect(r"^iam/the/(?P<name>.+)/$", "/donnie/the/{name}/", prepend_locale=False)])
middleware = RedirectsMiddleware(resolver)
resp = middleware.process_request(self.rf.get("/zh-TW/iam/the/walrus/"))
eq_(resp.status_code, 301)
eq_(resp["Location"], "/donnie/the/walrus/")
示例6: test_no_redirect
# 需要导入模块: from bedrock.redirects.middleware import RedirectsMiddleware [as 别名]
# 或者: from bedrock.redirects.middleware.RedirectsMiddleware import process_request [as 别名]
def test_no_redirect(self):
"""Should be able to skip redirects."""
resolver = get_resolver([
no_redirect(r'^iam/the/walrus/$'),
redirect(r'^iam/the/.*/$', '/coo/coo/cachoo/'),
])
middleware = RedirectsMiddleware(resolver)
resp = middleware.process_request(self.rf.get('/iam/the/walrus/'))
self.assertIsNone(resp)
# including locale
middleware = RedirectsMiddleware(resolver)
resp = middleware.process_request(self.rf.get('/pt-BR/iam/the/walrus/'))
self.assertIsNone(resp)
resp = middleware.process_request(self.rf.get('/iam/the/marmot/'))
assert resp.status_code == 301
assert resp['Location'] == '/coo/coo/cachoo/'
示例7: test_value_capture_and_substitution
# 需要导入模块: from bedrock.redirects.middleware import RedirectsMiddleware [as 别名]
# 或者: from bedrock.redirects.middleware.RedirectsMiddleware import process_request [as 别名]
def test_value_capture_and_substitution(self):
"""
Should be able to capture info from URL and use in redirection.
"""
resolver = get_resolver([redirect(r'^iam/the/(?P<name>.+)/$', '/donnie/the/{name}/')])
middleware = RedirectsMiddleware(resolver)
resp = middleware.process_request(self.rf.get('/iam/the/walrus/'))
assert resp.status_code == 301
assert resp['Location'] == '/donnie/the/walrus/'
示例8: test_empty_unnamed_captures
# 需要导入模块: from bedrock.redirects.middleware import RedirectsMiddleware [as 别名]
# 或者: from bedrock.redirects.middleware.RedirectsMiddleware import process_request [as 别名]
def test_empty_unnamed_captures(self):
"""
Should be able to define an optional unnamed capture.
"""
resolver = get_resolver([redirect(r"^iam/the(/.+)?/$", "/donnie/the{}/", locale_prefix=False)])
middleware = RedirectsMiddleware(resolver)
resp = middleware.process_request(self.rf.get("/iam/the/"))
eq_(resp.status_code, 301)
eq_(resp["Location"], "/donnie/the/")
示例9: test_empty_unnamed_captures
# 需要导入模块: from bedrock.redirects.middleware import RedirectsMiddleware [as 别名]
# 或者: from bedrock.redirects.middleware.RedirectsMiddleware import process_request [as 别名]
def test_empty_unnamed_captures(self):
"""
Should be able to define an optional unnamed capture.
"""
resolver = get_resolver([redirect(r'^iam/the(/.+)?/$', '/donnie/the{}/',
locale_prefix=False)])
middleware = RedirectsMiddleware(resolver)
resp = middleware.process_request(self.rf.get('/iam/the/'))
assert resp.status_code == 301
assert resp['Location'] == '/donnie/the/'
示例10: test_locale_value_capture_ignore_locale
# 需要导入模块: from bedrock.redirects.middleware import RedirectsMiddleware [as 别名]
# 或者: from bedrock.redirects.middleware.RedirectsMiddleware import process_request [as 别名]
def test_locale_value_capture_ignore_locale(self):
"""
Should be able to ignore the original locale.
"""
resolver = get_resolver([redirect(r'^iam/the/(?P<name>.+)/$',
'/donnie/the/{name}/', prepend_locale=False)])
middleware = RedirectsMiddleware(resolver)
resp = middleware.process_request(self.rf.get('/zh-TW/iam/the/walrus/'))
assert resp.status_code == 301
assert resp['Location'] == '/donnie/the/walrus/'
示例11: test_locale_value_capture_no_locale
# 需要导入模块: from bedrock.redirects.middleware import RedirectsMiddleware [as 别名]
# 或者: from bedrock.redirects.middleware.RedirectsMiddleware import process_request [as 别名]
def test_locale_value_capture_no_locale(self):
"""
Should get locale value in kwargs and not break if no locale in URL.
"""
resolver = get_resolver([redirect(r'^iam/the/(?P<name>.+)/$',
'/donnie/the/{name}/')])
middleware = RedirectsMiddleware(resolver)
resp = middleware.process_request(self.rf.get('/iam/the/walrus/'))
assert resp.status_code == 301
assert resp['Location'] == '/donnie/the/walrus/'
示例12: test_locale_value_capture
# 需要导入模块: from bedrock.redirects.middleware import RedirectsMiddleware [as 别名]
# 或者: from bedrock.redirects.middleware.RedirectsMiddleware import process_request [as 别名]
def test_locale_value_capture(self):
"""
Should prepend locale value automatically.
"""
resolver = get_resolver([redirect(r'^iam/the/(?P<name>.+)/$',
'/donnie/the/{name}/')])
middleware = RedirectsMiddleware(resolver)
resp = middleware.process_request(self.rf.get('/pt-BR/iam/the/walrus/'))
assert resp.status_code == 301
assert resp['Location'] == '/pt-BR/donnie/the/walrus/'
示例13: test_locale_value_capture
# 需要导入模块: from bedrock.redirects.middleware import RedirectsMiddleware [as 别名]
# 或者: from bedrock.redirects.middleware.RedirectsMiddleware import process_request [as 别名]
def test_locale_value_capture(self):
"""
Should get locale value in kwargs.
"""
resolver = get_resolver([redirect(r'^iam/the/(?P<name>.+)/$',
'/{locale}donnie/the/{name}/')])
middleware = RedirectsMiddleware(resolver)
resp = middleware.process_request(self.rf.get('/pt-BR/iam/the/walrus/'))
eq_(resp.status_code, 301)
eq_(resp['Location'], '/pt-BR/donnie/the/walrus/')
示例14: test_match_flags
# 需要导入模块: from bedrock.redirects.middleware import RedirectsMiddleware [as 别名]
# 或者: from bedrock.redirects.middleware.RedirectsMiddleware import process_request [as 别名]
def test_match_flags(self):
"""
Should be able to set regex flags for redirect URL.
"""
resolver = get_resolver(
[redirect(r"^iam/the/walrus/$", "/coo/coo/cachoo/"), no_redirect(r"^iam/the/walrus/$", re_flags="i")]
)
middleware = RedirectsMiddleware(resolver)
resp = middleware.process_request(self.rf.get("/IAm/The/Walrus/"))
self.assertIsNone(resp)
# also with locale
resp = middleware.process_request(self.rf.get("/es-ES/Iam/The/Walrus/"))
self.assertIsNone(resp)
# sanity check
resp = middleware.process_request(self.rf.get("/iam/the/walrus/"))
eq_(resp.status_code, 301)
eq_(resp["Location"], "/coo/coo/cachoo/")
示例15: test_match_flags
# 需要导入模块: from bedrock.redirects.middleware import RedirectsMiddleware [as 别名]
# 或者: from bedrock.redirects.middleware.RedirectsMiddleware import process_request [as 别名]
def test_match_flags(self):
"""
Should be able to set regex flags for redirect URL.
"""
resolver = get_resolver([
redirect(r'^iam/the/walrus/$', '/coo/coo/cachoo/'),
no_redirect(r'^iam/the/walrus/$', re_flags='i'),
])
middleware = RedirectsMiddleware(resolver)
resp = middleware.process_request(self.rf.get('/IAm/The/Walrus/'))
self.assertIsNone(resp)
# also with locale
resp = middleware.process_request(self.rf.get('/es-ES/Iam/The/Walrus/'))
self.assertIsNone(resp)
# sanity check
resp = middleware.process_request(self.rf.get('/iam/the/walrus/'))
assert resp.status_code == 301
assert resp['Location'] == '/coo/coo/cachoo/'