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
b0a0c30b
Commit
b0a0c30b
authored
Mar 22, 2017
by
Sergey Petrunin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added pytz exception in compat module.
Mock pytz.timezone localize in tests. Ref: #4986
parent
e4a1bd14
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
6 deletions
+24
-6
requirements/requirements-testing.txt
+0
-1
rest_framework/compat.py
+9
-0
rest_framework/fields.py
+3
-2
tests/test_fields.py
+12
-3
No files found.
requirements/requirements-testing.txt
View file @
b0a0c30b
...
@@ -2,4 +2,3 @@
...
@@ -2,4 +2,3 @@
pytest==3.0.5
pytest==3.0.5
pytest-django==3.1.2
pytest-django==3.1.2
pytest-cov==2.4.0
pytest-cov==2.4.0
pytz==2016.10
rest_framework/compat.py
View file @
b0a0c30b
...
@@ -275,6 +275,14 @@ except ImportError:
...
@@ -275,6 +275,14 @@ except ImportError:
def
pygments_css
(
style
):
def
pygments_css
(
style
):
return
None
return
None
try
:
import
pytz
from
pytz.exceptions
import
InvalidTimeError
except
ImportError
:
InvalidTimeError
=
Exception
# `separators` argument to `json.dumps()` differs between 2.x and 3.x
# `separators` argument to `json.dumps()` differs between 2.x and 3.x
# See: http://bugs.python.org/issue22767
# See: http://bugs.python.org/issue22767
if
six
.
PY3
:
if
six
.
PY3
:
...
@@ -339,6 +347,7 @@ def set_many(instance, field, value):
...
@@ -339,6 +347,7 @@ def set_many(instance, field, value):
field
=
getattr
(
instance
,
field
)
field
=
getattr
(
instance
,
field
)
field
.
set
(
value
)
field
.
set
(
value
)
def
include
(
module
,
namespace
=
None
,
app_name
=
None
):
def
include
(
module
,
namespace
=
None
,
app_name
=
None
):
from
django.conf.urls
import
include
from
django.conf.urls
import
include
if
django
.
VERSION
<
(
1
,
9
):
if
django
.
VERSION
<
(
1
,
9
):
...
...
rest_framework/fields.py
View file @
b0a0c30b
...
@@ -33,7 +33,8 @@ from django.utils.translation import ugettext_lazy as _
...
@@ -33,7 +33,8 @@ from django.utils.translation import ugettext_lazy as _
from
rest_framework
import
ISO_8601
from
rest_framework
import
ISO_8601
from
rest_framework.compat
import
(
from
rest_framework.compat
import
(
get_remote_field
,
unicode_repr
,
unicode_to_repr
,
value_from_object
InvalidTimeError
,
get_remote_field
,
unicode_repr
,
unicode_to_repr
,
value_from_object
)
)
from
rest_framework.exceptions
import
ErrorDetail
,
ValidationError
from
rest_framework.exceptions
import
ErrorDetail
,
ValidationError
from
rest_framework.settings
import
api_settings
from
rest_framework.settings
import
api_settings
...
@@ -1108,7 +1109,7 @@ class DateTimeField(Field):
...
@@ -1108,7 +1109,7 @@ class DateTimeField(Field):
if
(
field_timezone
is
not
None
)
and
not
timezone
.
is_aware
(
value
):
if
(
field_timezone
is
not
None
)
and
not
timezone
.
is_aware
(
value
):
try
:
try
:
return
timezone
.
make_aware
(
value
,
field_timezone
)
return
timezone
.
make_aware
(
value
,
field_timezone
)
except
Exception
:
except
InvalidTimeError
:
self
.
fail
(
'make_aware'
,
timezone
=
field_timezone
)
self
.
fail
(
'make_aware'
,
timezone
=
field_timezone
)
elif
(
field_timezone
is
None
)
and
timezone
.
is_aware
(
value
):
elif
(
field_timezone
is
None
)
and
timezone
.
is_aware
(
value
):
return
timezone
.
make_naive
(
value
,
utc
)
return
timezone
.
make_naive
(
value
,
utc
)
...
...
tests/test_fields.py
View file @
b0a0c30b
...
@@ -9,10 +9,10 @@ import pytest
...
@@ -9,10 +9,10 @@ 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
from
django.utils
import
six
from
django.utils
import
six
from
django.utils.timezone
import
pytz
,
utc
from
django.utils.timezone
import
utc
import
rest_framework
import
rest_framework
from
rest_framework
import
serializers
from
rest_framework
import
compat
,
serializers
from
rest_framework.fields
import
is_simple_callable
from
rest_framework.fields
import
is_simple_callable
try
:
try
:
...
@@ -1217,7 +1217,16 @@ class TestNaiveDayLightSavingTimeTimeZoneDateTimeField(FieldValues):
...
@@ -1217,7 +1217,16 @@ class TestNaiveDayLightSavingTimeTimeZoneDateTimeField(FieldValues):
'2017-11-05T01:30:00'
:
[
'Invalid datetime for the timezone "America/New_York".'
]
'2017-11-05T01:30:00'
:
[
'Invalid datetime for the timezone "America/New_York".'
]
}
}
outputs
=
{}
outputs
=
{}
field
=
serializers
.
DateTimeField
(
default_timezone
=
pytz
.
timezone
(
'America/New_York'
))
class
MockTimezone
:
@staticmethod
def
localize
(
value
,
is_dst
):
raise
compat
.
InvalidTimeError
()
def
__str__
(
self
):
return
'America/New_York'
field
=
serializers
.
DateTimeField
(
default_timezone
=
MockTimezone
())
class
TestTimeField
(
FieldValues
):
class
TestTimeField
(
FieldValues
):
...
...
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