From 8a591b86311c6c19c09b35e5fa3cba75f1d6be3e Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Fri, 18 Oct 2013 08:53:17 +0200 Subject: Add test for issue #348. --- tests/tests.py | 14 +++++++++++++- tests/urls.py | 1 + tests/views.py | 5 +++++ 3 files changed, 19 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/tests.py b/tests/tests.py index 2b26893..a08a9dd 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -9,7 +9,7 @@ from xml.etree import ElementTree as ET import django from django.conf import settings from django.contrib.auth.models import User -from django.db import connection +from django.db import connection, IntegrityError from django.http import HttpResponse from django.test import TestCase, RequestFactory from django.test.utils import override_settings @@ -188,6 +188,18 @@ class DebugToolbarIntegrationTestCase(TestCase): response = self.client.get('/regular/XML/') ET.fromstring(response.content) # shouldn't raise ParseError + def test_view_executed_once(self): + with self.settings(DEBUG=True, INTERNAL_IPS=['127.0.0.1'], + 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): + response = self.client.get('/new_user/') + self.assertEqual(User.objects.count(), 1) class DebugToolbarNameFromObjectTest(BaseTestCase): diff --git a/tests/urls.py b/tests/urls.py index 562ebd2..4bed492 100644 --- a/tests/urls.py +++ b/tests/urls.py @@ -23,5 +23,6 @@ urlpatterns = patterns('tests.views', url(r'^regular/(?P