summaryrefslogtreecommitdiff
path: root/tests/forms_tests
diff options
context:
space:
mode:
authorMarc Tamlyn <marc.tamlyn@gmail.com>2014-07-24 13:57:24 +0100
committerMarc Tamlyn <marc.tamlyn@gmail.com>2014-12-20 18:28:29 +0000
commit57554442fe3e209c135e15dda4ea45123e579e58 (patch)
tree0ef2cb0e3048d13b82e4c7e81192df6124556a44 /tests/forms_tests
parenta3d96bee36040975ded8e3bf02e33e48d06f1f16 (diff)
Fixed #2443 -- Added DurationField.
A field for storing periods of time - modeled in Python by timedelta. It is stored in the native interval data type on PostgreSQL and as a bigint of microseconds on other backends. Also includes significant changes to the internals of time related maths in expressions, including the removal of DateModifierNode. Thanks to Tim and Josh in particular for reviews.
Diffstat (limited to 'tests/forms_tests')
-rw-r--r--tests/forms_tests/tests/test_fields.py37
1 files changed, 32 insertions, 5 deletions
diff --git a/tests/forms_tests/tests/test_fields.py b/tests/forms_tests/tests/test_fields.py
index 3caf902349..b2f0869c47 100644
--- a/tests/forms_tests/tests/test_fields.py
+++ b/tests/forms_tests/tests/test_fields.py
@@ -43,11 +43,12 @@ except ImportError:
from django.core.files.uploadedfile import SimpleUploadedFile
from django.forms import (
BooleanField, CharField, ChoiceField, ComboField, DateField, DateTimeField,
- DecimalField, EmailField, Field, FileField, FilePathField, FloatField,
- Form, forms, HiddenInput, ImageField, IntegerField, MultipleChoiceField,
- NullBooleanField, NumberInput, PasswordInput, RadioSelect, RegexField,
- SplitDateTimeField, TextInput, Textarea, TimeField, TypedChoiceField,
- TypedMultipleChoiceField, URLField, UUIDField, ValidationError, Widget,
+ DecimalField, DurationField, EmailField, Field, FileField, FilePathField,
+ FloatField, Form, forms, HiddenInput, ImageField, IntegerField,
+ MultipleChoiceField, NullBooleanField, NumberInput, PasswordInput,
+ RadioSelect, RegexField, SplitDateTimeField, TextInput, Textarea,
+ TimeField, TypedChoiceField, TypedMultipleChoiceField, URLField, UUIDField,
+ ValidationError, Widget,
)
from django.test import SimpleTestCase
from django.utils import formats
@@ -611,6 +612,32 @@ class FieldsTests(SimpleTestCase):
# RegexField ##################################################################
+ def test_durationfield_1(self):
+ f = DurationField()
+ self.assertEqual(datetime.timedelta(seconds=30), f.clean('30'))
+ self.assertEqual(
+ datetime.timedelta(minutes=15, seconds=30),
+ f.clean('15:30')
+ )
+ self.assertEqual(
+ datetime.timedelta(hours=1, minutes=15, seconds=30),
+ f.clean('1:15:30')
+ )
+ self.assertEqual(
+ datetime.timedelta(
+ days=1, hours=1, minutes=15, seconds=30, milliseconds=300),
+ f.clean('1 1:15:30.3')
+ )
+
+ def test_durationfield_2(self):
+ class DurationForm(Form):
+ duration = DurationField(initial=datetime.timedelta(hours=1))
+ f = DurationForm()
+ self.assertHTMLEqual(
+ '<input id="id_duration" type="text" name="duration" value="01:00:00">',
+ str(f['duration'])
+ )
+
def test_regexfield_1(self):
f = RegexField('^[0-9][A-F][0-9]$')
self.assertEqual('2A2', f.clean('2A2'))