Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
39f6f113
Commit
39f6f113
authored
Jul 10, 2017
by
Tom Christie
Committed by
GitHub
Jul 10, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5261 from encode/validation-error-on-invalid-timezone-parsing
Raise validation error on invalid timezone parsing.
parents
fbb34909
41901185
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
5 deletions
+10
-5
rest_framework/fields.py
+3
-5
tests/test_fields.py
+7
-0
No files found.
rest_framework/fields.py
View file @
39f6f113
...
@@ -1137,18 +1137,16 @@ class DateTimeField(Field):
...
@@ -1137,18 +1137,16 @@ class DateTimeField(Field):
if
input_format
.
lower
()
==
ISO_8601
:
if
input_format
.
lower
()
==
ISO_8601
:
try
:
try
:
parsed
=
parse_datetime
(
value
)
parsed
=
parse_datetime
(
value
)
except
(
ValueError
,
TypeError
):
pass
else
:
if
parsed
is
not
None
:
if
parsed
is
not
None
:
return
self
.
enforce_timezone
(
parsed
)
return
self
.
enforce_timezone
(
parsed
)
except
(
ValueError
,
TypeError
):
pass
else
:
else
:
try
:
try
:
parsed
=
self
.
datetime_parser
(
value
,
input_format
)
parsed
=
self
.
datetime_parser
(
value
,
input_format
)
return
self
.
enforce_timezone
(
parsed
)
except
(
ValueError
,
TypeError
):
except
(
ValueError
,
TypeError
):
pass
pass
else
:
return
self
.
enforce_timezone
(
parsed
)
humanized_format
=
humanize_datetime
.
datetime_formats
(
input_formats
)
humanized_format
=
humanize_datetime
.
datetime_formats
(
input_formats
)
self
.
fail
(
'invalid'
,
format
=
humanized_format
)
self
.
fail
(
'invalid'
,
format
=
humanized_format
)
...
...
tests/test_fields.py
View file @
39f6f113
...
@@ -5,6 +5,7 @@ import unittest
...
@@ -5,6 +5,7 @@ import unittest
import
uuid
import
uuid
from
decimal
import
Decimal
from
decimal
import
Decimal
import
django
import
pytest
import
pytest
from
django.http
import
QueryDict
from
django.http
import
QueryDict
from
django.test
import
TestCase
,
override_settings
from
django.test
import
TestCase
,
override_settings
...
@@ -1150,6 +1151,7 @@ class TestDateTimeField(FieldValues):
...
@@ -1150,6 +1151,7 @@ class TestDateTimeField(FieldValues):
invalid_inputs
=
{
invalid_inputs
=
{
'abc'
:
[
'Datetime has wrong format. Use one of these formats instead: YYYY-MM-DDThh:mm[:ss[.uuuuuu]][+HH:MM|-HH:MM|Z].'
],
'abc'
:
[
'Datetime has wrong format. Use one of these formats instead: YYYY-MM-DDThh:mm[:ss[.uuuuuu]][+HH:MM|-HH:MM|Z].'
],
'2001-99-99T99:00'
:
[
'Datetime has wrong format. Use one of these formats instead: YYYY-MM-DDThh:mm[:ss[.uuuuuu]][+HH:MM|-HH:MM|Z].'
],
'2001-99-99T99:00'
:
[
'Datetime has wrong format. Use one of these formats instead: YYYY-MM-DDThh:mm[:ss[.uuuuuu]][+HH:MM|-HH:MM|Z].'
],
'2018-08-16 22:00-24:00'
:
[
'Datetime has wrong format. Use one of these formats instead: YYYY-MM-DDThh:mm[:ss[.uuuuuu]][+HH:MM|-HH:MM|Z].'
],
datetime
.
date
(
2001
,
1
,
1
):
[
'Expected a datetime but got a date.'
],
datetime
.
date
(
2001
,
1
,
1
):
[
'Expected a datetime but got a date.'
],
}
}
outputs
=
{
outputs
=
{
...
@@ -1163,6 +1165,11 @@ class TestDateTimeField(FieldValues):
...
@@ -1163,6 +1165,11 @@ class TestDateTimeField(FieldValues):
field
=
serializers
.
DateTimeField
(
default_timezone
=
utc
)
field
=
serializers
.
DateTimeField
(
default_timezone
=
utc
)
if
django
.
VERSION
[:
2
]
<=
(
1
,
8
):
# Doesn't raise an error on earlier versions of Django
TestDateTimeField
.
invalid_inputs
.
pop
(
'2018-08-16 22:00-24:00'
)
class
TestCustomInputFormatDateTimeField
(
FieldValues
):
class
TestCustomInputFormatDateTimeField
(
FieldValues
):
"""
"""
Valid and invalid values for `DateTimeField` with a custom input format.
Valid and invalid values for `DateTimeField` with a custom input format.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment