aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Cramer2011-03-30 16:33:34 -0700
committerDavid Cramer2011-03-30 16:33:34 -0700
commitf492b56c8200eebb77b8023ab386c9ef412cc06b (patch)
treee4b05a543bdbc5bdc2b179902ac824ae59f78224
parent65969f7777ce0bd6bba53540d960a93c27b346ce (diff)
downloaddjango-debug-toolbar-f492b56c8200eebb77b8023ab386c9ef412cc06b.tar.bz2
Some initial tests and fix for execution model
-rw-r--r--debug_toolbar/panels/sql.py4
-rw-r--r--debug_toolbar/runtests.py47
-rw-r--r--debug_toolbar/tests/__init__.py1
-rw-r--r--debug_toolbar/tests/templates/404.html0
-rw-r--r--debug_toolbar/tests/tests.py39
-rw-r--r--debug_toolbar/tests/urls.py14
-rw-r--r--debug_toolbar/tests/views.py7
-rw-r--r--setup.py5
8 files changed, 115 insertions, 2 deletions
diff --git a/debug_toolbar/panels/sql.py b/debug_toolbar/panels/sql.py
index a78a3e2..4c7b8a1 100644
--- a/debug_toolbar/panels/sql.py
+++ b/debug_toolbar/panels/sql.py
@@ -102,12 +102,12 @@ class CursorWrapper(object):
def execute(self, sql, params=()):
djdt = DebugToolbarMiddleware.get_current()
if not djdt:
- return self.cursor.execute(self, sql, params)
+ return self.cursor.execute(sql, params)
panel = djdt.get_panel(SQLDebugPanel)
start = datetime.now()
try:
- return self.cursor.execute(self, sql, params)
+ return self.cursor.execute(sql, params)
finally:
stop = datetime.now()
duration = ms_from_timedelta(stop - start)
diff --git a/debug_toolbar/runtests.py b/debug_toolbar/runtests.py
new file mode 100644
index 0000000..f16882a
--- /dev/null
+++ b/debug_toolbar/runtests.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python
+import sys
+from os.path import dirname, abspath
+
+from django.conf import settings
+
+if not settings.configured:
+ settings.configure(
+ DATABASE_ENGINE='sqlite3',
+ # HACK: this fixes our threaded runserver remote tests
+ # DATABASE_NAME='test_sentry',
+ # TEST_DATABASE_NAME='test_sentry',
+ INSTALLED_APPS=[
+ 'django.contrib.auth',
+ 'django.contrib.admin',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sessions',
+ 'django.contrib.sites',
+
+ 'debug_toolbar',
+
+ 'debug_toolbar.tests',
+ ],
+ ROOT_URLCONF='',
+ DEBUG=False,
+ SITE_ID=1,
+ )
+ import djcelery
+ djcelery.setup_loader()
+
+from django.test.simple import run_tests
+
+def runtests(*test_args):
+ if 'south' in settings.INSTALLED_APPS:
+ from south.management.commands import patch_for_test_db_setup
+ patch_for_test_db_setup()
+
+ if not test_args:
+ test_args = ['debug_toolbar']
+ parent = dirname(abspath(__file__))
+ sys.path.insert(0, parent)
+ failures = run_tests(test_args, verbosity=1, interactive=True)
+ sys.exit(failures)
+
+
+if __name__ == '__main__':
+ runtests(*sys.argv[1:]) \ No newline at end of file
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
diff --git a/setup.py b/setup.py
index 6051fad..6da0cb2 100644
--- a/setup.py
+++ b/setup.py
@@ -12,6 +12,11 @@ setup(
download_url='http://github.com/robhudson/django-debug-toolbar/downloads',
license='BSD',
packages=find_packages(exclude=['ez_setup']),
+ tests_require=[
+ 'django',
+ 'dingus',
+ ],
+ test_suite='debug_toolbar.runtests.runtests',
include_package_data=True,
zip_safe=False, # because we're including media that Django needs
classifiers=[