本文整理汇总了Python中debug_toolbar.middleware.DebugToolbarMiddleware类的典型用法代码示例。如果您正苦于以下问题:Python DebugToolbarMiddleware类的具体用法?Python DebugToolbarMiddleware怎么用?Python DebugToolbarMiddleware使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DebugToolbarMiddleware类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_tuple_urlconf
def test_tuple_urlconf(self):
request = rf.get('/')
urls = __import__('tests.urls').urls
urls.urlpatterns = tuple(urls.urlpatterns)
request.urlconf = urls
middleware = DebugToolbarMiddleware()
with Settings(INTERNAL_IPS=['127.0.0.1'], DEBUG=True):
middleware.process_request(request)
self.assertFalse(isinstance(request.urlconf, basestring))
示例2: test_show_toolbar_TEST
def test_show_toolbar_TEST(self):
request = rf.get('/')
middleware = DebugToolbarMiddleware()
with Settings(INTERNAL_IPS=['127.0.0.1'], TEST=True, DEBUG=True):
self.assertFalse(middleware._show_toolbar(request))
with Settings(INTERNAL_IPS=['127.0.0.1'], TEST=False, DEBUG=True):
self.assertTrue(middleware._show_toolbar(request))
示例3: test_request_urlconf_string
def test_request_urlconf_string(self):
request = rf.get('/')
set_urlconf('tests.urls')
middleware = DebugToolbarMiddleware()
middleware.process_request(request)
patterns = get_resolver(get_urlconf()).url_patterns
self.assertTrue(hasattr(patterns[1], '_callback_str'))
self.assertEqual(patterns[-1]._callback_str, 'tests.views.execute_sql')
示例4: test_tuple_urlconf
def test_tuple_urlconf(self):
request = rf.get('/')
urls = __import__('tests.urls').urls
urls.urlpatterns = tuple(urls.urlpatterns)
request.urlconf = urls
middleware = DebugToolbarMiddleware()
middleware.process_request(request)
self.assertFalse(isinstance(request.urlconf, six.string_types))
示例5: test_show_toolbar_TEST
def test_show_toolbar_TEST(self):
request = self.request
middleware = DebugToolbarMiddleware()
with Settings(TEST=True, DEBUG=True):
self.assertFalse(middleware._show_toolbar(request))
with Settings(TEST=False, DEBUG=True):
self.assertTrue(middleware._show_toolbar(request))
示例6: test_show_toolbar_INTERNAL_IPS
def test_show_toolbar_INTERNAL_IPS(self):
request = self.request
request.META = {"REMOTE_ADDR": "127.0.0.1"}
middleware = DebugToolbarMiddleware()
with Settings(INTERNAL_IPS=["127.0.0.1"], DEBUG=True):
self.assertTrue(middleware._show_toolbar(request))
with Settings(INTERNAL_IPS=[], DEBUG=True):
self.assertFalse(middleware._show_toolbar(request))
示例7: test_show_toolbar_INTERNAL_IPS
def test_show_toolbar_INTERNAL_IPS(self):
request = rf.get('/')
request.META = {'REMOTE_ADDR': '127.0.0.1'}
middleware = DebugToolbarMiddleware()
with Settings(INTERNAL_IPS=['127.0.0.1'], DEBUG=True):
self.assertTrue(middleware._show_toolbar(request))
with Settings(INTERNAL_IPS=[], DEBUG=True):
self.assertFalse(middleware._show_toolbar(request))
示例8: test_show_toolbar_TEST
def test_show_toolbar_TEST(self):
request = self.request
request.META = {'REMOTE_ADDR': '127.0.0.1'}
middleware = DebugToolbarMiddleware()
with Settings(INTERNAL_IPS=['127.0.0.1'], TEST=True, DEBUG=True):
self.assertFalse(middleware._show_toolbar(request))
with Settings(INTERNAL_IPS=['127.0.0.1'], TEST=False, DEBUG=True):
self.assertTrue(middleware._show_toolbar(request))
示例9: test_request_urlconf_string
def test_request_urlconf_string(self):
request = rf.get('/')
request.urlconf = 'tests.urls'
middleware = DebugToolbarMiddleware()
with Settings(INTERNAL_IPS=['127.0.0.1'], DEBUG=True):
middleware.process_request(request)
self.assertFalse(isinstance(request.urlconf, basestring))
self.assertTrue(hasattr(request.urlconf.urlpatterns[1], '_callback_str'))
self.assertEquals(request.urlconf.urlpatterns[-1]._callback_str, 'tests.views.execute_sql')
示例10: test_request_urlconf_module
def test_request_urlconf_module(self):
request = rf.get('/')
request.urlconf = __import__('tests.urls').urls
middleware = DebugToolbarMiddleware()
with self.settings(INTERNAL_IPS=['127.0.0.1'], DEBUG=True):
middleware.process_request(request)
self.assertFalse(isinstance(request.urlconf, six.string_types))
self.assertTrue(hasattr(request.urlconf.urlpatterns[1], '_callback_str'))
self.assertEqual(request.urlconf.urlpatterns[-1]._callback_str, 'tests.views.execute_sql')
示例11: test_request_urlconf_module
def test_request_urlconf_module(self):
request = rf.get('/')
request.urlconf = __import__('tests.urls').urls
middleware = DebugToolbarMiddleware()
middleware.process_request(request)
self.assertFalse(isinstance(request.urlconf, six.string_types))
patterns = request.urlconf.urlpatterns
self.assertTrue(hasattr(patterns[1], '_callback_str'))
self.assertEqual(patterns[-1]._callback_str, 'tests.views.execute_sql')
示例12: test_request_urlconf_string
def test_request_urlconf_string(self):
request = self.request
request.urlconf = "tests.urls"
request.META = {"REMOTE_ADDR": "127.0.0.1"}
middleware = DebugToolbarMiddleware()
with Settings(INTERNAL_IPS=["127.0.0.1"], DEBUG=True):
middleware.process_request(request)
self.assertFalse(isinstance(request.urlconf, basestring))
self.assertTrue(hasattr(request.urlconf.urlpatterns[0], "_callback_str"))
self.assertEquals(request.urlconf.urlpatterns[0]._callback_str, "debug_toolbar.views.debug_media")
self.assertEquals(request.urlconf.urlpatterns[-1].urlconf_name.__name__, "tests.urls")
示例13: test_request_urlconf_string
def test_request_urlconf_string(self):
request = self.request
request.urlconf = 'debug_toolbar.tests.urls'
request.META = {'REMOTE_ADDR': '127.0.0.1'}
middleware = DebugToolbarMiddleware()
with Settings(DEBUG=True):
middleware.process_request(request)
self.assertFalse(isinstance(request.urlconf, basestring))
self.assertTrue(hasattr(request.urlconf.urlpatterns[0], '_callback_str'))
self.assertEquals(request.urlconf.urlpatterns[0]._callback_str, 'debug_toolbar.views.debug_media')
self.assertEquals(request.urlconf.urlpatterns[-1].urlconf_name.__name__, 'debug_toolbar.tests.urls')
示例14: execute_command
def execute_command(func,self,*args,**options):
command = args[0]
start = datetime.now()
result = func(self,*args,**options)
stop = datetime.now()
duration = ms_from_timedelta(stop - start)
#TODO find more better way to get the calling func info
calframe = _get_func_info()
params = {
'func':calframe[4][3],
'func_path':"{}:{}".format(calframe[4][1],calframe[4][2]),
'command':command,
'result':result,
'start_time':start,
'stop_time':stop,
'duration':duration,
'is_slow':None,
}
#TODO more better way to loggging?
djdt = DebugToolbarMiddleware.get_current()
if not djdt:
return result
logger = djdt.get_panel(RedisDebugPanel)
logger.record(**params)
return result
示例15: test_request_urlconf_module
def test_request_urlconf_module(self):
request = self.request
request.urlconf = __import__('tests.urls').urls
request.META = {'REMOTE_ADDR': '127.0.0.1'}
middleware = DebugToolbarMiddleware()
with Settings(INTERNAL_IPS=['127.0.0.1'], DEBUG=True):
middleware.process_request(request)
self.assertFalse(isinstance(request.urlconf, basestring))
self.assertTrue(hasattr(request.urlconf.urlpatterns[0], '_callback_str'))
self.assertEquals(request.urlconf.urlpatterns[0]._callback_str, 'debug_toolbar.views.debug_media')
self.assertTrue(hasattr(request.urlconf.urlpatterns[1], '_callback_str'))
self.assertEquals(request.urlconf.urlpatterns[-1]._callback_str, 'tests.views.execute_sql')