summaryrefslogtreecommitdiff
path: root/tests/model_fields
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2015-07-24 07:51:40 -0400
committerTim Graham <timograham@gmail.com>2015-08-10 08:51:32 -0400
commit5980b05c1fad69eef907e0076aa2dc837edab529 (patch)
tree559858b70445d26700fcf6ef09c655d2fa050557 /tests/model_fields
parent12f91f6ebdd2470197fff4e053b50f3e54294028 (diff)
Fixed #25160 -- Moved unsaved model instance data loss check to Model.save()
This mostly reverts 5643a3b51be338196d0b292d5626ad43648448d3 and 81e1a35c364e5353d2bf99368ad30a4184fbb653. Thanks Carl Meyer for review.
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)