blob: 6a7823ec71eddbe0925b4136741aee55d4e72620 (
plain)
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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)
 |