本文整理汇总了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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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")
示例9: setUp
def setUp(self):
super(UserAgentMiddlewareTest, self).setUp()
self.middleware = UserAgentMiddleware()
self.request = Mock()
self.request.path = "/"
self.request.META = {}
示例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"
#.........这里部分代码省略.........
示例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)