diff options
| author | Aymeric Augustin | 2013-11-01 21:51:37 +0100 |
|---|---|---|
| committer | Aymeric Augustin | 2013-11-01 21:51:37 +0100 |
| commit | 96f1cb4b0d4b10903502e917ddaa460bc05f5ca3 (patch) | |
| tree | 2d72e912b523f498f7e1c82aad362d5e6a58f396 /tests/commands/test_debugsqlshell.py | |
| parent | f69f51f7abf25aaf5282c953475e8975694f41c1 (diff) | |
| download | django-debug-toolbar-96f1cb4b0d4b10903502e917ddaa460bc05f5ca3.tar.bz2 | |
Split tests across several modules.
Fix #426.
Diffstat (limited to 'tests/commands/test_debugsqlshell.py')
| -rw-r--r-- | tests/commands/test_debugsqlshell.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/commands/test_debugsqlshell.py b/tests/commands/test_debugsqlshell.py new file mode 100644 index 0000000..f35ef07 --- /dev/null +++ b/tests/commands/test_debugsqlshell.py @@ -0,0 +1,34 @@ +from __future__ import unicode_literals + +import sys + +from django.contrib.auth.models import User +from django.core import management +from django.db.backends import util +from django.test import TestCase +from django.test.utils import override_settings +from django.utils import six + + +@override_settings(DEBUG=True) +class DebugSQLShellTestCase(TestCase): + + def setUp(self): + self.original_cursor_wrapper = util.CursorDebugWrapper + # Since debugsqlshell monkey-patches django.db.backends.util, we can + # test it simply by loading it, without executing it. But we have to + # undo the monkey-patch on exit. + command_name = 'debugsqlshell' + app_name = management.get_commands()[command_name] + management.load_command_class(app_name, command_name) + + def tearDown(self): + util.CursorDebugWrapper = self.original_cursor_wrapper + + def test_command(self): + original_stdout, sys.stdout = sys.stdout, six.StringIO() + try: + User.objects.count() + self.assertIn("SELECT COUNT(*)", sys.stdout.getvalue()) + finally: + sys.stdout = original_stdout |
