summaryrefslogtreecommitdiff
path: root/tests/model_forms
diff options
context:
space:
mode:
Diffstat (limited to 'tests/model_forms')
-rw-r--r--tests/model_forms/test_modelchoicefield.py8
-rw-r--r--tests/model_forms/tests.py9
2 files changed, 16 insertions, 1 deletions
diff --git a/tests/model_forms/test_modelchoicefield.py b/tests/model_forms/test_modelchoicefield.py
index 19e9db69a0..83d801768a 100644
--- a/tests/model_forms/test_modelchoicefield.py
+++ b/tests/model_forms/test_modelchoicefield.py
@@ -7,7 +7,7 @@ from django.forms.widgets import CheckboxSelectMultiple
from django.template import Context, Template
from django.test import TestCase
-from .models import Article, Author, Book, Category, Writer
+from .models import Article, Author, Book, Category, ExplicitPK, Writer
class ModelChoiceFieldTests(TestCase):
@@ -79,6 +79,12 @@ class ModelChoiceFieldTests(TestCase):
self.assertEqual(f.clean(self.c1.slug), self.c1)
self.assertEqual(f.clean(self.c1), self.c1)
+ def test_model_choice_null_characters(self):
+ f = forms.ModelChoiceField(queryset=ExplicitPK.objects.all())
+ msg = "Null characters are not allowed."
+ with self.assertRaisesMessage(ValidationError, msg):
+ f.clean("\x00something")
+
def test_choices(self):
f = forms.ModelChoiceField(
Category.objects.filter(pk=self.c1.id), required=False
diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py
index 3f927cb053..c6e12e1aab 100644
--- a/tests/model_forms/tests.py
+++ b/tests/model_forms/tests.py
@@ -2227,6 +2227,15 @@ class ModelMultipleChoiceFieldTests(TestCase):
f = forms.ModelMultipleChoiceField(queryset=Writer.objects.all())
self.assertNumQueries(1, f.clean, [p.pk for p in persons[1:11:2]])
+ def test_model_multiple_choice_null_characters(self):
+ f = forms.ModelMultipleChoiceField(queryset=ExplicitPK.objects.all())
+ msg = "Null characters are not allowed."
+ with self.assertRaisesMessage(ValidationError, msg):
+ f.clean(["\x00something"])
+
+ with self.assertRaisesMessage(ValidationError, msg):
+ f.clean(["valid", "\x00something"])
+
def test_model_multiple_choice_run_validators(self):
"""
ModelMultipleChoiceField run given validators (#14144).