summaryrefslogtreecommitdiff
path: root/tests/regressiontests/requests/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/regressiontests/requests/tests.py')
-rw-r--r--tests/regressiontests/requests/tests.py18
1 files changed, 10 insertions, 8 deletions
diff --git a/tests/regressiontests/requests/tests.py b/tests/regressiontests/requests/tests.py
index d89f6d68be..84928f39ba 100644
--- a/tests/regressiontests/requests/tests.py
+++ b/tests/regressiontests/requests/tests.py
@@ -548,9 +548,6 @@ class TransactionRequestTests(TransactionTestCase):
'This test will close the connection, in-memory '
'sqlite connections must not be closed.')
def test_request_finished_failed_connection(self):
- # See comments in test_request_finished_db_state() for the self.client
- # usage.
- response = self.client.get('/')
conn = connections[DEFAULT_DB_ALIAS]
conn.enter_transaction_management()
conn.managed(True)
@@ -560,9 +557,14 @@ class TransactionRequestTests(TransactionTestCase):
def fail_horribly():
raise Exception("Horrible failure!")
conn._rollback = fail_horribly
- signals.request_finished.send(sender=response._handler_class)
- # As even rollback wasn't possible the connection wrapper itself was
- # abandoned. Accessing the connections[alias] will create a new
- # connection wrapper, whch must be different than the original one.
- self.assertIsNot(conn, connections[DEFAULT_DB_ALIAS])
+ try:
+ with self.assertRaises(Exception):
+ signals.request_finished.send(sender=self.__class__)
+ # The connection's state wasn't cleaned up
+ self.assertTrue(len(connection.transaction_state), 1)
+ finally:
+ del conn._rollback
+ # The connection will be cleaned on next request where the conn
+ # works again.
+ signals.request_finished.send(sender=self.__class__)
self.assertEqual(len(connection.transaction_state), 0)