mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-10 19:56:59 +03:00
Merge pull request #4824 from auvipy/newv
new matrix for python 3.6 and django 1.11
This commit is contained in:
commit
5e9249f429
16
.travis.yml
16
.travis.yml
|
@ -2,7 +2,6 @@ language: python
|
|||
|
||||
python:
|
||||
- "2.7"
|
||||
- "3.3"
|
||||
- "3.4"
|
||||
- "3.5"
|
||||
|
||||
|
@ -12,6 +11,7 @@ env:
|
|||
- DJANGO=1.8
|
||||
- DJANGO=1.9
|
||||
- DJANGO=1.10
|
||||
- DJANGO=1.11
|
||||
- DJANGO=master
|
||||
|
||||
matrix:
|
||||
|
@ -19,19 +19,23 @@ matrix:
|
|||
include:
|
||||
- python: "3.6"
|
||||
env: DJANGO=master
|
||||
- python: "3.6"
|
||||
env: DJANGO=1.11
|
||||
- python: "3.3"
|
||||
env: DJANGO=1.18
|
||||
- python: "2.7"
|
||||
env: TOXENV="lint"
|
||||
- python: "2.7"
|
||||
env: TOXENV="docs"
|
||||
exclude:
|
||||
- python: "3.3"
|
||||
env: DJANGO=1.9
|
||||
- python: "3.3"
|
||||
env: DJANGO=1.10
|
||||
- python: "3.3"
|
||||
- python: "2.7"
|
||||
env: DJANGO=master
|
||||
- python: "3.4"
|
||||
env: DJANGO=master
|
||||
|
||||
allow_failures:
|
||||
- env: DJANGO=master
|
||||
- env: DJANGO=1.11
|
||||
|
||||
install:
|
||||
- pip install tox tox-travis
|
||||
|
|
|
@ -312,3 +312,12 @@ def set_many(instance, field, value):
|
|||
else:
|
||||
field = getattr(instance, field)
|
||||
field.set(value)
|
||||
|
||||
|
||||
try:
|
||||
# A `utc` instance is available in Django 1.11+
|
||||
from django.utils.timezone import utc
|
||||
except ImportError:
|
||||
# A `UTC` class is available in older versions
|
||||
from django.utils.timezone import UTC
|
||||
utc = UTC()
|
||||
|
|
|
@ -32,7 +32,7 @@ from django.utils.translation import ugettext_lazy as _
|
|||
|
||||
from rest_framework import ISO_8601
|
||||
from rest_framework.compat import (
|
||||
get_remote_field, unicode_repr, unicode_to_repr, value_from_object
|
||||
get_remote_field, unicode_repr, unicode_to_repr, utc, value_from_object
|
||||
)
|
||||
from rest_framework.exceptions import ErrorDetail, ValidationError
|
||||
from rest_framework.settings import api_settings
|
||||
|
@ -1104,7 +1104,7 @@ class DateTimeField(Field):
|
|||
if (field_timezone is not None) and not timezone.is_aware(value):
|
||||
return timezone.make_aware(value, field_timezone)
|
||||
elif (field_timezone is None) and timezone.is_aware(value):
|
||||
return timezone.make_naive(value, timezone.UTC())
|
||||
return timezone.make_naive(value, utc)
|
||||
return value
|
||||
|
||||
def default_timezone(self):
|
||||
|
|
|
@ -8,10 +8,11 @@ from decimal import Decimal
|
|||
import pytest
|
||||
from django.http import QueryDict
|
||||
from django.test import TestCase, override_settings
|
||||
from django.utils import six, timezone
|
||||
from django.utils import six
|
||||
|
||||
import rest_framework
|
||||
from rest_framework import serializers
|
||||
from rest_framework.compat import utc
|
||||
from rest_framework.fields import is_simple_callable
|
||||
|
||||
try:
|
||||
|
@ -1129,13 +1130,13 @@ class TestDateTimeField(FieldValues):
|
|||
Valid and invalid values for `DateTimeField`.
|
||||
"""
|
||||
valid_inputs = {
|
||||
'2001-01-01 13:00': datetime.datetime(2001, 1, 1, 13, 00, tzinfo=timezone.UTC()),
|
||||
'2001-01-01T13:00': datetime.datetime(2001, 1, 1, 13, 00, tzinfo=timezone.UTC()),
|
||||
'2001-01-01T13:00Z': datetime.datetime(2001, 1, 1, 13, 00, tzinfo=timezone.UTC()),
|
||||
datetime.datetime(2001, 1, 1, 13, 00): datetime.datetime(2001, 1, 1, 13, 00, tzinfo=timezone.UTC()),
|
||||
datetime.datetime(2001, 1, 1, 13, 00, tzinfo=timezone.UTC()): datetime.datetime(2001, 1, 1, 13, 00, tzinfo=timezone.UTC()),
|
||||
'2001-01-01 13:00': datetime.datetime(2001, 1, 1, 13, 00, tzinfo=utc),
|
||||
'2001-01-01T13:00': datetime.datetime(2001, 1, 1, 13, 00, tzinfo=utc),
|
||||
'2001-01-01T13:00Z': datetime.datetime(2001, 1, 1, 13, 00, tzinfo=utc),
|
||||
datetime.datetime(2001, 1, 1, 13, 00): datetime.datetime(2001, 1, 1, 13, 00, tzinfo=utc),
|
||||
datetime.datetime(2001, 1, 1, 13, 00, tzinfo=utc): datetime.datetime(2001, 1, 1, 13, 00, tzinfo=utc),
|
||||
# Django 1.4 does not support timezone string parsing.
|
||||
'2001-01-01T13:00Z': datetime.datetime(2001, 1, 1, 13, 00, tzinfo=timezone.UTC())
|
||||
'2001-01-01T13:00Z': datetime.datetime(2001, 1, 1, 13, 00, tzinfo=utc)
|
||||
}
|
||||
invalid_inputs = {
|
||||
'abc': ['Datetime has wrong format. Use one of these formats instead: YYYY-MM-DDThh:mm[:ss[.uuuuuu]][+HH:MM|-HH:MM|Z].'],
|
||||
|
@ -1144,13 +1145,13 @@ class TestDateTimeField(FieldValues):
|
|||
}
|
||||
outputs = {
|
||||
datetime.datetime(2001, 1, 1, 13, 00): '2001-01-01T13:00:00',
|
||||
datetime.datetime(2001, 1, 1, 13, 00, tzinfo=timezone.UTC()): '2001-01-01T13:00:00Z',
|
||||
datetime.datetime(2001, 1, 1, 13, 00, tzinfo=utc): '2001-01-01T13:00:00Z',
|
||||
'2001-01-01T00:00:00': '2001-01-01T00:00:00',
|
||||
six.text_type('2016-01-10T00:00:00'): '2016-01-10T00:00:00',
|
||||
None: None,
|
||||
'': None,
|
||||
}
|
||||
field = serializers.DateTimeField(default_timezone=timezone.UTC())
|
||||
field = serializers.DateTimeField(default_timezone=utc)
|
||||
|
||||
|
||||
class TestCustomInputFormatDateTimeField(FieldValues):
|
||||
|
@ -1158,13 +1159,13 @@ class TestCustomInputFormatDateTimeField(FieldValues):
|
|||
Valid and invalid values for `DateTimeField` with a custom input format.
|
||||
"""
|
||||
valid_inputs = {
|
||||
'1:35pm, 1 Jan 2001': datetime.datetime(2001, 1, 1, 13, 35, tzinfo=timezone.UTC()),
|
||||
'1:35pm, 1 Jan 2001': datetime.datetime(2001, 1, 1, 13, 35, tzinfo=utc),
|
||||
}
|
||||
invalid_inputs = {
|
||||
'2001-01-01T20:50': ['Datetime has wrong format. Use one of these formats instead: hh:mm[AM|PM], DD [Jan-Dec] YYYY.']
|
||||
}
|
||||
outputs = {}
|
||||
field = serializers.DateTimeField(default_timezone=timezone.UTC(), input_formats=['%I:%M%p, %d %b %Y'])
|
||||
field = serializers.DateTimeField(default_timezone=utc, input_formats=['%I:%M%p, %d %b %Y'])
|
||||
|
||||
|
||||
class TestCustomOutputFormatDateTimeField(FieldValues):
|
||||
|
@ -1196,7 +1197,7 @@ class TestNaiveDateTimeField(FieldValues):
|
|||
Valid and invalid values for `DateTimeField` with naive datetimes.
|
||||
"""
|
||||
valid_inputs = {
|
||||
datetime.datetime(2001, 1, 1, 13, 00, tzinfo=timezone.UTC()): datetime.datetime(2001, 1, 1, 13, 00),
|
||||
datetime.datetime(2001, 1, 1, 13, 00, tzinfo=utc): datetime.datetime(2001, 1, 1, 13, 00),
|
||||
'2001-01-01 13:00': datetime.datetime(2001, 1, 1, 13, 00),
|
||||
}
|
||||
invalid_inputs = {}
|
||||
|
|
7
tox.ini
7
tox.ini
|
@ -5,7 +5,8 @@ addopts=--tb=short
|
|||
envlist =
|
||||
{py27,py33,py34,py35}-django18,
|
||||
{py27,py34,py35}-django{19,110},
|
||||
{py27,py34,py35,py36}-djangomaster,
|
||||
{py27,py34,py35,py36}-django111,
|
||||
{py35,py36}-djangomaster
|
||||
lint,docs
|
||||
|
||||
[travis:env]
|
||||
|
@ -13,6 +14,7 @@ DJANGO =
|
|||
1.8: django18
|
||||
1.9: django19
|
||||
1.10: django110
|
||||
1.11: django111
|
||||
master: djangomaster
|
||||
|
||||
[testenv]
|
||||
|
@ -22,8 +24,9 @@ setenv =
|
|||
PYTHONWARNINGS=once
|
||||
deps =
|
||||
django18: Django>=1.8,<1.9
|
||||
django19: Django>=1.9,<.1.10
|
||||
django19: Django>=1.9,<1.10
|
||||
django110: Django>=1.10,<1.11
|
||||
django111: Django>=1.11a1,<2.0
|
||||
djangomaster: https://github.com/django/django/archive/master.tar.gz
|
||||
-rrequirements/requirements-testing.txt
|
||||
-rrequirements/requirements-optionals.txt
|
||||
|
|
Loading…
Reference in New Issue
Block a user