From 6bea275de815e37dc6743213eaa1e54a31c473df Mon Sep 17 00:00:00 2001 From: Kevin Stone Date: Wed, 6 Mar 2013 15:15:19 -0800 Subject: [PATCH] Added failing test cases for giving a DateField or DateTimeField a None value to serialize. Signed-off-by: Kevin Stone --- rest_framework/tests/fields.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/rest_framework/tests/fields.py b/rest_framework/tests/fields.py index 28f18ed89..fd6de7797 100644 --- a/rest_framework/tests/fields.py +++ b/rest_framework/tests/fields.py @@ -171,6 +171,13 @@ class DateFieldTest(TestCase): self.assertEqual('1984 - 07.31', result_1) + def test_to_native_none(self): + """ + Make sure from_native() returns None on None param. + """ + f = serializers.DateField(required=False) + self.assertEqual(None, f.to_native(None)) + class DateTimeFieldTest(TestCase): """ @@ -303,6 +310,13 @@ class DateTimeFieldTest(TestCase): self.assertEqual('1984 - 04:31', result_3) self.assertEqual('1984 - 04:31', result_4) + def test_to_native_none(self): + """ + Make sure from_native() returns None on None param. + """ + f = serializers.DateTimeField(required=False) + self.assertEqual(None, f.to_native(None)) + class TimeFieldTest(TestCase): """