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


Python middleware.UserAgentMiddleware类代码示例

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


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

示例1: test_overriding_skips_gifs_by_default

 def test_overriding_skips_gifs_by_default(self):
     self.middleware = UserAgentMiddleware()
     self.request.path = "/foo.gif"
     self.request.META = {
         "HTTP_USER_AGENT": "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
     }
     self.assertEqual(self.middleware.process_request(self.request), None)
开发者ID:andrewebdev,项目名称:django-seo-js,代码行数:7,代码来源:test_middlewares.py

示例2: test_overriding_matches_skips_if_service_is_down

 def test_overriding_matches_skips_if_service_is_down(self):
     self.middleware = UserAgentMiddleware()
     self.request.META = {
         "HTTP_USER_AGENT":
         "Mozilla/2.0 (compatible; Ask Jeeves/Teoma; +http://about.ask.com/en/docs/about/webmasters.shtml)"
     }
     self.assertEqual(self.middleware.process_request(self.request), None)
开发者ID:skoczen,项目名称:django-seo-js,代码行数:7,代码来源:test_middlewares.py

示例3: test_overriding_skips_gifs_by_default

 def test_overriding_skips_gifs_by_default(self):
     self.middleware = UserAgentMiddleware()
     self.request.path = "/foo.gif"
     self.request.META = {
         "HTTP_USER_AGENT":
         "Mozilla/2.0 (compatible; Ask Jeeves/Teoma; +http://about.ask.com/en/docs/about/webmasters.shtml)"
     }
     self.assertEqual(self.middleware.process_request(self.request), None)
开发者ID:skoczen,项目名称:django-seo-js,代码行数:8,代码来源:test_middlewares.py

示例4: test_overriding_skips_custom_overrides_xml_by_default

    def test_overriding_skips_custom_overrides_xml_by_default(self):
        self.middleware = UserAgentMiddleware()
        self.request.path = "/sitemap.xml"
        self.request.META = {
            "HTTP_USER_AGENT": "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
        }
        self.assertEqual(self.middleware.process_request(self.request).content, "Test")

        self.request.path = "/foo.html"
        self.assertEqual(self.middleware.process_request(self.request), None)

        self.request.path = "/bar/ibbity.html"
        self.assertEqual(self.middleware.process_request(self.request), None)
开发者ID:andrewebdev,项目名称:django-seo-js,代码行数:13,代码来源:test_middlewares.py

示例5: test_overriding_skips_custom_overrides_xml_by_default

    def test_overriding_skips_custom_overrides_xml_by_default(self):
        self.middleware = UserAgentMiddleware()
        self.request.path = "/sitemap.xml"
        self.request.META = {
            "HTTP_USER_AGENT":
            "Mozilla/2.0 (compatible; Ask Jeeves/Teoma; +http://about.ask.com/en/docs/about/webmasters.shtml)"
        }
        self.assertEqual(self.middleware.process_request(self.request).content, b"Test")

        self.request.path = "/foo.html"
        self.assertEqual(self.middleware.process_request(self.request), None)

        self.request.path = "/bar/ibbity.html"
        self.assertEqual(self.middleware.process_request(self.request), None)
开发者ID:skoczen,项目名称:django-seo-js,代码行数:14,代码来源:test_middlewares.py

示例6: test_overriding_matches_skips_if_disabled_via_enabled

 def test_overriding_matches_skips_if_disabled_via_enabled(self):
     self.middleware = UserAgentMiddleware()
     self.request.META = {
         "HTTP_USER_AGENT": "The TestUserAgent v1.0"
     }
     self.assertEqual(self.middleware.process_request(self.request), None)
开发者ID:skoczen,项目名称:django-seo-js,代码行数:6,代码来源:test_middlewares.py

示例7: test_missing_user_agent_still_works

 def test_missing_user_agent_still_works(self):
     self.middleware = UserAgentMiddleware()
     self.request.META = {}
     self.assertEqual(self.middleware.process_request(self.request), None)
开发者ID:skoczen,项目名称:django-seo-js,代码行数:4,代码来源:test_middlewares.py

示例8: test_overriding_matches

 def test_overriding_matches(self):
     self.middleware = UserAgentMiddleware()
     self.request.META = {
         "HTTP_USER_AGENT": "The TestUserAgent v1.0"
     }
     self.assertEqual(self.middleware.process_request(self.request).content, b"Test")
开发者ID:skoczen,项目名称:django-seo-js,代码行数:6,代码来源:test_middlewares.py

示例9: setUp

 def setUp(self):
     super(UserAgentMiddlewareTest, self).setUp()
     self.middleware = UserAgentMiddleware()
     self.request = Mock()
     self.request.path = "/"
     self.request.META = {}
开发者ID:skoczen,项目名称:django-seo-js,代码行数:6,代码来源:test_middlewares.py

示例10: UserAgentMiddlewareTest

class UserAgentMiddlewareTest(TestCase):

    @override_settings(BACKEND='django_seo_js.backends.TestBackend')
    def setUp(self):
        super(UserAgentMiddlewareTest, self).setUp()
        self.middleware = UserAgentMiddleware()
        self.request = Mock()
        self.request.path = "/"
        self.request.META = {}

    def test_matches_one_of_the_default_user_agents(self):
        self.request.META = {
            "HTTP_USER_AGENT":
            "Mozilla/2.0 (compatible; Ask Jeeves/Teoma; +http://about.ask.com/en/docs/about/webmasters.shtml)"
        }
        self.assertEqual(self.middleware.process_request(self.request).content, b"Test")

    def test_does_not_match_one_of_the_default_user_agents(self):
        self.request.META = {
            "HTTP_USER_AGENT": "This user-agent is not a search engine."
        }
        self.assertEqual(self.middleware.process_request(self.request), None)

    @override_settings(
        USER_AGENTS=["TestUserAgent", ],
        BACKEND='django_seo_js.backends.TestBackend'
    )
    def test_overriding_matches(self):
        self.middleware = UserAgentMiddleware()
        self.request.META = {
            "HTTP_USER_AGENT": "The TestUserAgent v1.0"
        }
        self.assertEqual(self.middleware.process_request(self.request).content, b"Test")

    @override_settings(
        USER_AGENTS=["TestUserAgent", ],
        BACKEND='django_seo_js.backends.TestBackend'
    )
    def test_overriding_does_not_match_properly(self):
        self.middleware = UserAgentMiddleware()
        self.request.META = {
            "HTTP_USER_AGENT":
            "Mozilla/2.0 (compatible; Ask Jeeves/Teoma; +http://about.ask.com/en/docs/about/webmasters.shtml)"
        }
        self.assertEqual(self.middleware.process_request(self.request), None)

    @override_settings(
        USER_AGENTS=["TestUserAgent", ],
        BACKEND='django_seo_js.backends.TestBackend'
    )
    def test_missing_user_agent_still_works(self):
        self.middleware = UserAgentMiddleware()
        self.request.META = {}
        self.assertEqual(self.middleware.process_request(self.request), None)

    @override_settings(BACKEND='django_seo_js.backends.TestBackend', ENABLED=False)
    def test_overriding_matches_skips_if_disabled_via_enabled(self):
        self.middleware = UserAgentMiddleware()
        self.request.META = {
            "HTTP_USER_AGENT": "The TestUserAgent v1.0"
        }
        self.assertEqual(self.middleware.process_request(self.request), None)

    @override_settings(BACKEND='django_seo_js.backends.TestServiceDownBackend')
    def test_overriding_matches_skips_if_service_is_down(self):
        self.middleware = UserAgentMiddleware()
        self.request.META = {
            "HTTP_USER_AGENT":
            "Mozilla/2.0 (compatible; Ask Jeeves/Teoma; +http://about.ask.com/en/docs/about/webmasters.shtml)"
        }
        self.assertEqual(self.middleware.process_request(self.request), None)

    @override_settings(BACKEND='django_seo_js.backends.TestBackend')
    def test_overriding_skips_sitemap_xml_by_default(self):
        self.middleware = UserAgentMiddleware()
        self.request.path = "/sitemap.xml"
        self.request.META = {
            "HTTP_USER_AGENT":
            "Mozilla/2.0 (compatible; Ask Jeeves/Teoma; +http://about.ask.com/en/docs/about/webmasters.shtml)"
        }
        self.assertEqual(self.middleware.process_request(self.request), None)

    @override_settings(
        BACKEND='django_seo_js.backends.TestBackend',
        IGNORE_URLS=["/foo.html", "/bar/ibbity.html", ],
        IGNORE_EXTENSIONS=[],
    )
    def test_overriding_skips_custom_overrides_xml_by_default(self):
        self.middleware = UserAgentMiddleware()
        self.request.path = "/sitemap.xml"
        self.request.META = {
            "HTTP_USER_AGENT":
            "Mozilla/2.0 (compatible; Ask Jeeves/Teoma; +http://about.ask.com/en/docs/about/webmasters.shtml)"
        }
        self.assertEqual(self.middleware.process_request(self.request).content, b"Test")

        self.request.path = "/foo.html"
        self.assertEqual(self.middleware.process_request(self.request), None)

        self.request.path = "/bar/ibbity.html"
#.........这里部分代码省略.........
开发者ID:skoczen,项目名称:django-seo-js,代码行数:101,代码来源:test_middlewares.py

示例11: test_overriding_matches_skips_if_service_is_down

 def test_overriding_matches_skips_if_service_is_down(self):
     self.middleware = UserAgentMiddleware()
     self.request.META = {
         "HTTP_USER_AGENT": "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
     }
     self.assertEqual(self.middleware.process_request(self.request), None)
开发者ID:andrewebdev,项目名称:django-seo-js,代码行数:6,代码来源:test_middlewares.py


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