diff options
| author | Anssi Kääriäinen <akaariai@gmail.com> | 2013-09-26 21:16:50 +0300 |
|---|---|---|
| committer | Anssi Kääriäinen <akaariai@gmail.com> | 2013-10-05 23:07:52 +0300 |
| commit | 1df3c49a1a1c11198d181ddd0ce31bbb42e631d8 (patch) | |
| tree | 5a778f559fc9b819466cfeb2d00db40019b27ef1 /tests | |
| parent | 93cc6dcdac6fc3e506640fa38dd1798c3cd61cff (diff) | |
Fixed #21174 -- transaction control in related manager methods
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/many_to_one/tests.py | 7 | ||||
| -rw-r--r-- | tests/multiple_database/tests.py | 11 |
2 files changed, 12 insertions, 6 deletions
diff --git a/tests/many_to_one/tests.py b/tests/many_to_one/tests.py index ae629288b1..6b3a043d68 100644 --- a/tests/many_to_one/tests.py +++ b/tests/many_to_one/tests.py @@ -2,6 +2,7 @@ from copy import deepcopy import datetime from django.core.exceptions import MultipleObjectsReturned, FieldError +from django.db import transaction from django.test import TestCase from django.utils import six from django.utils.translation import ugettext_lazy @@ -68,8 +69,10 @@ class ManyToOneTests(TestCase): self.assertQuerysetEqual(self.r2.article_set.all(), ["<Article: Paul's story>"]) # Adding an object of the wrong type raises TypeError. - with six.assertRaisesRegex(self, TypeError, "'Article' instance expected, got <Reporter.*"): - self.r.article_set.add(self.r2) + with transaction.atomic(): + with six.assertRaisesRegex(self, TypeError, + "'Article' instance expected, got <Reporter.*"): + self.r.article_set.add(self.r2) self.assertQuerysetEqual(self.r.article_set.all(), [ "<Article: John's second story>", diff --git a/tests/multiple_database/tests.py b/tests/multiple_database/tests.py index 191cbaa154..665de2b604 100644 --- a/tests/multiple_database/tests.py +++ b/tests/multiple_database/tests.py @@ -7,7 +7,7 @@ from operator import attrgetter from django.contrib.auth.models import User from django.contrib.contenttypes.models import ContentType from django.core import management -from django.db import connections, router, DEFAULT_DB_ALIAS +from django.db import connections, router, DEFAULT_DB_ALIAS, transaction from django.db.models import signals from django.db.utils import ConnectionRouter from django.test import TestCase @@ -490,21 +490,24 @@ class QueryTestCase(TestCase): # Set a foreign key with an object from a different database try: - dive.editor = marty + with transaction.atomic(using='default'): + dive.editor = marty self.fail("Shouldn't be able to assign across databases") except ValueError: pass # Set a foreign key set with an object from a different database try: - marty.edited = [pro, dive] + with transaction.atomic(using='default'): + marty.edited = [pro, dive] self.fail("Shouldn't be able to assign across databases") except ValueError: pass # Add to a foreign key set with an object from a different database try: - marty.edited.add(dive) + with transaction.atomic(using='default'): + marty.edited.add(dive) self.fail("Shouldn't be able to assign across databases") except ValueError: pass |
