mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 09:36:49 +03:00
added utc compat to tests of fields
This commit is contained in:
parent
bc3849bd59
commit
326e09dde9
|
@ -8,11 +8,12 @@ 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.fields import is_simple_callable
|
||||
from rest_framework.compat import utc
|
||||
|
||||
try:
|
||||
import typings
|
||||
|
@ -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 = {}
|
||||
|
|
Loading…
Reference in New Issue
Block a user