Skip to content

Commit a29bbc7

Browse files
committed
Move a test specific to the profiling panel in its module.
1 parent b8d3c1c commit a29bbc7

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

tests/panels/test_profiling.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from __future__ import unicode_literals
2+
3+
from django.contrib.auth.models import User
4+
from django.db import IntegrityError, transaction
5+
from django.test import TestCase
6+
from django.test.utils import override_settings
7+
8+
9+
@override_settings(DEBUG=True,
10+
DEBUG_TOOLBAR_PANELS=['debug_toolbar.panels.profiling.ProfilingDebugPanel'])
11+
class ProfilingPanelIntegrationTestCase(TestCase):
12+
13+
urls = 'tests.urls'
14+
15+
def test_view_executed_once(self):
16+
17+
self.assertEqual(User.objects.count(), 0)
18+
19+
response = self.client.get('/new_user/')
20+
self.assertContains(response, 'Profiling')
21+
self.assertEqual(User.objects.count(), 1)
22+
23+
with self.assertRaises(IntegrityError):
24+
if hasattr(transaction, 'atomic'): # Django >= 1.6
25+
with transaction.atomic():
26+
response = self.client.get('/new_user/')
27+
else:
28+
response = self.client.get('/new_user/')
29+
self.assertEqual(User.objects.count(), 1)

tests/test_integration.py

-20
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
from xml.etree import ElementTree as ET
66

7-
from django.contrib.auth.models import User
8-
from django.db import IntegrityError, transaction
97
from django.test import TestCase, RequestFactory
108
from django.test.utils import override_settings
119
from django.utils import six
@@ -158,21 +156,3 @@ def test_object_with_non_ascii_repr_in_request_vars(self):
158156
def test_xml_validation(self):
159157
response = self.client.get('/regular/XML/')
160158
ET.fromstring(response.content) # shouldn't raise ParseError
161-
162-
def test_view_executed_once(self):
163-
with self.settings(
164-
DEBUG_TOOLBAR_PANELS=['debug_toolbar.panels.profiling.ProfilingDebugPanel']):
165-
166-
self.assertEqual(User.objects.count(), 0)
167-
168-
response = self.client.get('/new_user/')
169-
self.assertContains(response, 'Profiling')
170-
self.assertEqual(User.objects.count(), 1)
171-
172-
with self.assertRaises(IntegrityError):
173-
if hasattr(transaction, 'atomic'): # Django >= 1.6
174-
with transaction.atomic():
175-
response = self.client.get('/new_user/')
176-
else:
177-
response = self.client.get('/new_user/')
178-
self.assertEqual(User.objects.count(), 1)

tests/tests.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
if django.VERSION[:2] < (1, 6): # unittest-style discovery isn't available
44
from .commands.test_debugsqlshell import * # noqa
55
from .panels.test_logger import * # noqa
6+
from .panels.test_profiling import * # noqa
67
from .panels.test_sql import * # noqa
78
from .panels.test_template import * # noqa
89
from .test_integration import * # noqa

0 commit comments

Comments
 (0)