mirror of
https://github.com/Hopiu/django-cachalot.git
synced 2026-05-16 08:33:11 +00:00
Tests errors during the end of a transaction (see #87).
This commit is contained in:
parent
5ca8a6bb9f
commit
366176b764
1 changed files with 22 additions and 2 deletions
|
|
@ -3,8 +3,8 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.db import transaction
|
||||
from django.test import TransactionTestCase
|
||||
from django.db import transaction, connection, IntegrityError
|
||||
from django.test import TransactionTestCase, skipUnlessDBFeature
|
||||
|
||||
from .models import Test
|
||||
from .test_utils import TestUtilsMixin
|
||||
|
|
@ -171,3 +171,23 @@ class AtomicTestCase(TestUtilsMixin, TransactionTestCase):
|
|||
with self.assertNumQueries(1):
|
||||
data3 = list(Test.objects.all())
|
||||
self.assertListEqual(data3, [t1])
|
||||
|
||||
@skipUnlessDBFeature('can_defer_constraint_checks')
|
||||
def test_deferred_error(self):
|
||||
"""
|
||||
Checks that an error occurring during the end of a transaction
|
||||
has no impact on future queries.
|
||||
"""
|
||||
with connection.cursor() as cursor:
|
||||
cursor.execute(
|
||||
'CREATE TABLE example ('
|
||||
'id int UNIQUE DEFERRABLE INITIALLY DEFERRED);')
|
||||
with self.assertRaises(IntegrityError):
|
||||
with transaction.atomic():
|
||||
with self.assertNumQueries(1):
|
||||
list(Test.objects.all())
|
||||
cursor.execute(
|
||||
'INSERT INTO example VALUES (1), (1);'
|
||||
'-- ' + Test._meta.db_table) # Should invalidate Test.
|
||||
with self.assertNumQueries(1):
|
||||
list(Test.objects.all())
|
||||
|
|
|
|||
Loading…
Reference in a new issue