diff --git a/tests/handlers/tests.py b/tests/handlers/tests.py
index a1fed74..871b65e 100644
|
a
|
b
|
from __future__ import unicode_literals
|
| 4 | 4 | |
| 5 | 5 | from django.core.handlers.wsgi import WSGIHandler, WSGIRequest |
| 6 | 6 | from django.core.signals import request_finished, request_started |
| 7 | | from django.db import close_old_connections, connection |
| | 7 | from django.db import close_old_connections, connection, transaction |
| 8 | 8 | from django.test import ( |
| 9 | 9 | RequestFactory, TestCase, TransactionTestCase, override_settings, |
| 10 | 10 | ) |
| … |
… |
class TransactionsPerRequestTests(TransactionTestCase):
|
| 121 | 121 | old_atomic_requests = connection.settings_dict['ATOMIC_REQUESTS'] |
| 122 | 122 | try: |
| 123 | 123 | connection.settings_dict['ATOMIC_REQUESTS'] = True |
| 124 | | response = self.client.get('/in_transaction/') |
| | 124 | with self.assertNumQueries(1): |
| | 125 | response = self.client.get('/in_transaction/') |
| 125 | 126 | finally: |
| 126 | 127 | connection.settings_dict['ATOMIC_REQUESTS'] = old_atomic_requests |
| 127 | 128 | self.assertContains(response, 'True') |
| … |
… |
class TransactionsPerRequestTests(TransactionTestCase):
|
| 130 | 131 | old_atomic_requests = connection.settings_dict['ATOMIC_REQUESTS'] |
| 131 | 132 | try: |
| 132 | 133 | connection.settings_dict['ATOMIC_REQUESTS'] = True |
| 133 | | response = self.client.get('/not_in_transaction/') |
| | 134 | with self.assertNumQueries(0): |
| | 135 | response = self.client.get('/not_in_transaction/') |
| 134 | 136 | finally: |
| 135 | 137 | connection.settings_dict['ATOMIC_REQUESTS'] = old_atomic_requests |
| 136 | 138 | self.assertContains(response, 'False') |
| 137 | 139 | |
| | 140 | def test_within_existing_transaction(self): |
| | 141 | old_atomic_requests = connection.settings_dict['ATOMIC_REQUESTS'] |
| | 142 | try: |
| | 143 | connection.settings_dict['ATOMIC_REQUESTS'] = True |
| | 144 | with transaction.atomic(): |
| | 145 | # @atomic() opened a transaction, we should not see an extra |
| | 146 | # query. |
| | 147 | with self.assertNumQueries(0): |
| | 148 | response = self.client.get('/in_transaction/') |
| | 149 | finally: |
| | 150 | connection.settings_dict['ATOMIC_REQUESTS'] = old_atomic_requests |
| | 151 | self.assertContains(response, 'True') |
| | 152 | |
| 138 | 153 | |
| 139 | 154 | @override_settings(ROOT_URLCONF='handlers.urls') |
| 140 | 155 | class SignalsTests(TestCase): |