mirror of
https://github.com/django/django.git
synced 2025-01-03 06:55:47 +00:00
Refs #32559 -- Added selenium test for FloatField client-side validation.
step="any" is required for non-integer values. See:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/number#step
Covers behaviour added in 7ec2a21be1
.
This commit is contained in:
parent
832adb31f2
commit
4b8e9492d9
@ -1,7 +1,9 @@
|
|||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.forms import FloatField, NumberInput
|
from django.forms import FloatField, NumberInput
|
||||||
from django.test import SimpleTestCase
|
from django.test import SimpleTestCase
|
||||||
|
from django.test.selenium import SeleniumTestCase
|
||||||
from django.test.utils import ignore_warnings, override_settings
|
from django.test.utils import ignore_warnings, override_settings
|
||||||
|
from django.urls import reverse
|
||||||
from django.utils import formats, translation
|
from django.utils import formats, translation
|
||||||
from django.utils.deprecation import RemovedInDjango50Warning
|
from django.utils.deprecation import RemovedInDjango50Warning
|
||||||
|
|
||||||
@ -111,3 +113,24 @@ class FloatFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
|
|||||||
msg = "'Enter a number.'"
|
msg = "'Enter a number.'"
|
||||||
with self.assertRaisesMessage(ValidationError, msg):
|
with self.assertRaisesMessage(ValidationError, msg):
|
||||||
f.clean('1,001.1')
|
f.clean('1,001.1')
|
||||||
|
|
||||||
|
|
||||||
|
@override_settings(ROOT_URLCONF='forms_tests.urls')
|
||||||
|
class FloatFieldHTMLTest(SeleniumTestCase):
|
||||||
|
|
||||||
|
available_apps = ['forms_tests']
|
||||||
|
|
||||||
|
def test_float_field_rendering_passes_client_side_validation(self):
|
||||||
|
"""
|
||||||
|
Rendered widget allows non-integer value with the client-side
|
||||||
|
validation.
|
||||||
|
"""
|
||||||
|
from selenium.webdriver.common.by import By
|
||||||
|
|
||||||
|
self.selenium.get(self.live_server_url + reverse('form_view'))
|
||||||
|
number_input = self.selenium.find_element(By.ID, 'id_number')
|
||||||
|
number_input.send_keys('0.5')
|
||||||
|
is_valid = self.selenium.execute_script(
|
||||||
|
"return document.getElementById('id_number').checkValidity()"
|
||||||
|
)
|
||||||
|
self.assertTrue(is_valid)
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
from .views import ArticleFormView
|
from .views import ArticleFormView, form_view
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
path('form_view/', form_view, name='form_view'),
|
||||||
path('model_form/<int:pk>/', ArticleFormView.as_view(), name='article_form'),
|
path('model_form/<int:pk>/', ArticleFormView.as_view(), name='article_form'),
|
||||||
]
|
]
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
from django import forms
|
from django import forms
|
||||||
|
from django.http import HttpResponse
|
||||||
|
from django.template import Context, Template
|
||||||
from django.views.generic.edit import UpdateView
|
from django.views.generic.edit import UpdateView
|
||||||
|
|
||||||
from .models import Article
|
from .models import Article
|
||||||
@ -16,3 +18,12 @@ class ArticleFormView(UpdateView):
|
|||||||
model = Article
|
model = Article
|
||||||
success_url = '/'
|
success_url = '/'
|
||||||
form_class = ArticleForm
|
form_class = ArticleForm
|
||||||
|
|
||||||
|
|
||||||
|
def form_view(request):
|
||||||
|
class Form(forms.Form):
|
||||||
|
number = forms.FloatField()
|
||||||
|
|
||||||
|
template = Template('<html>{{ form }}</html>')
|
||||||
|
context = Context({'form': Form()})
|
||||||
|
return HttpResponse(template.render(context))
|
||||||
|
Loading…
Reference in New Issue
Block a user