本文整理汇总了Python中django_seo_js.middleware.UserAgentMiddleware.process_request方法的典型用法代码示例。如果您正苦于以下问题:Python UserAgentMiddleware.process_request方法的具体用法?Python UserAgentMiddleware.process_request怎么用?Python UserAgentMiddleware.process_request使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django_seo_js.middleware.UserAgentMiddleware
的用法示例。
在下文中一共展示了UserAgentMiddleware.process_request方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: UserAgentMiddlewareTest
# 需要导入模块: from django_seo_js.middleware import UserAgentMiddleware [as 别名]
# 或者: from django_seo_js.middleware.UserAgentMiddleware import process_request [as 别名]
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"
#.........这里部分代码省略.........