summaryrefslogtreecommitdiff
path: root/tests/get_or_create
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2013-04-28 17:15:41 +0200
committerAymeric Augustin <aymeric.augustin@m4x.org>2013-04-28 17:15:41 +0200
commit3a4276ffc35326f20e95890b50a67aebeabc9ad0 (patch)
treeccc956de9845c00e25e45409abfd29a06e62703f /tests/get_or_create
parent90fe9141ded9f7005546e9a66f31fd196f60e7e4 (diff)
downloaddjango-3a4276ffc35326f20e95890b50a67aebeabc9ad0.tar.gz
Tested that get_or_create raises IntegrityError.
It used to raise "DatabaseError: no such savepoint" with the old transaction management. Closes #15117.
Diffstat (limited to 'tests/get_or_create')
-rw-r--r--tests/get_or_create/models.py4
-rw-r--r--tests/get_or_create/tests.py17
2 files changed, 19 insertions, 2 deletions
diff --git a/tests/get_or_create/models.py b/tests/get_or_create/models.py
index 678f5a401c..82905de4f8 100644
--- a/tests/get_or_create/models.py
+++ b/tests/get_or_create/models.py
@@ -24,3 +24,7 @@ class Person(models.Model):
class ManualPrimaryKeyTest(models.Model):
id = models.IntegerField(primary_key=True)
data = models.CharField(max_length=100)
+
+
+class Profile(models.Model):
+ person = models.ForeignKey(Person, primary_key=True)
diff --git a/tests/get_or_create/tests.py b/tests/get_or_create/tests.py
index 1e300fbb4d..e9cce9bbde 100644
--- a/tests/get_or_create/tests.py
+++ b/tests/get_or_create/tests.py
@@ -4,9 +4,9 @@ from datetime import date
import traceback
from django.db import IntegrityError
-from django.test import TestCase
+from django.test import TestCase, TransactionTestCase
-from .models import Person, ManualPrimaryKeyTest
+from .models import Person, ManualPrimaryKeyTest, Profile
class GetOrCreateTests(TestCase):
@@ -64,3 +64,16 @@ class GetOrCreateTests(TestCase):
formatted_traceback = traceback.format_exc()
self.assertIn('obj.save', formatted_traceback)
+
+class GetOrCreateTransactionTests(TransactionTestCase):
+
+ def test_get_or_create_integrityerror(self):
+ # Regression test for #15117. Requires a TransactionTestCase on
+ # databases that delay integrity checks until the end of transactions,
+ # otherwise the exception is never raised.
+ try:
+ Profile.objects.get_or_create(person=Person(id=1))
+ except IntegrityError:
+ pass
+ else:
+ self.skipTest("This backend does not support integrity checks.")