diff options
Diffstat (limited to 'tests/contenttypes_tests')
| -rw-r--r-- | tests/contenttypes_tests/test_fields.py | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/tests/contenttypes_tests/test_fields.py b/tests/contenttypes_tests/test_fields.py index ce5e244df5..5638846cc5 100644 --- a/tests/contenttypes_tests/test_fields.py +++ b/tests/contenttypes_tests/test_fields.py @@ -2,14 +2,14 @@ import json from django.contrib.contenttypes.fields import GenericForeignKey from django.db import models -from django.test import SimpleTestCase, TestCase +from django.test import TestCase from django.test.utils import isolate_apps -from .models import Answer, Question +from .models import Answer, Post, Question @isolate_apps('contenttypes_tests') -class GenericForeignKeyTests(SimpleTestCase): +class GenericForeignKeyTests(TestCase): def test_str(self): class Model(models.Model): @@ -24,6 +24,19 @@ class GenericForeignKeyTests(SimpleTestCase): with self.assertRaisesMessage(ValueError, "Custom queryset can't be used for this lookup."): Answer.question.get_prefetch_queryset(Answer.objects.all(), Answer.objects.all()) + def test_get_object_cache_respects_deleted_objects(self): + question = Question.objects.create(text='Who?') + post = Post.objects.create(title='Answer', parent=question) + + question_pk = question.pk + Question.objects.all().delete() + + post = Post.objects.get(pk=post.pk) + with self.assertNumQueries(1): + self.assertEqual(post.object_id, question_pk) + self.assertIsNone(post.parent) + self.assertIsNone(post.parent) + class GenericRelationTests(TestCase): |
