diff options
| author | Bouke Haarsma <bouke@webatoom.nl> | 2013-10-15 17:24:35 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2013-10-16 07:03:46 -0400 |
| commit | 3918eeb9fde03a2ad1941bce022615fff8eae34d (patch) | |
| tree | b5a412d5be750107c9106d56e6d8cf479f65604c /tests | |
| parent | 763ac8b642bc21b5a05c0d540c962804b36454ec (diff) | |
Fixed #7551 -- Made GFK allow None init argument.
Thanks SamBull for the report.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/generic_relations/models.py | 7 | ||||
| -rw-r--r-- | tests/generic_relations/tests.py | 17 |
2 files changed, 23 insertions, 1 deletions
diff --git a/tests/generic_relations/models.py b/tests/generic_relations/models.py index 79eb59fe47..859a17845e 100644 --- a/tests/generic_relations/models.py +++ b/tests/generic_relations/models.py @@ -137,3 +137,10 @@ class ConcreteRelatedModel(models.Model): class ProxyRelatedModel(ConcreteRelatedModel): class Meta: proxy = True + + +# To test fix for #7551 +class AllowsNullGFK(models.Model): + content_type = models.ForeignKey(ContentType, null=True) + object_id = models.PositiveIntegerField(null=True) + content_object = generic.GenericForeignKey() diff --git a/tests/generic_relations/tests.py b/tests/generic_relations/tests.py index dde00ccc8a..6f3f267c5f 100644 --- a/tests/generic_relations/tests.py +++ b/tests/generic_relations/tests.py @@ -4,11 +4,12 @@ from django import forms from django.contrib.contenttypes.generic import generic_inlineformset_factory from django.contrib.contenttypes.models import ContentType from django.test import TestCase +from django.utils import six from .models import (TaggedItem, ValuableTaggedItem, Comparison, Animal, Vegetable, Mineral, Gecko, Rock, ManualPK, ForProxyModelModel, ForConcreteModelModel, - ProxyRelatedModel, ConcreteRelatedModel) + ProxyRelatedModel, ConcreteRelatedModel, AllowsNullGFK) class GenericRelationsTests(TestCase): @@ -440,3 +441,17 @@ class ProxyRelatedModelTest(TestCase): newrel.bases = [base] newrel = ConcreteRelatedModel.objects.get(pk=newrel.pk) self.assertEqual(base, newrel.bases.get()) + + +class TestInitWithNoneArgument(TestCase): + def test_none_not_allowed(self): + # TaggedItem requires a content_type, initializing with None should + # raise a ValueError. + with six.assertRaisesRegex(self, ValueError, + 'Cannot assign None: "TaggedItem.content_type" does not allow null values'): + TaggedItem(content_object=None) + + def test_none_allowed(self): + # AllowsNullGFK doesn't require a content_type, so None argument should + # also be allowed. + AllowsNullGFK(content_object=None) |
