|
2 | 2 |
|
3 | 3 | from django.conf import settings
|
4 | 4 | from django.contrib.auth.models import User
|
| 5 | +from django.db import connection |
5 | 6 | from django.http import HttpResponse
|
6 | 7 | from django.test import TestCase, RequestFactory
|
7 | 8 | from django.template import Template, Context
|
| 9 | +from django.utils import unittest |
8 | 10 |
|
9 | 11 | from debug_toolbar.middleware import DebugToolbarMiddleware
|
10 | 12 | from debug_toolbar.panels.sql import SQLDebugPanel
|
@@ -214,6 +216,19 @@ def test_recording(self):
|
214 | 216 | # ensure the stacktrace is populated
|
215 | 217 | self.assertTrue(len(query[1]['stacktrace']) > 0)
|
216 | 218 |
|
| 219 | + @unittest.skipUnless(connection.vendor=='postgresql', |
| 220 | + 'Test valid only on PostgreSQL') |
| 221 | + def test_erroneous_query(self): |
| 222 | + """ |
| 223 | + Test that an error in the query isn't swallowed by the middleware. |
| 224 | + """ |
| 225 | + from django.db import connection |
| 226 | + from django.db.utils import DatabaseError |
| 227 | + try: |
| 228 | + connection.cursor().execute("erroneous query") |
| 229 | + except DatabaseError as e: |
| 230 | + self.assertTrue('erroneous query' in str(e)) |
| 231 | + |
217 | 232 | def test_disable_stacktraces(self):
|
218 | 233 | panel = self.toolbar.get_panel(SQLDebugPanel)
|
219 | 234 | self.assertEquals(len(panel._queries), 0)
|
|
0 commit comments