diff options
| author | Stephen Burrows <stephen.r.burrows@gmail.com> | 2014-05-06 18:14:06 -0700 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2014-05-10 10:56:39 +0200 |
| commit | a5de0df58b5431b25a3246a57432db73843be87f (patch) | |
| tree | 8570266e99b96608e254afdc53f51373551b3a91 /tests | |
| parent | 35e1b1efab262ed78b3b8916ec01eb897872fe60 (diff) | |
Fixed #22502 -- Fixed microseconds/default/form interaction
Made explicit lack of microsecond handling by built-in datetime form
fields. Used that explicitness to appropriately nix microsecond
values in bound fields. Thanks Claude Paroz for the review.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/forms_tests/tests/test_forms.py | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py index b8c5f28d2f..06c155ed60 100644 --- a/tests/forms_tests/tests/test_forms.py +++ b/tests/forms_tests/tests/test_forms.py @@ -11,10 +11,10 @@ from django.core.files.uploadedfile import SimpleUploadedFile from django.core.validators import RegexValidator from django.forms import ( BooleanField, CharField, CheckboxSelectMultiple, ChoiceField, DateField, - EmailField, FileField, FloatField, Form, forms, HiddenInput, IntegerField, - MultipleChoiceField, MultipleHiddenInput, MultiValueField, + DateTimeField, EmailField, FileField, FloatField, Form, forms, HiddenInput, + IntegerField, MultipleChoiceField, MultipleHiddenInput, MultiValueField, NullBooleanField, PasswordInput, RadioSelect, Select, SplitDateTimeField, - Textarea, TextInput, ValidationError, widgets, + Textarea, TextInput, TimeField, ValidationError, widgets ) from django.forms.utils import ErrorList from django.http import QueryDict @@ -1321,6 +1321,29 @@ class FormsTestCase(TestCase): self.assertEqual(bound['password'].value(), 'foo') self.assertEqual(unbound['password'].value(), None) + def test_initial_datetime_values(self): + now = datetime.datetime.now() + # Nix microseconds (since they should be ignored). #22502 + now_no_ms = now.replace(microsecond=0) + if now == now_no_ms: + now = now.replace(microsecond=1) + + def delayed_now(): + return now + + def delayed_now_time(): + return now.time() + + class DateTimeForm(Form): + auto_timestamp = DateTimeField(initial=delayed_now) + auto_time_only = TimeField(initial=delayed_now_time) + supports_microseconds = DateTimeField(initial=delayed_now, widget=TextInput) + + unbound = DateTimeForm() + self.assertEqual(unbound['auto_timestamp'].value(), now_no_ms) + self.assertEqual(unbound['auto_time_only'].value(), now_no_ms.time()) + self.assertEqual(unbound['supports_microseconds'].value(), now) + def test_help_text(self): # You can specify descriptive text for a field by using the 'help_text' argument) class UserRegistration(Form): |
