diff options
| author | David Smith <smithdc@gmail.com> | 2020-03-05 21:53:16 +0000 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-03-12 09:36:01 +0100 |
| commit | ccf32aca442feae4c765fb6133c418b4e387f428 (patch) | |
| tree | def50c3b781abe0592615d67c8dc0412dcf25bef /tests/forms_tests | |
| parent | 7d8cdad6b704051bb69a47721913701349463ead (diff) | |
Fixed #8760 -- Changed ModelMultipleChoiceField to use invalid_list as a error message key.
Diffstat (limited to 'tests/forms_tests')
| -rw-r--r-- | tests/forms_tests/tests/test_error_messages.py | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/tests/forms_tests/tests/test_error_messages.py b/tests/forms_tests/tests/test_error_messages.py index 52e436791a..f324c08096 100644 --- a/tests/forms_tests/tests/test_error_messages.py +++ b/tests/forms_tests/tests/test_error_messages.py @@ -7,7 +7,8 @@ from django.forms import ( SplitDateTimeField, TimeField, URLField, ValidationError, utils, ) from django.template import Context, Template -from django.test import SimpleTestCase, TestCase +from django.test import SimpleTestCase, TestCase, ignore_warnings +from django.utils.deprecation import RemovedInDjango40Warning from django.utils.safestring import mark_safe from ..models import ChoiceModel @@ -301,9 +302,30 @@ class ModelChoiceFieldErrorMessagesTestCase(TestCase, AssertFormErrorsMixin): e = { 'required': 'REQUIRED', 'invalid_choice': '%(value)s IS INVALID CHOICE', - 'list': 'NOT A LIST OF VALUES', + 'invalid_list': 'NOT A LIST OF VALUES', } f = ModelMultipleChoiceField(queryset=ChoiceModel.objects.all(), error_messages=e) self.assertFormErrors(['REQUIRED'], f.clean, '') self.assertFormErrors(['NOT A LIST OF VALUES'], f.clean, '3') self.assertFormErrors(['4 IS INVALID CHOICE'], f.clean, ['4']) + + +class DeprecationTests(TestCase, AssertFormErrorsMixin): + @ignore_warnings(category=RemovedInDjango40Warning) + def test_list_error_message(self): + f = ModelMultipleChoiceField( + queryset=ChoiceModel.objects.all(), + error_messages={'list': 'NOT A LIST OF VALUES'}, + ) + self.assertFormErrors(['NOT A LIST OF VALUES'], f.clean, '3') + + def test_list_error_message_warning(self): + msg = ( + "The 'list' error message key is deprecated in favor of " + "'invalid_list'." + ) + with self.assertRaisesMessage(RemovedInDjango40Warning, msg): + ModelMultipleChoiceField( + queryset=ChoiceModel.objects.all(), + error_messages={'list': 'NOT A LIST OF VALUES'}, + ) |
