summaryrefslogtreecommitdiff
path: root/tests/contenttypes_tests
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/contenttypes_tests
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/contenttypes_tests')
-rw-r--r--tests/contenttypes_tests/tests.py48
1 files changed, 0 insertions, 48 deletions
diff --git a/tests/contenttypes_tests/tests.py b/tests/contenttypes_tests/tests.py
index 3ff613d9c4..0d0f9d30b8 100644
--- a/tests/contenttypes_tests/tests.py
+++ b/tests/contenttypes_tests/tests.py
@@ -236,54 +236,6 @@ class GenericForeignKeyTests(IsolatedModelsTestCase):
errors = checks.run_checks()
self.assertEqual(errors, ['performed!'])
- def test_unsaved_instance_on_generic_foreign_key(self):
- """
- #10811 -- Assigning an unsaved object to GenericForeignKey
- should raise an exception.
- """
- class Model(models.Model):
- content_type = models.ForeignKey(ContentType, models.SET_NULL, null=True)
- object_id = models.PositiveIntegerField(null=True)
- content_object = GenericForeignKey('content_type', 'object_id')
-
- author = Author(name='Author')
- model = Model()
- model.content_object = None # no error here as content_type allows None
- with self.assertRaisesMessage(ValueError,
- 'Cannot assign "%r": "%s" instance isn\'t saved in the database.'
- % (author, author._meta.object_name)):
- model.content_object = author # raised ValueError here as author is unsaved
-
- author.save()
- model.content_object = author # no error because the instance is saved
-
- def test_unsaved_instance_on_generic_foreign_key_allowed_when_wanted(self):
- """
- #24495 - Assigning an unsaved object to a GenericForeignKey
- should be allowed when the allow_unsaved_instance_assignment
- attribute has been set to True.
- """
- class UnsavedGenericForeignKey(GenericForeignKey):
- # A GenericForeignKey which can point to an unsaved object
- allow_unsaved_instance_assignment = True
-
- class Band(models.Model):
- name = models.CharField(max_length=50)
-
- class BandMember(models.Model):
- band_ct = models.ForeignKey(ContentType, models.CASCADE)
- band_id = models.PositiveIntegerField()
- band = UnsavedGenericForeignKey('band_ct', 'band_id')
- first_name = models.CharField(max_length=50)
- last_name = models.CharField(max_length=50)
-
- beatles = Band(name='The Beatles')
- john = BandMember(first_name='John', last_name='Lennon')
- # This should not raise an exception as the GenericForeignKey between
- # member and band has allow_unsaved_instance_assignment=True.
- john.band = beatles
- self.assertEqual(john.band, beatles)
-
class GenericRelationshipTests(IsolatedModelsTestCase):