From a29bbc7cfcef52af29960f2a2f3d53e9c0b0015d Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Sat, 9 Nov 2013 19:50:08 +0100 Subject: Move a test specific to the profiling panel in its module. --- tests/panels/test_profiling.py | 29 +++++++++++++++++++++++++++++ tests/test_integration.py | 20 -------------------- tests/tests.py | 1 + 3 files changed, 30 insertions(+), 20 deletions(-) create mode 100644 tests/panels/test_profiling.py (limited to 'tests') diff --git a/tests/panels/test_profiling.py b/tests/panels/test_profiling.py new file mode 100644 index 0000000..6a7823e --- /dev/null +++ b/tests/panels/test_profiling.py @@ -0,0 +1,29 @@ +from __future__ import unicode_literals + +from django.contrib.auth.models import User +from django.db import IntegrityError, transaction +from django.test import TestCase +from django.test.utils import override_settings + + +@override_settings(DEBUG=True, + DEBUG_TOOLBAR_PANELS=['debug_toolbar.panels.profiling.ProfilingDebugPanel']) +class ProfilingPanelIntegrationTestCase(TestCase): + + urls = 'tests.urls' + + def test_view_executed_once(self): + + self.assertEqual(User.objects.count(), 0) + + response = self.client.get('/new_user/') + self.assertContains(response, 'Profiling') + self.assertEqual(User.objects.count(), 1) + + with self.assertRaises(IntegrityError): + if hasattr(transaction, 'atomic'): # Django >= 1.6 + with transaction.atomic(): + response = self.client.get('/new_user/') + else: + response = self.client.get('/new_user/') + self.assertEqual(User.objects.count(), 1) diff --git a/tests/test_integration.py b/tests/test_integration.py index 875efbe..e661467 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -4,8 +4,6 @@ from __future__ import unicode_literals from xml.etree import ElementTree as ET -from django.contrib.auth.models import User -from django.db import IntegrityError, transaction from django.test import TestCase, RequestFactory from django.test.utils import override_settings from django.utils import six @@ -158,21 +156,3 @@ class DebugToolbarIntegrationTestCase(TestCase): def test_xml_validation(self): response = self.client.get('/regular/XML/') ET.fromstring(response.content) # shouldn't raise ParseError - - def test_view_executed_once(self): - with self.settings( - DEBUG_TOOLBAR_PANELS=['debug_toolbar.panels.profiling.ProfilingDebugPanel']): - - self.assertEqual(User.objects.count(), 0) - - response = self.client.get('/new_user/') - self.assertContains(response, 'Profiling') - self.assertEqual(User.objects.count(), 1) - - with self.assertRaises(IntegrityError): - if hasattr(transaction, 'atomic'): # Django >= 1.6 - with transaction.atomic(): - response = self.client.get('/new_user/') - else: - response = self.client.get('/new_user/') - self.assertEqual(User.objects.count(), 1) diff --git a/tests/tests.py b/tests/tests.py index 10e0a9b..1059902 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -3,6 +3,7 @@ import django if django.VERSION[:2] < (1, 6): # unittest-style discovery isn't available from .commands.test_debugsqlshell import * # noqa from .panels.test_logger import * # noqa + from .panels.test_profiling import * # noqa from .panels.test_sql import * # noqa from .panels.test_template import * # noqa from .test_integration import * # noqa -- cgit v1.2.3