diff options
| author | François Freitag <mail@franek.fr> | 2020-02-12 14:48:49 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-04-28 10:49:00 +0200 |
| commit | 9ef4a18dbe71f538a9ef8c39111ae2f0b62eb90b (patch) | |
| tree | 0016b13a357af2f642483bdd168d6f83190f33bb /tests | |
| parent | 2788de95e375cccd03a3dfd161fc92b7d6df6024 (diff) | |
Changed django.forms.ValidationError imports to django.core.exceptions.ValidationError.
Co-Authored-By: Mariusz Felisiak <felisiak.mariusz@gmail.com>
Diffstat (limited to 'tests')
36 files changed, 124 insertions, 103 deletions
diff --git a/tests/admin_inlines/admin.py b/tests/admin_inlines/admin.py index 72a32e4d17..5c968870e4 100644 --- a/tests/admin_inlines/admin.py +++ b/tests/admin_inlines/admin.py @@ -1,5 +1,6 @@ from django import forms from django.contrib import admin +from django.core.exceptions import ValidationError from django.db import models from .models import ( @@ -102,7 +103,7 @@ class TitleForm(forms.ModelForm): title1 = cleaned_data.get("title1") title2 = cleaned_data.get("title2") if title1 != title2: - raise forms.ValidationError("The two titles must be the same") + raise ValidationError("The two titles must be the same") return cleaned_data diff --git a/tests/admin_views/admin.py b/tests/admin_views/admin.py index beec6f80f4..44623e483f 100644 --- a/tests/admin_views/admin.py +++ b/tests/admin_views/admin.py @@ -223,7 +223,7 @@ class BasePersonModelFormSet(BaseModelFormSet): person = person_dict.get('id') alive = person_dict.get('alive') if person and alive and person.name == "Grace Hopper": - raise forms.ValidationError("Grace is not a Zombie") + raise ValidationError("Grace is not a Zombie") class PersonAdmin(admin.ModelAdmin): diff --git a/tests/admin_views/custom_has_permission_admin.py b/tests/admin_views/custom_has_permission_admin.py index 0c774ef573..354f6a2418 100644 --- a/tests/admin_views/custom_has_permission_admin.py +++ b/tests/admin_views/custom_has_permission_admin.py @@ -4,6 +4,7 @@ A custom AdminSite for AdminViewPermissionsTest.test_login_has_permission(). from django.contrib import admin from django.contrib.auth import get_permission_codename from django.contrib.auth.forms import AuthenticationForm +from django.core.exceptions import ValidationError from . import admin as base_admin, models @@ -12,9 +13,8 @@ PERMISSION_NAME = 'admin_views.%s' % get_permission_codename('change', models.Ar class PermissionAdminAuthenticationForm(AuthenticationForm): def confirm_login_allowed(self, user): - from django import forms if not user.is_active or not (user.is_staff or user.has_perm(PERMISSION_NAME)): - raise forms.ValidationError('permission denied') + raise ValidationError('permission denied') class HasPermissionAdmin(admin.AdminSite): diff --git a/tests/admin_views/forms.py b/tests/admin_views/forms.py index cceb543c41..b25e49246a 100644 --- a/tests/admin_views/forms.py +++ b/tests/admin_views/forms.py @@ -1,6 +1,6 @@ -from django import forms from django.contrib.admin.forms import AdminAuthenticationForm from django.contrib.admin.helpers import ActionForm +from django.core.exceptions import ValidationError class CustomAdminAuthenticationForm(AdminAuthenticationForm): @@ -11,7 +11,7 @@ class CustomAdminAuthenticationForm(AdminAuthenticationForm): def clean_username(self): username = self.cleaned_data.get('username') if username == 'customform': - raise forms.ValidationError('custom form error') + raise ValidationError('custom form error') return username diff --git a/tests/auth_tests/test_forms.py b/tests/auth_tests/test_forms.py index 4e5f8e3094..88b4b32667 100644 --- a/tests/auth_tests/test_forms.py +++ b/tests/auth_tests/test_forms.py @@ -2,7 +2,6 @@ import datetime import re from unittest import mock -from django import forms from django.contrib.auth.forms import ( AdminPasswordChangeForm, AuthenticationForm, PasswordChangeForm, PasswordResetForm, ReadOnlyPasswordHashField, ReadOnlyPasswordHashWidget, @@ -12,6 +11,7 @@ from django.contrib.auth.models import User from django.contrib.auth.signals import user_login_failed from django.contrib.sites.models import Site from django.core import mail +from django.core.exceptions import ValidationError from django.core.mail import EmailMultiAlternatives from django.forms.fields import CharField, Field, IntegerField from django.test import SimpleTestCase, TestCase, override_settings @@ -372,13 +372,13 @@ class AuthenticationFormTest(TestDataMixin, TestCase): form = AuthenticationFormWithInactiveUsersOkay(None, data) self.assertTrue(form.is_valid()) - # If we want to disallow some logins according to custom logic, - # we should raise a django.forms.ValidationError in the form. + # Raise a ValidationError in the form to disallow some logins according + # to custom logic. class PickyAuthenticationForm(AuthenticationForm): def confirm_login_allowed(self, user): if user.username == "inactive": - raise forms.ValidationError("This user is disallowed.") - raise forms.ValidationError("Sorry, nobody's allowed in.") + raise ValidationError("This user is disallowed.") + raise ValidationError("Sorry, nobody's allowed in.") form = PickyAuthenticationForm(None, data) self.assertFalse(form.is_valid()) @@ -496,7 +496,7 @@ class AuthenticationFormTest(TestDataMixin, TestCase): def test_get_invalid_login_error(self): error = AuthenticationForm().get_invalid_login_error() - self.assertIsInstance(error, forms.ValidationError) + self.assertIsInstance(error, ValidationError) self.assertEqual( error.message, 'Please enter a correct %(username)s and password. Note that both ' diff --git a/tests/forms_tests/field_tests/test_booleanfield.py b/tests/forms_tests/field_tests/test_booleanfield.py index 7ea117a071..b0153e9e0b 100644 --- a/tests/forms_tests/field_tests/test_booleanfield.py +++ b/tests/forms_tests/field_tests/test_booleanfield.py @@ -1,6 +1,7 @@ import pickle -from django.forms import BooleanField, ValidationError +from django.core.exceptions import ValidationError +from django.forms import BooleanField from django.test import SimpleTestCase diff --git a/tests/forms_tests/field_tests/test_charfield.py b/tests/forms_tests/field_tests/test_charfield.py index cbacf4d0d7..352761deec 100644 --- a/tests/forms_tests/field_tests/test_charfield.py +++ b/tests/forms_tests/field_tests/test_charfield.py @@ -1,6 +1,6 @@ +from django.core.exceptions import ValidationError from django.forms import ( CharField, HiddenInput, PasswordInput, Textarea, TextInput, - ValidationError, ) from django.test import SimpleTestCase diff --git a/tests/forms_tests/field_tests/test_choicefield.py b/tests/forms_tests/field_tests/test_choicefield.py index 465cfd83a8..cdb264b36c 100644 --- a/tests/forms_tests/field_tests/test_choicefield.py +++ b/tests/forms_tests/field_tests/test_choicefield.py @@ -1,4 +1,5 @@ -from django.forms import ChoiceField, Form, ValidationError +from django.core.exceptions import ValidationError +from django.forms import ChoiceField, Form from django.test import SimpleTestCase from . import FormFieldAssertionsMixin diff --git a/tests/forms_tests/field_tests/test_combofield.py b/tests/forms_tests/field_tests/test_combofield.py index b40e7ba885..481783fe2e 100644 --- a/tests/forms_tests/field_tests/test_combofield.py +++ b/tests/forms_tests/field_tests/test_combofield.py @@ -1,4 +1,5 @@ -from django.forms import CharField, ComboField, EmailField, ValidationError +from django.core.exceptions import ValidationError +from django.forms import CharField, ComboField, EmailField from django.test import SimpleTestCase diff --git a/tests/forms_tests/field_tests/test_datefield.py b/tests/forms_tests/field_tests/test_datefield.py index 415e1643ee..c0e369cd0c 100644 --- a/tests/forms_tests/field_tests/test_datefield.py +++ b/tests/forms_tests/field_tests/test_datefield.py @@ -1,8 +1,7 @@ from datetime import date, datetime -from django.forms import ( - DateField, Form, HiddenInput, SelectDateWidget, ValidationError, -) +from django.core.exceptions import ValidationError +from django.forms import DateField, Form, HiddenInput, SelectDateWidget from django.test import SimpleTestCase, override_settings from django.utils import translation diff --git a/tests/forms_tests/field_tests/test_datetimefield.py b/tests/forms_tests/field_tests/test_datetimefield.py index 50f1d8e557..f0e6ada3c5 100644 --- a/tests/forms_tests/field_tests/test_datetimefield.py +++ b/tests/forms_tests/field_tests/test_datetimefield.py @@ -1,6 +1,7 @@ from datetime import date, datetime -from django.forms import DateTimeField, ValidationError +from django.core.exceptions import ValidationError +from django.forms import DateTimeField from django.test import SimpleTestCase from django.utils.timezone import get_fixed_timezone, utc diff --git a/tests/forms_tests/field_tests/test_decimalfield.py b/tests/forms_tests/field_tests/test_decimalfield.py index 44ebebcf75..d999dab3f3 100644 --- a/tests/forms_tests/field_tests/test_decimalfield.py +++ b/tests/forms_tests/field_tests/test_decimalfield.py @@ -1,6 +1,7 @@ import decimal -from django.forms import DecimalField, NumberInput, ValidationError, Widget +from django.core.exceptions import ValidationError +from django.forms import DecimalField, NumberInput, Widget from django.test import SimpleTestCase, override_settings from django.utils import formats, translation diff --git a/tests/forms_tests/field_tests/test_emailfield.py b/tests/forms_tests/field_tests/test_emailfield.py index 826524ae62..7bea420a54 100644 --- a/tests/forms_tests/field_tests/test_emailfield.py +++ b/tests/forms_tests/field_tests/test_emailfield.py @@ -1,4 +1,5 @@ -from django.forms import EmailField, ValidationError +from django.core.exceptions import ValidationError +from django.forms import EmailField from django.test import SimpleTestCase from . import FormFieldAssertionsMixin diff --git a/tests/forms_tests/field_tests/test_filefield.py b/tests/forms_tests/field_tests/test_filefield.py index fc5c4b5c1e..261d9f4ca9 100644 --- a/tests/forms_tests/field_tests/test_filefield.py +++ b/tests/forms_tests/field_tests/test_filefield.py @@ -1,7 +1,8 @@ import pickle +from django.core.exceptions import ValidationError from django.core.files.uploadedfile import SimpleUploadedFile -from django.forms import FileField, ValidationError +from django.forms import FileField from django.test import SimpleTestCase diff --git a/tests/forms_tests/field_tests/test_filepathfield.py b/tests/forms_tests/field_tests/test_filepathfield.py index 2b9683ed84..bdd55c32a5 100644 --- a/tests/forms_tests/field_tests/test_filepathfield.py +++ b/tests/forms_tests/field_tests/test_filepathfield.py @@ -1,6 +1,7 @@ import os.path -from django.forms import FilePathField, ValidationError +from django.core.exceptions import ValidationError +from django.forms import FilePathField from django.test import SimpleTestCase PATH = os.path.dirname(os.path.abspath(__file__)) diff --git a/tests/forms_tests/field_tests/test_floatfield.py b/tests/forms_tests/field_tests/test_floatfield.py index 531396868a..d97bbfc13e 100644 --- a/tests/forms_tests/field_tests/test_floatfield.py +++ b/tests/forms_tests/field_tests/test_floatfield.py @@ -1,4 +1,5 @@ -from django.forms import FloatField, NumberInput, ValidationError +from django.core.exceptions import ValidationError +from django.forms import FloatField, NumberInput from django.test import SimpleTestCase from django.test.utils import override_settings from django.utils import formats, translation diff --git a/tests/forms_tests/field_tests/test_genericipaddressfield.py b/tests/forms_tests/field_tests/test_genericipaddressfield.py index 97a83e38ae..92dbd71a28 100644 --- a/tests/forms_tests/field_tests/test_genericipaddressfield.py +++ b/tests/forms_tests/field_tests/test_genericipaddressfield.py @@ -1,4 +1,5 @@ -from django.forms import GenericIPAddressField, ValidationError +from django.core.exceptions import ValidationError +from django.forms import GenericIPAddressField from django.test import SimpleTestCase diff --git a/tests/forms_tests/field_tests/test_imagefield.py b/tests/forms_tests/field_tests/test_imagefield.py index b134fedefc..1cb34bf058 100644 --- a/tests/forms_tests/field_tests/test_imagefield.py +++ b/tests/forms_tests/field_tests/test_imagefield.py @@ -1,12 +1,11 @@ import os import unittest +from django.core.exceptions import ValidationError from django.core.files.uploadedfile import ( SimpleUploadedFile, TemporaryUploadedFile, ) -from django.forms import ( - ClearableFileInput, FileInput, ImageField, ValidationError, Widget, -) +from django.forms import ClearableFileInput, FileInput, ImageField, Widget from django.test import SimpleTestCase from . import FormFieldAssertionsMixin diff --git a/tests/forms_tests/field_tests/test_integerfield.py b/tests/forms_tests/field_tests/test_integerfield.py index a0cde40910..0dde7ff488 100644 --- a/tests/forms_tests/field_tests/test_integerfield.py +++ b/tests/forms_tests/field_tests/test_integerfield.py @@ -1,4 +1,5 @@ -from django.forms import IntegerField, Textarea, ValidationError +from django.core.exceptions import ValidationError +from django.forms import IntegerField, Textarea from django.test import SimpleTestCase from . import FormFieldAssertionsMixin diff --git a/tests/forms_tests/field_tests/test_multiplechoicefield.py b/tests/forms_tests/field_tests/test_multiplechoicefield.py index 9ffe461687..6dbeee2685 100644 --- a/tests/forms_tests/field_tests/test_multiplechoicefield.py +++ b/tests/forms_tests/field_tests/test_multiplechoicefield.py @@ -1,4 +1,5 @@ -from django.forms import MultipleChoiceField, ValidationError +from django.core.exceptions import ValidationError +from django.forms import MultipleChoiceField from django.test import SimpleTestCase diff --git a/tests/forms_tests/field_tests/test_multivaluefield.py b/tests/forms_tests/field_tests/test_multivaluefield.py index fb99451f6c..29287d0b01 100644 --- a/tests/forms_tests/field_tests/test_multivaluefield.py +++ b/tests/forms_tests/field_tests/test_multivaluefield.py @@ -1,9 +1,9 @@ from datetime import datetime +from django.core.exceptions import ValidationError from django.forms import ( CharField, Form, MultipleChoiceField, MultiValueField, MultiWidget, SelectMultiple, SplitDateTimeField, SplitDateTimeWidget, TextInput, - ValidationError, ) from django.test import SimpleTestCase diff --git a/tests/forms_tests/field_tests/test_regexfield.py b/tests/forms_tests/field_tests/test_regexfield.py index 9e1d2cefc1..51b6fe6fd5 100644 --- a/tests/forms_tests/field_tests/test_regexfield.py +++ b/tests/forms_tests/field_tests/test_regexfield.py @@ -1,6 +1,7 @@ import re -from django.forms import RegexField, ValidationError +from django.core.exceptions import ValidationError +from django.forms import RegexField from django.test import SimpleTestCase diff --git a/tests/forms_tests/field_tests/test_splitdatetimefield.py b/tests/forms_tests/field_tests/test_splitdatetimefield.py index 940d03b8a9..716e49c343 100644 --- a/tests/forms_tests/field_tests/test_splitdatetimefield.py +++ b/tests/forms_tests/field_tests/test_splitdatetimefield.py @@ -1,6 +1,7 @@ import datetime -from django.forms import SplitDateTimeField, ValidationError +from django.core.exceptions import ValidationError +from django.forms import SplitDateTimeField from django.forms.widgets import SplitDateTimeWidget from django.test import SimpleTestCase diff --git a/tests/forms_tests/field_tests/test_timefield.py b/tests/forms_tests/field_tests/test_timefield.py index bd8a67992f..a44b10fa07 100644 --- a/tests/forms_tests/field_tests/test_timefield.py +++ b/tests/forms_tests/field_tests/test_timefield.py @@ -1,6 +1,7 @@ import datetime -from django.forms import TimeField, ValidationError +from django.core.exceptions import ValidationError +from django.forms import TimeField from django.test import SimpleTestCase from . import FormFieldAssertionsMixin diff --git a/tests/forms_tests/field_tests/test_typedchoicefield.py b/tests/forms_tests/field_tests/test_typedchoicefield.py index bf0fdb4d47..2c6cd265b5 100644 --- a/tests/forms_tests/field_tests/test_typedchoicefield.py +++ b/tests/forms_tests/field_tests/test_typedchoicefield.py @@ -1,6 +1,7 @@ import decimal -from django.forms import TypedChoiceField, ValidationError +from django.core.exceptions import ValidationError +from django.forms import TypedChoiceField from django.test import SimpleTestCase diff --git a/tests/forms_tests/field_tests/test_typedmultiplechoicefield.py b/tests/forms_tests/field_tests/test_typedmultiplechoicefield.py index b33d26bdaa..1c97676a87 100644 --- a/tests/forms_tests/field_tests/test_typedmultiplechoicefield.py +++ b/tests/forms_tests/field_tests/test_typedmultiplechoicefield.py @@ -1,6 +1,7 @@ import decimal -from django.forms import TypedMultipleChoiceField, ValidationError +from django.core.exceptions import ValidationError +from django.forms import TypedMultipleChoiceField from django.test import SimpleTestCase diff --git a/tests/forms_tests/field_tests/test_urlfield.py b/tests/forms_tests/field_tests/test_urlfield.py index 52f1080cdc..46cc38acb8 100644 --- a/tests/forms_tests/field_tests/test_urlfield.py +++ b/tests/forms_tests/field_tests/test_urlfield.py @@ -1,4 +1,5 @@ -from django.forms import URLField, ValidationError +from django.core.exceptions import ValidationError +from django.forms import URLField from django.test import SimpleTestCase from . import FormFieldAssertionsMixin diff --git a/tests/forms_tests/field_tests/test_uuidfield.py b/tests/forms_tests/field_tests/test_uuidfield.py index 242b81647d..3f902643e0 100644 --- a/tests/forms_tests/field_tests/test_uuidfield.py +++ b/tests/forms_tests/field_tests/test_uuidfield.py @@ -1,6 +1,7 @@ import uuid -from django.forms import UUIDField, ValidationError +from django.core.exceptions import ValidationError +from django.forms import UUIDField from django.test import SimpleTestCase diff --git a/tests/forms_tests/tests/test_error_messages.py b/tests/forms_tests/tests/test_error_messages.py index f324c08096..d60acc1daa 100644 --- a/tests/forms_tests/tests/test_error_messages.py +++ b/tests/forms_tests/tests/test_error_messages.py @@ -1,10 +1,11 @@ +from django.core.exceptions import ValidationError from django.core.files.uploadedfile import SimpleUploadedFile from django.forms import ( BooleanField, CharField, ChoiceField, DateField, DateTimeField, DecimalField, EmailField, FileField, FloatField, Form, GenericIPAddressField, IntegerField, ModelChoiceField, ModelMultipleChoiceField, MultipleChoiceField, RegexField, - SplitDateTimeField, TimeField, URLField, ValidationError, utils, + SplitDateTimeField, TimeField, URLField, utils, ) from django.template import Context, Template from django.test import SimpleTestCase, TestCase, ignore_warnings diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py index 16ecf09814..26f8ecafea 100644 --- a/tests/forms_tests/tests/test_forms.py +++ b/tests/forms_tests/tests/test_forms.py @@ -3359,7 +3359,7 @@ Good luck picking a username that doesn't already exist.</p> self.assertIsInstance(e, list) self.assertIn('Foo', e) - self.assertIn('Foo', forms.ValidationError(e)) + self.assertIn('Foo', ValidationError(e)) self.assertEqual( e.as_text(), diff --git a/tests/forms_tests/tests/test_formsets.py b/tests/forms_tests/tests/test_formsets.py index 0a4be19623..689f972a07 100644 --- a/tests/forms_tests/tests/test_formsets.py +++ b/tests/forms_tests/tests/test_formsets.py @@ -2,9 +2,10 @@ import datetime from collections import Counter from unittest import mock +from django.core.exceptions import ValidationError from django.forms import ( BaseForm, CharField, DateField, FileField, Form, IntegerField, - SplitDateTimeField, ValidationError, formsets, + SplitDateTimeField, formsets, ) from django.forms.formsets import BaseFormSet, all_valid, formset_factory from django.forms.utils import ErrorList diff --git a/tests/forms_tests/tests/test_input_formats.py b/tests/forms_tests/tests/test_input_formats.py index e7aabf74b3..81ba9eb943 100644 --- a/tests/forms_tests/tests/test_input_formats.py +++ b/tests/forms_tests/tests/test_input_formats.py @@ -1,6 +1,7 @@ from datetime import date, datetime, time from django import forms +from django.core.exceptions import ValidationError from django.test import SimpleTestCase, override_settings from django.utils.translation import activate, deactivate @@ -19,7 +20,7 @@ class LocalizedTimeTests(SimpleTestCase): "TimeFields can parse dates in the default format" f = forms.TimeField() # Parse a time in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('1:30:05 PM') # Parse a time in a valid format, get a parsed result @@ -46,7 +47,7 @@ class LocalizedTimeTests(SimpleTestCase): "Localized TimeFields act as unlocalized widgets" f = forms.TimeField(localize=True) # Parse a time in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('1:30:05 PM') # Parse a time in a valid format, get a parsed result @@ -69,9 +70,9 @@ class LocalizedTimeTests(SimpleTestCase): "TimeFields with manually specified input formats can accept those formats" f = forms.TimeField(input_formats=["%H.%M.%S", "%H.%M"]) # Parse a time in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('1:30:05 PM') - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('13:30:05') # Parse a time in a valid format, get a parsed result @@ -94,9 +95,9 @@ class LocalizedTimeTests(SimpleTestCase): "Localized TimeFields with manually specified input formats can accept those formats" f = forms.TimeField(input_formats=["%H.%M.%S", "%H.%M"], localize=True) # Parse a time in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('1:30:05 PM') - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('13:30:05') # Parse a time in a valid format, get a parsed result @@ -122,7 +123,7 @@ class CustomTimeInputFormatsTests(SimpleTestCase): "TimeFields can parse dates in the default format" f = forms.TimeField() # Parse a time in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('13:30:05') # Parse a time in a valid format, get a parsed result @@ -145,7 +146,7 @@ class CustomTimeInputFormatsTests(SimpleTestCase): "Localized TimeFields act as unlocalized widgets" f = forms.TimeField(localize=True) # Parse a time in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('13:30:05') # Parse a time in a valid format, get a parsed result @@ -168,9 +169,9 @@ class CustomTimeInputFormatsTests(SimpleTestCase): "TimeFields with manually specified input formats can accept those formats" f = forms.TimeField(input_formats=["%H.%M.%S", "%H.%M"]) # Parse a time in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('1:30:05 PM') - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('13:30:05') # Parse a time in a valid format, get a parsed result @@ -193,9 +194,9 @@ class CustomTimeInputFormatsTests(SimpleTestCase): "Localized TimeFields with manually specified input formats can accept those formats" f = forms.TimeField(input_formats=["%H.%M.%S", "%H.%M"], localize=True) # Parse a time in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('1:30:05 PM') - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('13:30:05') # Parse a time in a valid format, get a parsed result @@ -220,7 +221,7 @@ class SimpleTimeFormatTests(SimpleTestCase): "TimeFields can parse dates in the default format" f = forms.TimeField() # Parse a time in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('1:30:05 PM') # Parse a time in a valid format, get a parsed result @@ -243,7 +244,7 @@ class SimpleTimeFormatTests(SimpleTestCase): "Localized TimeFields in a non-localized environment act as unlocalized widgets" f = forms.TimeField() # Parse a time in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('1:30:05 PM') # Parse a time in a valid format, get a parsed result @@ -266,7 +267,7 @@ class SimpleTimeFormatTests(SimpleTestCase): "TimeFields with manually specified input formats can accept those formats" f = forms.TimeField(input_formats=["%I:%M:%S %p", "%I:%M %p"]) # Parse a time in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('13:30:05') # Parse a time in a valid format, get a parsed result @@ -289,7 +290,7 @@ class SimpleTimeFormatTests(SimpleTestCase): "Localized TimeFields with manually specified input formats can accept those formats" f = forms.TimeField(input_formats=["%I:%M:%S %p", "%I:%M %p"], localize=True) # Parse a time in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('13:30:05') # Parse a time in a valid format, get a parsed result @@ -321,7 +322,7 @@ class LocalizedDateTests(SimpleTestCase): "DateFields can parse dates in the default format" f = forms.DateField() # Parse a date in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('21/12/2010') # ISO formats are accepted, even if not specified in formats.py @@ -347,7 +348,7 @@ class LocalizedDateTests(SimpleTestCase): "Localized DateFields act as unlocalized widgets" f = forms.DateField(localize=True) # Parse a date in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('21/12/2010') # Parse a date in a valid format, get a parsed result @@ -370,11 +371,11 @@ class LocalizedDateTests(SimpleTestCase): "DateFields with manually specified input formats can accept those formats" f = forms.DateField(input_formats=["%m.%d.%Y", "%m-%d-%Y"]) # Parse a date in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('2010-12-21') - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('21/12/2010') - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('21.12.2010') # Parse a date in a valid format, get a parsed result @@ -397,11 +398,11 @@ class LocalizedDateTests(SimpleTestCase): "Localized DateFields with manually specified input formats can accept those formats" f = forms.DateField(input_formats=["%m.%d.%Y", "%m-%d-%Y"], localize=True) # Parse a date in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('2010-12-21') - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('21/12/2010') - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('21.12.2010') # Parse a date in a valid format, get a parsed result @@ -427,7 +428,7 @@ class CustomDateInputFormatsTests(SimpleTestCase): "DateFields can parse dates in the default format" f = forms.DateField() # Parse a date in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('2010-12-21') # Parse a date in a valid format, get a parsed result @@ -450,7 +451,7 @@ class CustomDateInputFormatsTests(SimpleTestCase): "Localized DateFields act as unlocalized widgets" f = forms.DateField(localize=True) # Parse a date in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('2010-12-21') # Parse a date in a valid format, get a parsed result @@ -473,9 +474,9 @@ class CustomDateInputFormatsTests(SimpleTestCase): "DateFields with manually specified input formats can accept those formats" f = forms.DateField(input_formats=["%m.%d.%Y", "%m-%d-%Y"]) # Parse a date in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('21.12.2010') - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('2010-12-21') # Parse a date in a valid format, get a parsed result @@ -498,9 +499,9 @@ class CustomDateInputFormatsTests(SimpleTestCase): "Localized DateFields with manually specified input formats can accept those formats" f = forms.DateField(input_formats=["%m.%d.%Y", "%m-%d-%Y"], localize=True) # Parse a date in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('21.12.2010') - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('2010-12-21') # Parse a date in a valid format, get a parsed result @@ -525,7 +526,7 @@ class SimpleDateFormatTests(SimpleTestCase): "DateFields can parse dates in the default format" f = forms.DateField() # Parse a date in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('21.12.2010') # Parse a date in a valid format, get a parsed result @@ -548,7 +549,7 @@ class SimpleDateFormatTests(SimpleTestCase): "Localized DateFields in a non-localized environment act as unlocalized widgets" f = forms.DateField() # Parse a date in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('21.12.2010') # Parse a date in a valid format, get a parsed result @@ -571,7 +572,7 @@ class SimpleDateFormatTests(SimpleTestCase): "DateFields with manually specified input formats can accept those formats" f = forms.DateField(input_formats=["%d.%m.%Y", "%d-%m-%Y"]) # Parse a date in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('2010-12-21') # Parse a date in a valid format, get a parsed result @@ -594,7 +595,7 @@ class SimpleDateFormatTests(SimpleTestCase): "Localized DateFields with manually specified input formats can accept those formats" f = forms.DateField(input_formats=["%d.%m.%Y", "%d-%m-%Y"], localize=True) # Parse a date in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('2010-12-21') # Parse a date in a valid format, get a parsed result @@ -626,7 +627,7 @@ class LocalizedDateTimeTests(SimpleTestCase): "DateTimeFields can parse dates in the default format" f = forms.DateTimeField() # Parse a date in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('1:30:05 PM 21/12/2010') # ISO formats are accepted, even if not specified in formats.py @@ -652,7 +653,7 @@ class LocalizedDateTimeTests(SimpleTestCase): "Localized DateTimeFields act as unlocalized widgets" f = forms.DateTimeField(localize=True) # Parse a date in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('1:30:05 PM 21/12/2010') # Parse a date in a valid format, get a parsed result @@ -675,11 +676,11 @@ class LocalizedDateTimeTests(SimpleTestCase): "DateTimeFields with manually specified input formats can accept those formats" f = forms.DateTimeField(input_formats=["%H.%M.%S %m.%d.%Y", "%H.%M %m-%d-%Y"]) # Parse a date in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('2010-12-21 13:30:05 13:30:05') - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('1:30:05 PM 21/12/2010') - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('13:30:05 21.12.2010') # Parse a date in a valid format, get a parsed result @@ -702,11 +703,11 @@ class LocalizedDateTimeTests(SimpleTestCase): "Localized DateTimeFields with manually specified input formats can accept those formats" f = forms.DateTimeField(input_formats=["%H.%M.%S %m.%d.%Y", "%H.%M %m-%d-%Y"], localize=True) # Parse a date in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('2010/12/21 13:30:05') - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('1:30:05 PM 21/12/2010') - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('13:30:05 21.12.2010') # Parse a date in a valid format, get a parsed result @@ -736,7 +737,7 @@ class CustomDateTimeInputFormatsTests(SimpleTestCase): "DateTimeFields can parse dates in the default format" f = forms.DateTimeField() # Parse a date in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('2010/12/21 13:30:05') # Parse a date in a valid format, get a parsed result @@ -759,7 +760,7 @@ class CustomDateTimeInputFormatsTests(SimpleTestCase): "Localized DateTimeFields act as unlocalized widgets" f = forms.DateTimeField(localize=True) # Parse a date in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('2010/12/21 13:30:05') # Parse a date in a valid format, get a parsed result @@ -782,9 +783,9 @@ class CustomDateTimeInputFormatsTests(SimpleTestCase): "DateTimeFields with manually specified input formats can accept those formats" f = forms.DateTimeField(input_formats=["%m.%d.%Y %H:%M:%S", "%m-%d-%Y %H:%M"]) # Parse a date in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('13:30:05 21.12.2010') - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('2010/12/21 13:30:05') # Parse a date in a valid format, get a parsed result @@ -807,9 +808,9 @@ class CustomDateTimeInputFormatsTests(SimpleTestCase): "Localized DateTimeFields with manually specified input formats can accept those formats" f = forms.DateTimeField(input_formats=["%m.%d.%Y %H:%M:%S", "%m-%d-%Y %H:%M"], localize=True) # Parse a date in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('13:30:05 21.12.2010') - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('2010/12/21 13:30:05') # Parse a date in a valid format, get a parsed result @@ -834,7 +835,7 @@ class SimpleDateTimeFormatTests(SimpleTestCase): "DateTimeFields can parse dates in the default format" f = forms.DateTimeField() # Parse a date in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('13:30:05 21.12.2010') # Parse a date in a valid format, get a parsed result @@ -857,7 +858,7 @@ class SimpleDateTimeFormatTests(SimpleTestCase): "Localized DateTimeFields in a non-localized environment act as unlocalized widgets" f = forms.DateTimeField() # Parse a date in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('13:30:05 21.12.2010') # Parse a date in a valid format, get a parsed result @@ -880,7 +881,7 @@ class SimpleDateTimeFormatTests(SimpleTestCase): "DateTimeFields with manually specified input formats can accept those formats" f = forms.DateTimeField(input_formats=["%I:%M:%S %p %d.%m.%Y", "%I:%M %p %d-%m-%Y"]) # Parse a date in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('2010/12/21 13:30:05') # Parse a date in a valid format, get a parsed result @@ -903,7 +904,7 @@ class SimpleDateTimeFormatTests(SimpleTestCase): "Localized DateTimeFields with manually specified input formats can accept those formats" f = forms.DateTimeField(input_formats=["%I:%M:%S %p %d.%m.%Y", "%I:%M %p %d-%m-%Y"], localize=True) # Parse a date in an unaccepted format; get an error - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): f.clean('2010/12/21 13:30:05') # Parse a date in a valid format, get a parsed result diff --git a/tests/gis_tests/test_geoforms.py b/tests/gis_tests/test_geoforms.py index 269ce03bde..c6fb2f71fb 100644 --- a/tests/gis_tests/test_geoforms.py +++ b/tests/gis_tests/test_geoforms.py @@ -3,7 +3,7 @@ import re from django.contrib.gis import forms from django.contrib.gis.forms import BaseGeometryWidget, OpenLayersWidget from django.contrib.gis.geos import GEOSGeometry -from django.forms import ValidationError +from django.core.exceptions import ValidationError from django.test import SimpleTestCase, override_settings from django.utils.html import escape @@ -39,7 +39,7 @@ class GeometryFieldTest(SimpleTestCase): "Testing GeometryField's handling of null (None) geometries." # Form fields, by default, are required (`required=True`) fld = forms.GeometryField() - with self.assertRaisesMessage(forms.ValidationError, "No geometry value provided."): + with self.assertRaisesMessage(ValidationError, "No geometry value provided."): fld.clean(None) # This will clean None as a geometry (See #10660). @@ -64,7 +64,7 @@ class GeometryFieldTest(SimpleTestCase): pnt_fld.to_python('LINESTRING(0 0, 1 1)') ) # but rejected by `clean` - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): pnt_fld.clean('LINESTRING(0 0, 1 1)') def test_to_python(self): @@ -92,7 +92,7 @@ class GeometryFieldTest(SimpleTestCase): # but raises a ValidationError for any other string for geo_input in bad_inputs: with self.subTest(geo_input=geo_input): - with self.assertRaises(forms.ValidationError): + with self.assertRaises(ValidationError): fld.to_python(geo_input) def test_to_python_different_map_srid(self): diff --git a/tests/model_forms/test_modelchoicefield.py b/tests/model_forms/test_modelchoicefield.py index 1d4b9f9e70..8f41ce9c40 100644 --- a/tests/model_forms/test_modelchoicefield.py +++ b/tests/model_forms/test_modelchoicefield.py @@ -1,7 +1,7 @@ import datetime from django import forms -from django.core.validators import ValidationError +from django.core.exceptions import ValidationError from django.forms.models import ModelChoiceIterator from django.forms.widgets import CheckboxSelectMultiple from django.template import Context, Template diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py index 0caf6e9bad..00e68d1dae 100644 --- a/tests/model_forms/tests.py +++ b/tests/model_forms/tests.py @@ -5,10 +5,9 @@ from unittest import mock, skipUnless from django import forms from django.core.exceptions import ( - NON_FIELD_ERRORS, FieldError, ImproperlyConfigured, + NON_FIELD_ERRORS, FieldError, ImproperlyConfigured, ValidationError, ) from django.core.files.uploadedfile import SimpleUploadedFile -from django.core.validators import ValidationError from django.db import connection, models from django.db.models.query import EmptyQuerySet from django.forms.models import ( @@ -2619,7 +2618,7 @@ class CustomCleanTests(TestCase): def clean(self): if not self.cleaned_data['left'] == self.cleaned_data['right']: - raise forms.ValidationError('Left and right should be equal') + raise ValidationError('Left and right should be equal') return self.cleaned_data form = TripleFormWithCleanOverride({'left': 1, 'middle': 2, 'right': 1}) diff --git a/tests/test_client/views.py b/tests/test_client/views.py index c2aef76508..b56ea458a2 100644 --- a/tests/test_client/views.py +++ b/tests/test_client/views.py @@ -4,8 +4,9 @@ from xml.dom.minidom import parseString from django.contrib.auth.decorators import login_required, permission_required from django.core import mail +from django.core.exceptions import ValidationError from django.forms import fields -from django.forms.forms import Form, ValidationError +from django.forms.forms import Form from django.forms.formsets import BaseFormSet, formset_factory from django.http import ( HttpResponse, HttpResponseBadRequest, HttpResponseNotAllowed, |
