本文整理匯總了Python中cms.middleware.toolbar.ToolbarMiddleware.show_toolbar方法的典型用法代碼示例。如果您正苦於以下問題:Python ToolbarMiddleware.show_toolbar方法的具體用法?Python ToolbarMiddleware.show_toolbar怎麽用?Python ToolbarMiddleware.show_toolbar使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cms.middleware.toolbar.ToolbarMiddleware
的用法示例。
在下文中一共展示了ToolbarMiddleware.show_toolbar方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_02_toolbar_middleware_show_toolbar
# 需要導入模塊: from cms.middleware.toolbar import ToolbarMiddleware [as 別名]
# 或者: from cms.middleware.toolbar.ToolbarMiddleware import show_toolbar [as 別名]
def test_02_toolbar_middleware_show_toolbar(self):
class Mock:
pass
middle = ToolbarMiddleware()
request = Mock()
response = Mock()
# if request.is_ajax():
setattr(request,'is_ajax', lambda : True)
result = middle.show_toolbar(request, response)
self.assertEqual(result, False)
#if response.status_code != 200:
setattr(request,'is_ajax', lambda : False)
setattr(response, 'status_code', 201)
result = middle.show_toolbar(request, response)
self.assertEqual(result, False)
setattr(response, 'status_code', 200)
#if not response['Content-Type'].split(';')[0] in HTML_TYPES:
setattr(response, '__getitem__', lambda _: 'Whatever')
result = middle.show_toolbar(request, response)
self.assertEqual(result, False)
setattr(response, '__getitem__', lambda _: 'text/html')
#if is_media_request(request):
setattr(request, 'path', '/media/')
result = middle.show_toolbar(request, response)
self.assertEqual(result, False)
setattr(request, 'path', '')
#if "edit" in request.GET:
setattr(request, 'GET', ["edit"])
result = middle.show_toolbar(request, response)
self.assertEqual(result, True)
setattr(request, 'GET', [])
#if not hasattr(request, "user"):
result = middle.show_toolbar(request, response)
self.assertEqual(result, False)
setattr(request, 'user', 'test-user')