diff options
Diffstat (limited to 'debug_toolbar/tests')
| -rw-r--r-- | debug_toolbar/tests/__init__.py | 1 | ||||
| -rw-r--r-- | debug_toolbar/tests/templates/404.html | 0 | ||||
| -rw-r--r-- | debug_toolbar/tests/tests.py | 39 | ||||
| -rw-r--r-- | debug_toolbar/tests/urls.py | 14 | ||||
| -rw-r--r-- | debug_toolbar/tests/views.py | 7 |
5 files changed, 61 insertions, 0 deletions
diff --git a/debug_toolbar/tests/__init__.py b/debug_toolbar/tests/__init__.py new file mode 100644 index 0000000..f853b10 --- /dev/null +++ b/debug_toolbar/tests/__init__.py @@ -0,0 +1 @@ +from tests import *
\ No newline at end of file diff --git a/debug_toolbar/tests/templates/404.html b/debug_toolbar/tests/templates/404.html new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/debug_toolbar/tests/templates/404.html diff --git a/debug_toolbar/tests/tests.py b/debug_toolbar/tests/tests.py new file mode 100644 index 0000000..cdc1947 --- /dev/null +++ b/debug_toolbar/tests/tests.py @@ -0,0 +1,39 @@ +from debug_toolbar.middleware import DebugToolbarMiddleware +from debug_toolbar.panels.sql import SQLDebugPanel +from debug_toolbar.toolbar.loader import DebugToolbar + +from django.contrib.auth.models import User +from django.test import TestCase + +from dingus import Dingus +import thread + +class BaseTestCase(TestCase): + def setUp(self): + request = Dingus('request') + toolbar = DebugToolbar(request) + DebugToolbarMiddleware.debug_toolbars[thread.get_ident()] = toolbar + self.toolbar = toolbar + +class DebugToolbarTestCase(BaseTestCase): + urls = 'debug_toolbar.tests.urls' + + def test_middleware(self): + resp = self.client.get('/execute_sql/') + self.assertEquals(resp.status_code, 200) + +class SQLPanelTestCase(BaseTestCase): + def test_recording(self): + panel = self.toolbar.get_panel(SQLDebugPanel) + self.assertEquals(len(panel._queries), 0) + + list(User.objects.all()) + + # ensure query was logged + self.assertEquals(len(panel._queries), 1) + query = panel._queries[0] + self.assertEquals(query[0], 'default') + self.assertTrue('sql' in query[1]) + self.assertTrue('duration' in query[1]) + self.assertTrue('stacktrace' in query[1]) +
\ No newline at end of file diff --git a/debug_toolbar/tests/urls.py b/debug_toolbar/tests/urls.py new file mode 100644 index 0000000..7c99b03 --- /dev/null +++ b/debug_toolbar/tests/urls.py @@ -0,0 +1,14 @@ +""" +URLpatterns for the debug toolbar. + +These should not be loaded explicitly; the debug toolbar middleware will patch +this into the urlconf for the request. +""" +from django.conf.urls.defaults import * +from django.contrib import admin + +admin.autodiscover() + +urlpatterns = patterns('', + url(r'^execute_sql/$', 'debug_toolbar.tests.views.execute_sql'), +) diff --git a/debug_toolbar/tests/views.py b/debug_toolbar/tests/views.py new file mode 100644 index 0000000..f989dcd --- /dev/null +++ b/debug_toolbar/tests/views.py @@ -0,0 +1,7 @@ +from django.contrib.auth.models import User +from django.http import HttpResponse + +def execute_sql(request): + list(User.objects.all()) + + return HttpResponse()
\ No newline at end of file |
