summaryrefslogtreecommitdiff
path: root/tests/model_fields
diff options
context:
space:
mode:
Diffstat (limited to 'tests/model_fields')
-rw-r--r--tests/model_fields/test_uuid.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/tests/model_fields/test_uuid.py b/tests/model_fields/test_uuid.py
index bef1d54a74..343140c248 100644
--- a/tests/model_fields/test_uuid.py
+++ b/tests/model_fields/test_uuid.py
@@ -2,8 +2,10 @@ import json
import uuid
from django.core import exceptions, serializers
-from django.db import models
-from django.test import SimpleTestCase, TestCase
+from django.db import IntegrityError, models
+from django.test import (
+ SimpleTestCase, TestCase, TransactionTestCase, skipUnlessDBFeature,
+)
from .models import (
NullableUUIDModel, PrimaryKeyUUIDModel, RelatedToUUIDModel, UUIDGrandchild,
@@ -158,3 +160,14 @@ class TestAsPrimaryKey(TestCase):
def test_two_level_foreign_keys(self):
# exercises ForeignKey.get_db_prep_value()
UUIDGrandchild().save()
+
+
+class TestAsPrimaryKeyTransactionTests(TransactionTestCase):
+ # Need a TransactionTestCase to avoid deferring FK constraint checking.
+ available_apps = ['model_fields']
+
+ @skipUnlessDBFeature('supports_foreign_keys')
+ def test_unsaved_fk(self):
+ u1 = PrimaryKeyUUIDModel()
+ with self.assertRaises(IntegrityError):
+ RelatedToUUIDModel.objects.create(uuid_fk=u1)