diff options
| author | Tim Graham <timograham@gmail.com> | 2015-07-24 07:51:40 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-08-10 08:51:32 -0400 |
| commit | 5980b05c1fad69eef907e0076aa2dc837edab529 (patch) | |
| tree | 559858b70445d26700fcf6ef09c655d2fa050557 /tests/generic_relations/tests.py | |
| parent | 12f91f6ebdd2470197fff4e053b50f3e54294028 (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/generic_relations/tests.py')
| -rw-r--r-- | tests/generic_relations/tests.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/tests/generic_relations/tests.py b/tests/generic_relations/tests.py index 0162565969..c800bd77b0 100644 --- a/tests/generic_relations/tests.py +++ b/tests/generic_relations/tests.py @@ -4,6 +4,7 @@ from django import forms from django.contrib.contenttypes.forms import generic_inlineformset_factory from django.contrib.contenttypes.models import ContentType from django.core.exceptions import FieldError +from django.db import IntegrityError from django.db.models import Q from django.test import SimpleTestCase, TestCase from django.utils import six @@ -486,6 +487,15 @@ class GenericRelationsTests(TestCase): with self.assertRaisesMessage(FieldError, msg): TaggedItem.objects.get(content_object='') + def test_unsaved_instance_on_generic_foreign_key(self): + """ + Assigning an unsaved object to GenericForeignKey should raise an + exception on model.save(). + """ + quartz = Mineral(name="Quartz", hardness=7) + with self.assertRaises(IntegrityError): + TaggedItem.objects.create(tag="shiny", content_object=quartz) + class CustomWidget(forms.TextInput): pass |
