Last active
December 20, 2015 15:59
-
-
Save loic/6158578 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/tests/model_forms/models.py b/tests/model_forms/models.py | |
| index a4cf947..17aec29 100644 | |
| --- a/tests/model_forms/models.py | |
| +++ b/tests/model_forms/models.py | |
| @@ -12,7 +12,7 @@ import os | |
| import tempfile | |
| from django.core import validators | |
| -from django.core.exceptions import ImproperlyConfigured | |
| +from django.core.exceptions import ImproperlyConfigured, ValidationError | |
| from django.core.files.storage import FileSystemStorage | |
| from django.db import models | |
| from django.utils import six | |
| @@ -296,3 +296,7 @@ class CustomErrorMessage(models.Model): | |
| name2 = models.CharField(max_length=50, | |
| validators=[validators.validate_slug], | |
| error_messages={'invalid': 'Model custom error message.'}) | |
| + | |
| + def clean(self): | |
| + if self.name1 == 'FORBIDDEN_VALUE': | |
| + raise ValidationError({'name1': [ValidationError('Model.clean() error messages.')]}) | |
| diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py | |
| index 21e3143..1404725 100644 | |
| --- a/tests/model_forms/tests.py | |
| +++ b/tests/model_forms/tests.py | |
| @@ -1782,6 +1782,14 @@ class OldFormForXTests(TestCase): | |
| '<ul class="errorlist"><li>Model custom error message.</li></ul>' | |
| ) | |
| + def test_model_clean_error_messages(self) : | |
| + data = {'name1': 'FORBIDDEN_VALUE', 'name2': 'ABC'} | |
| + errors = CustomErrorMessageForm(data).errors | |
| + self.assertHTMLEqual( | |
| + str(errors['name1']), | |
| + '<ul class="errorlist"><li>Model.clean() error messages.</li></ul>' | |
| + ) | |
| + | |
| class M2mHelpTextTest(TestCase): | |
| """Tests for ticket #9321.""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment