mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Deprecated TransactionMiddleware and TRANSACTIONS_MANAGED.
Replaced them with per-database options, for proper multi-db support. Also toned down the recommendation to tie transactions to HTTP requests. Thanks Jeremy for sharing his experience.
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
from django.core.handlers.wsgi import WSGIHandler
|
||||
from django.core.signals import request_started, request_finished
|
||||
from django.db import close_old_connections
|
||||
from django.test import RequestFactory, TestCase
|
||||
from django.db import close_old_connections, connection
|
||||
from django.test import RequestFactory, TestCase, TransactionTestCase
|
||||
from django.test.utils import override_settings
|
||||
from django.utils import six
|
||||
|
||||
|
||||
class HandlerTests(TestCase):
|
||||
@@ -37,6 +36,31 @@ class HandlerTests(TestCase):
|
||||
self.assertEqual(response.status_code, 400)
|
||||
|
||||
|
||||
class TransactionsPerRequestTests(TransactionTestCase):
|
||||
urls = 'handlers.urls'
|
||||
|
||||
def test_no_transaction(self):
|
||||
response = self.client.get('/in_transaction/')
|
||||
self.assertContains(response, 'False')
|
||||
|
||||
def test_auto_transaction(self):
|
||||
old_atomic_requests = connection.settings_dict['ATOMIC_REQUESTS']
|
||||
try:
|
||||
connection.settings_dict['ATOMIC_REQUESTS'] = True
|
||||
response = self.client.get('/in_transaction/')
|
||||
finally:
|
||||
connection.settings_dict['ATOMIC_REQUESTS'] = old_atomic_requests
|
||||
self.assertContains(response, 'True')
|
||||
|
||||
def test_no_auto_transaction(self):
|
||||
old_atomic_requests = connection.settings_dict['ATOMIC_REQUESTS']
|
||||
try:
|
||||
connection.settings_dict['ATOMIC_REQUESTS'] = True
|
||||
response = self.client.get('/not_in_transaction/')
|
||||
finally:
|
||||
connection.settings_dict['ATOMIC_REQUESTS'] = old_atomic_requests
|
||||
self.assertContains(response, 'False')
|
||||
|
||||
class SignalsTests(TestCase):
|
||||
urls = 'handlers.urls'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user