diff options
| author | Aymeric Augustin | 2013-10-18 08:53:17 +0200 | 
|---|---|---|
| committer | Aymeric Augustin | 2013-10-18 23:16:10 +0200 | 
| commit | 8a591b86311c6c19c09b35e5fa3cba75f1d6be3e (patch) | |
| tree | b210f6d903ed3e08bb3436a482523c4a4c276ca6 /tests | |
| parent | d112cc5ed14fa97eb187aa7f0b38318ea03d77dc (diff) | |
| download | django-debug-toolbar-8a591b86311c6c19c09b35e5fa3cba75f1d6be3e.tar.bz2 | |
Add test for issue #348.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/tests.py | 14 | ||||
| -rw-r--r-- | tests/urls.py | 1 | ||||
| -rw-r--r-- | tests/views.py | 5 | 
3 files changed, 19 insertions, 1 deletions
| 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<title>.*)/$', 'regular_view'),      url(r'^non_ascii_context/$', 'non_ascii_context'),      url(r'^non_ascii_request/$', 'regular_view', {'title': NonAsciiRepr()}), +    url(r'^new_user/$', 'new_user'),      url(r'^execute_sql/$', 'execute_sql'),  ) diff --git a/tests/views.py b/tests/views.py index 2fba2a7..e6d9ebb 100644 --- a/tests/views.py +++ b/tests/views.py @@ -23,6 +23,11 @@ def regular_view(request, title):      return render(request, 'basic.html', {'title': title}) +def new_user(request): +    User.objects.create_user(username='joe') +    return render(request, 'basic.html', {'title': 'new user'}) + +  def resolving_view(request, arg1, arg2):      # see test_url_resolving in tests.py      return HttpResponse() | 
