mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-27 03:54:01 +03:00
Fix for python 3 support
This commit is contained in:
parent
956a65f5af
commit
36d5b24b76
|
@ -184,17 +184,17 @@ class DateFieldTest(TestCase):
|
||||||
def test_wrong_default_date_input_format(self):
|
def test_wrong_default_date_input_format(self):
|
||||||
serializer = DateObjectSerializer(data={'date': 'something wrong'})
|
serializer = DateObjectSerializer(data={'date': 'something wrong'})
|
||||||
self.assertFalse(serializer.is_valid())
|
self.assertFalse(serializer.is_valid())
|
||||||
self.assertEquals(serializer.errors, {'date': [u'Date has wrong format. Use one of these formats instead: '
|
self.assertEquals(serializer.errors, {'date': ['Date has wrong format. Use one of these formats instead: '
|
||||||
u'YYYY-MM-DD; MM/DD/YYYY; MM/DD/YY; [Jan through Dec] DD YYYY; '
|
'YYYY-MM-DD; MM/DD/YYYY; MM/DD/YY; [Jan through Dec] DD YYYY; '
|
||||||
u'[Jan through Dec] DD, YYYY; DD [Jan through Dec] YYYY; '
|
'[Jan through Dec] DD, YYYY; DD [Jan through Dec] YYYY; '
|
||||||
u'DD [Jan through Dec], YYYY; [January through December] DD YYYY; '
|
'DD [Jan through Dec], YYYY; [January through December] DD YYYY; '
|
||||||
u'[January through December] DD, YYYY; DD [January through December] YYYY; '
|
'[January through December] DD, YYYY; DD [January through December] YYYY; '
|
||||||
u'DD [January through December], YYYY']})
|
'DD [January through December], YYYY']})
|
||||||
|
|
||||||
def test_wrong_custom_date_input_format(self):
|
def test_wrong_custom_date_input_format(self):
|
||||||
serializer = DateObjectCustomFormatSerializer(data={'date': '07/31/1984'})
|
serializer = DateObjectCustomFormatSerializer(data={'date': '07/31/1984'})
|
||||||
self.assertFalse(serializer.is_valid())
|
self.assertFalse(serializer.is_valid())
|
||||||
self.assertEquals(serializer.errors, {'date': [u'Date has wrong format. Use one of these formats instead: YYYY; YYYY -- MM']})
|
self.assertEquals(serializer.errors, {'date': ['Date has wrong format. Use one of these formats instead: YYYY; YYYY -- MM']})
|
||||||
|
|
||||||
def test_from_native(self):
|
def test_from_native(self):
|
||||||
f = serializers.DateField()
|
f = serializers.DateField()
|
||||||
|
@ -223,12 +223,12 @@ class DateFieldTest(TestCase):
|
||||||
try:
|
try:
|
||||||
f.from_native('1984-42-31')
|
f.from_native('1984-42-31')
|
||||||
except validators.ValidationError as e:
|
except validators.ValidationError as e:
|
||||||
self.assertEqual(e.messages, [u'Date has wrong format. Use one of these formats instead: '
|
self.assertEqual(e.messages, ['Date has wrong format. Use one of these formats instead: '
|
||||||
u'YYYY-MM-DD; MM/DD/YYYY; MM/DD/YY; [Jan through Dec] DD YYYY; '
|
'YYYY-MM-DD; MM/DD/YYYY; MM/DD/YY; [Jan through Dec] DD YYYY; '
|
||||||
u'[Jan through Dec] DD, YYYY; DD [Jan through Dec] YYYY; '
|
'[Jan through Dec] DD, YYYY; DD [Jan through Dec] YYYY; '
|
||||||
u'DD [Jan through Dec], YYYY; [January through December] DD YYYY; '
|
'DD [Jan through Dec], YYYY; [January through December] DD YYYY; '
|
||||||
u'[January through December] DD, YYYY; DD [January through December] YYYY; '
|
'[January through December] DD, YYYY; DD [January through December] YYYY; '
|
||||||
u'DD [January through December], YYYY'])
|
'DD [January through December], YYYY'])
|
||||||
else:
|
else:
|
||||||
self.fail("ValidationError was not properly raised")
|
self.fail("ValidationError was not properly raised")
|
||||||
|
|
||||||
|
@ -284,25 +284,25 @@ class DateTimeFieldTest(TestCase):
|
||||||
def test_wrong_default_date_time_input_format_for_django_gte_1_4(self):
|
def test_wrong_default_date_time_input_format_for_django_gte_1_4(self):
|
||||||
serializer = DateTimeObjectSerializer(data={'date_time': 'something wrong'})
|
serializer = DateTimeObjectSerializer(data={'date_time': 'something wrong'})
|
||||||
self.assertFalse(serializer.is_valid())
|
self.assertFalse(serializer.is_valid())
|
||||||
self.assertEquals(serializer.errors, {'date_time': [u'Datetime has wrong format. Use one of these formats instead: '
|
self.assertEquals(serializer.errors, {'date_time': ['Datetime has wrong format. Use one of these formats instead: '
|
||||||
u'YYYY-MM-DD HH:MM:SS; YYYY-MM-DD HH:MM:SS.uuuuuu; YYYY-MM-DD HH:MM; '
|
'YYYY-MM-DD HH:MM:SS; YYYY-MM-DD HH:MM:SS.uuuuuu; YYYY-MM-DD HH:MM; '
|
||||||
u'YYYY-MM-DD; MM/DD/YYYY HH:MM:SS; MM/DD/YYYY HH:MM:SS.uuuuuu; '
|
'YYYY-MM-DD; MM/DD/YYYY HH:MM:SS; MM/DD/YYYY HH:MM:SS.uuuuuu; '
|
||||||
u'MM/DD/YYYY HH:MM; MM/DD/YYYY; MM/DD/YY HH:MM:SS; '
|
'MM/DD/YYYY HH:MM; MM/DD/YYYY; MM/DD/YY HH:MM:SS; '
|
||||||
u'MM/DD/YY HH:MM:SS.uuuuuu; MM/DD/YY HH:MM; MM/DD/YY']})
|
'MM/DD/YY HH:MM:SS.uuuuuu; MM/DD/YY HH:MM; MM/DD/YY']})
|
||||||
|
|
||||||
@unittest.skipUnless(django.VERSION < (1, 4), "django >= 1.4 have microseconds in default settings")
|
@unittest.skipUnless(django.VERSION < (1, 4), "django >= 1.4 have microseconds in default settings")
|
||||||
def test_wrong_default_date_time_input_format_for_django_lt_1_4(self):
|
def test_wrong_default_date_time_input_format_for_django_lt_1_4(self):
|
||||||
serializer = DateTimeObjectSerializer(data={'date_time': 'something wrong'})
|
serializer = DateTimeObjectSerializer(data={'date_time': 'something wrong'})
|
||||||
self.assertFalse(serializer.is_valid())
|
self.assertFalse(serializer.is_valid())
|
||||||
self.assertEquals(serializer.errors, {'date_time': [u'Datetime has wrong format. Use one of these formats instead:'
|
self.assertEquals(serializer.errors, {'date_time': ['Datetime has wrong format. Use one of these formats instead: '
|
||||||
u' YYYY-MM-DD HH:MM:SS; YYYY-MM-DD HH:MM; YYYY-MM-DD; '
|
'YYYY-MM-DD HH:MM:SS; YYYY-MM-DD HH:MM; YYYY-MM-DD; '
|
||||||
u'MM/DD/YYYY HH:MM:SS; MM/DD/YYYY HH:MM; MM/DD/YYYY; '
|
'MM/DD/YYYY HH:MM:SS; MM/DD/YYYY HH:MM; MM/DD/YYYY; '
|
||||||
u'MM/DD/YY HH:MM:SS; MM/DD/YY HH:MM; MM/DD/YY']})
|
'MM/DD/YY HH:MM:SS; MM/DD/YY HH:MM; MM/DD/YY']})
|
||||||
|
|
||||||
def test_wrong_custom_date_time_input_format(self):
|
def test_wrong_custom_date_time_input_format(self):
|
||||||
serializer = DateTimeObjectCustomFormatSerializer(data={'date_time': '07/31/84 04:31'})
|
serializer = DateTimeObjectCustomFormatSerializer(data={'date_time': '07/31/84 04:31'})
|
||||||
self.assertFalse(serializer.is_valid())
|
self.assertFalse(serializer.is_valid())
|
||||||
self.assertEquals(serializer.errors, {'date_time': [u'Datetime has wrong format. Use one of these formats instead: YYYY; YYYY HH:MM']})
|
self.assertEquals(serializer.errors, {'date_time': ['Datetime has wrong format. Use one of these formats instead: YYYY; YYYY HH:MM']})
|
||||||
|
|
||||||
def test_from_native(self):
|
def test_from_native(self):
|
||||||
f = serializers.DateTimeField()
|
f = serializers.DateTimeField()
|
||||||
|
@ -326,31 +326,31 @@ class DateTimeFieldTest(TestCase):
|
||||||
self.assertEqual(result, None)
|
self.assertEqual(result, None)
|
||||||
|
|
||||||
@unittest.skipUnless(django.VERSION >= (1, 4), "django < 1.4 don't have microseconds in default settings")
|
@unittest.skipUnless(django.VERSION >= (1, 4), "django < 1.4 don't have microseconds in default settings")
|
||||||
def test_from_native_invalid_datetime(self):
|
def test_from_native_invalid_datetime_for_django_gte_1_4(self):
|
||||||
f = serializers.DateTimeField()
|
f = serializers.DateTimeField()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
f.from_native('1984-42-31 04:31')
|
f.from_native('1984-42-31 04:31')
|
||||||
except validators.ValidationError as e:
|
except validators.ValidationError as e:
|
||||||
self.assertEqual(e.messages, [u'Datetime has wrong format. Use one of these formats instead: '
|
self.assertEqual(e.messages, ['Datetime has wrong format. Use one of these formats instead: '
|
||||||
u'YYYY-MM-DD HH:MM:SS; YYYY-MM-DD HH:MM:SS.uuuuuu; YYYY-MM-DD HH:MM; '
|
'YYYY-MM-DD HH:MM:SS; YYYY-MM-DD HH:MM:SS.uuuuuu; YYYY-MM-DD HH:MM; '
|
||||||
u'YYYY-MM-DD; MM/DD/YYYY HH:MM:SS; MM/DD/YYYY HH:MM:SS.uuuuuu; '
|
'YYYY-MM-DD; MM/DD/YYYY HH:MM:SS; MM/DD/YYYY HH:MM:SS.uuuuuu; '
|
||||||
u'MM/DD/YYYY HH:MM; MM/DD/YYYY; MM/DD/YY HH:MM:SS; '
|
'MM/DD/YYYY HH:MM; MM/DD/YYYY; MM/DD/YY HH:MM:SS; '
|
||||||
u'MM/DD/YY HH:MM:SS.uuuuuu; MM/DD/YY HH:MM; MM/DD/YY'])
|
'MM/DD/YY HH:MM:SS.uuuuuu; MM/DD/YY HH:MM; MM/DD/YY'])
|
||||||
else:
|
else:
|
||||||
self.fail("ValidationError was not properly raised")
|
self.fail("ValidationError was not properly raised")
|
||||||
|
|
||||||
@unittest.skipUnless(django.VERSION < (1, 4), "django >= 1.4 have microseconds in default settings")
|
@unittest.skipUnless(django.VERSION < (1, 4), "django >= 1.4 have microseconds in default settings")
|
||||||
def test_from_native_invalid_datetime(self):
|
def test_from_native_invalid_datetime_for_django_lt_1_4(self):
|
||||||
f = serializers.DateTimeField()
|
f = serializers.DateTimeField()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
f.from_native('1984-42-31 04:31')
|
f.from_native('1984-42-31 04:31')
|
||||||
except validators.ValidationError as e:
|
except validators.ValidationError as e:
|
||||||
self.assertEqual(e.messages, [u'Datetime has wrong format. Use one of these formats instead:'
|
self.assertEqual(e.messages, ['Datetime has wrong format. Use one of these formats instead: '
|
||||||
u' YYYY-MM-DD HH:MM:SS; YYYY-MM-DD HH:MM; YYYY-MM-DD; '
|
'YYYY-MM-DD HH:MM:SS; YYYY-MM-DD HH:MM; YYYY-MM-DD; '
|
||||||
u'MM/DD/YYYY HH:MM:SS; MM/DD/YYYY HH:MM; MM/DD/YYYY; '
|
'MM/DD/YYYY HH:MM:SS; MM/DD/YYYY HH:MM; MM/DD/YYYY; '
|
||||||
u'MM/DD/YY HH:MM:SS; MM/DD/YY HH:MM; MM/DD/YY'])
|
'MM/DD/YY HH:MM:SS; MM/DD/YY HH:MM; MM/DD/YY'])
|
||||||
else:
|
else:
|
||||||
self.fail("ValidationError was not properly raised")
|
self.fail("ValidationError was not properly raised")
|
||||||
|
|
||||||
|
@ -373,12 +373,12 @@ class TimeFieldTest(TestCase):
|
||||||
def test_wrong_default_time_input_format(self):
|
def test_wrong_default_time_input_format(self):
|
||||||
serializer = TimeObjectSerializer(data={'time': 'something wrong'})
|
serializer = TimeObjectSerializer(data={'time': 'something wrong'})
|
||||||
self.assertFalse(serializer.is_valid())
|
self.assertFalse(serializer.is_valid())
|
||||||
self.assertEquals(serializer.errors, {'time': [u'Time has wrong format. Use one of these formats instead: HH:MM:SS; HH:MM']})
|
self.assertEquals(serializer.errors, {'time': ['Time has wrong format. Use one of these formats instead: HH:MM:SS; HH:MM']})
|
||||||
|
|
||||||
def test_wrong_custom_time_input_format(self):
|
def test_wrong_custom_time_input_format(self):
|
||||||
serializer = TimeObjectCustomFormatSerializer(data={'time': '04:31'})
|
serializer = TimeObjectCustomFormatSerializer(data={'time': '04:31'})
|
||||||
self.assertFalse(serializer.is_valid())
|
self.assertFalse(serializer.is_valid())
|
||||||
self.assertEquals(serializer.errors, {'time': [u'Time has wrong format. Use one of these formats instead: HH -- MM; HHMMSS']})
|
self.assertEquals(serializer.errors, {'time': ['Time has wrong format. Use one of these formats instead: HH -- MM; HHMMSS']})
|
||||||
|
|
||||||
def test_from_native(self):
|
def test_from_native(self):
|
||||||
f = serializers.TimeField()
|
f = serializers.TimeField()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user