diff options
| author | Ramiro Morales <cramm0@gmail.com> | 2012-01-05 00:45:31 +0000 |
|---|---|---|
| committer | Ramiro Morales <cramm0@gmail.com> | 2012-01-05 00:45:31 +0000 |
| commit | 8312b85c979c8ddd314abe0a7edb6cb37fe3e3ac (patch) | |
| tree | 888b276d5d3a5fa34daf7f21d404ddb3fcefed68 /tests | |
| parent | bc63ba700a0ae3ba435c267789d8c2e3931016df (diff) | |
Added support for savepoints to the MySQL DB backend.
MySQL provides the savepoint functionality starting with version 5.0.3
when using the MyISAM storage engine.
Thanks lamby for the report and patch.
Fixes #15507.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17341 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/regressiontests/transactions_regress/tests.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/regressiontests/transactions_regress/tests.py b/tests/regressiontests/transactions_regress/tests.py index bdc1b53600..22f1b0f911 100644 --- a/tests/regressiontests/transactions_regress/tests.py +++ b/tests/regressiontests/transactions_regress/tests.py @@ -4,6 +4,7 @@ from django.core.exceptions import ImproperlyConfigured from django.db import connection, transaction from django.db.transaction import commit_on_success, commit_manually, TransactionManagementError from django.test import TransactionTestCase, skipUnlessDBFeature +from django.utils.unittest import skipIf from .models import Mod, M2mA, M2mB @@ -165,6 +166,7 @@ class TestTransactionClosing(TransactionTestCase): except: self.fail("A transaction consisting of a failed operation was not closed.") + class TestManyToManyAddTransaction(TransactionTestCase): def test_manyrelated_add_commit(self): "Test for https://code.djangoproject.com/ticket/16818" @@ -178,3 +180,39 @@ class TestManyToManyAddTransaction(TransactionTestCase): # that the bulk insert was not auto-committed. transaction.rollback() self.assertEqual(a.others.count(), 1) + + +class SavepointTest(TransactionTestCase): + + @skipUnlessDBFeature('uses_savepoints') + def test_savepoint_commit(self): + @commit_manually + def work(): + mod = Mod.objects.create(fld=1) + pk = mod.pk + sid = transaction.savepoint() + mod1 = Mod.objects.filter(pk=pk).update(fld=10) + transaction.savepoint_commit(sid) + mod2 = Mod.objects.get(pk=pk) + transaction.commit() + self.assertEqual(mod2.fld, 10) + + work() + + @skipIf(connection.vendor == 'mysql' and \ + connection.features._mysql_storage_engine() == 'MyISAM', + "MyISAM MySQL storage engine doesn't support savepoints") + @skipUnlessDBFeature('uses_savepoints') + def test_savepoint_rollback(self): + @commit_manually + def work(): + mod = Mod.objects.create(fld=1) + pk = mod.pk + sid = transaction.savepoint() + mod1 = Mod.objects.filter(pk=pk).update(fld=20) + transaction.savepoint_rollback(sid) + mod2 = Mod.objects.get(pk=pk) + transaction.commit() + self.assertEqual(mod2.fld, 1) + + work() |
