summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLoic Bistuer <loic.bistuer@gmail.com>2014-03-30 01:57:28 +0700
committerLoic Bistuer <loic.bistuer@gmail.com>2014-03-30 12:13:00 +0700
commitbc9be72bdc9bb4dfc7f967ac3856115f0a6166b8 (patch)
tree04a4a68821d1ba243f4ad7841ebc80da400f591a /tests
parent975337e5c348a770df5a1925ce256ab54cb8c529 (diff)
Fixed transaction handling for a number of operations on related objects.
Thanks Anssi and Aymeric for the reviews. Refs #21174.
Diffstat (limited to 'tests')
-rw-r--r--tests/many_to_many/tests.py5
-rw-r--r--tests/multiple_database/tests.py15
2 files changed, 14 insertions, 6 deletions
diff --git a/tests/many_to_many/tests.py b/tests/many_to_many/tests.py
index 4293fc0c42..545d50a90e 100644
--- a/tests/many_to_many/tests.py
+++ b/tests/many_to_many/tests.py
@@ -1,5 +1,6 @@
from __future__ import unicode_literals
+from django.db import transaction
from django.test import TestCase
from django.utils import six
@@ -54,7 +55,9 @@ class ManyToManyTests(TestCase):
# Adding an object of the wrong type raises TypeError
with six.assertRaisesRegex(self, TypeError, "'Publication' instance expected, got <Article.*"):
- a6.publications.add(a5)
+ with transaction.atomic():
+ a6.publications.add(a5)
+
# Add a Publication directly via publications.add by using keyword arguments.
a6.publications.create(title='Highlights for Adults')
self.assertQuerysetEqual(a6.publications.all(),
diff --git a/tests/multiple_database/tests.py b/tests/multiple_database/tests.py
index cf225dbf36..01c6e1ef15 100644
--- a/tests/multiple_database/tests.py
+++ b/tests/multiple_database/tests.py
@@ -295,19 +295,23 @@ class QueryTestCase(TestCase):
# Add to an m2m with an object from a different database
with self.assertRaises(ValueError):
- marty.book_set.add(dive)
+ with transaction.atomic(using='default'):
+ marty.book_set.add(dive)
# Set a m2m with an object from a different database
with self.assertRaises(ValueError):
- marty.book_set = [pro, dive]
+ with transaction.atomic(using='default'):
+ marty.book_set = [pro, dive]
# Add to a reverse m2m with an object from a different database
with self.assertRaises(ValueError):
- dive.authors.add(marty)
+ with transaction.atomic(using='other'):
+ dive.authors.add(marty)
# Set a reverse m2m with an object from a different database
with self.assertRaises(ValueError):
- dive.authors = [mark, marty]
+ with transaction.atomic(using='other'):
+ dive.authors = [mark, marty]
def test_m2m_deletion(self):
"Cascaded deletions of m2m relations issue queries on the right database"
@@ -762,7 +766,8 @@ class QueryTestCase(TestCase):
# Add to a foreign key set with an object from a different database
with self.assertRaises(ValueError):
- dive.reviews.add(review1)
+ with transaction.atomic(using='other'):
+ dive.reviews.add(review1)
# BUT! if you assign a FK object when the base object hasn't
# been saved yet, you implicitly assign the database for the