当前位置: 首页>>代码示例>>Python>>正文


Python middleware.RedirectsMiddleware类代码示例

本文整理汇总了Python中bedrock.redirects.middleware.RedirectsMiddleware的典型用法代码示例。如果您正苦于以下问题:Python RedirectsMiddleware类的具体用法?Python RedirectsMiddleware怎么用?Python RedirectsMiddleware使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了RedirectsMiddleware类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_value_capture_and_substitution

 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/'
开发者ID:alexgibson,项目名称:bedrock,代码行数:9,代码来源:test_util.py

示例2: test_empty_unnamed_captures

 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/")
开发者ID:kyoshino,项目名称:bedrock,代码行数:9,代码来源:test_util.py

示例3: test_locale_value_capture_ignore_locale

 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/")
开发者ID:kyoshino,项目名称:bedrock,代码行数:9,代码来源:test_util.py

示例4: test_locale_value_capture_no_locale

 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/")
开发者ID:kyoshino,项目名称:bedrock,代码行数:9,代码来源:test_util.py

示例5: test_locale_value_capture

 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/")
开发者ID:kyoshino,项目名称:bedrock,代码行数:9,代码来源:test_util.py

示例6: test_value_capture_and_substitution

 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/")
开发者ID:kyoshino,项目名称:bedrock,代码行数:9,代码来源:test_util.py

示例7: test_locale_value_capture

 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/'
开发者ID:alexgibson,项目名称:bedrock,代码行数:10,代码来源:test_util.py

示例8: test_locale_value_capture_ignore_locale

 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/'
开发者ID:alexgibson,项目名称:bedrock,代码行数:10,代码来源:test_util.py

示例9: test_locale_value_capture

 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/')
开发者ID:rishiloyola,项目名称:bedrock,代码行数:10,代码来源:test_util.py

示例10: test_empty_unnamed_captures

 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/'
开发者ID:alexgibson,项目名称:bedrock,代码行数:10,代码来源:test_util.py

示例11: test_locale_value_capture_no_locale

 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/'
开发者ID:alexgibson,项目名称:bedrock,代码行数:10,代码来源:test_util.py

示例12: test_no_locale_prefix

    def test_no_locale_prefix(self):
        """
        Should be able to define a redirect that ignores locale prefix.

        Also when not using any named captures (like implied locale) unnamed
        captures should work. For some reason Django only allows unnamed captures
        to pass through if there are no named ones.
        """
        resolver = get_resolver([redirect(r"^iam/the/(.+)/$", "/donnie/the/{}/", locale_prefix=False)])
        middleware = RedirectsMiddleware(resolver)
        resp = middleware.process_request(self.rf.get("/iam/the/walrus/"))
        eq_(resp.status_code, 301)
        eq_(resp["Location"], "/donnie/the/walrus/")
开发者ID:kyoshino,项目名称:bedrock,代码行数:13,代码来源:test_util.py

示例13: test_no_redirect

    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/")
开发者ID:kyoshino,项目名称:bedrock,代码行数:15,代码来源:test_util.py

示例14: test_non_ascii_strip_tags

    def test_non_ascii_strip_tags(self):
        """
        Should deal with non-ascii characters when there's a substitution as well as strip tags.

        This is from errors that happened in prod. The following URL caused a 500:

        https://www.mozilla.org/editor/midasdemo/securityprefs.html%3C/span%3E%3C/a%3E%C2%A0

        https://sentry.prod.mozaws.net/marketing/bedrock-prod-eu-west/issues/349078/
        """
        resolver = get_resolver([redirect(r"^editor/(?P<page>.*)$", "http://www-archive.mozilla.org/editor/{page}")])
        middleware = RedirectsMiddleware(resolver)
        resp = middleware.process_request(
            self.rf.get("/editor/midasdemo/securityprefs.html" "%3C/span%3E%3C/a%3E%C2%A0")
        )
        eq_(resp.status_code, 301)
        eq_(resp["Location"], "http://www-archive.mozilla.org/editor/midasdemo/securityprefs.html%C2%A0")
开发者ID:kyoshino,项目名称:bedrock,代码行数:17,代码来源:test_util.py

示例15: test_no_redirect

    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/'
开发者ID:alexgibson,项目名称:bedrock,代码行数:18,代码来源:test_util.py


注:本文中的bedrock.redirects.middleware.RedirectsMiddleware类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。