1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

Avoided transaction.set_autocommit in tests.

It doesn't work as one might expect on a certain database backend where
autocommits_when_autocommit_is_off = True. That backend happens to be
popular for running tests.

Backport of 38bc581bc0 from master.
This commit is contained in:
Aymeric Augustin
2013-07-09 21:12:51 +02:00
parent ae685e54cb
commit d200405471
3 changed files with 21 additions and 49 deletions

View File

@@ -660,22 +660,15 @@ class TestTicket11101(TransactionTestCase):
'django.contrib.contenttypes',
]
def ticket_11101(self):
management.call_command(
'loaddata',
'thingy.json',
verbosity=0,
)
self.assertEqual(Thingy.objects.count(), 1)
transaction.rollback()
self.assertEqual(Thingy.objects.count(), 0)
transaction.commit()
@skipUnlessDBFeature('supports_transactions')
def test_ticket_11101(self):
"""Test that fixtures can be rolled back (ticket #11101)."""
transaction.set_autocommit(False)
try:
self.ticket_11101()
finally:
transaction.set_autocommit(True)
with transaction.atomic():
management.call_command(
'loaddata',
'thingy.json',
verbosity=0,
)
self.assertEqual(Thingy.objects.count(), 1)
transaction.set_rollback(True)
self.assertEqual(Thingy.objects.count(), 0)