From 735c75abb9e612fa0f1e6bdfa4283610752056d2 Mon Sep 17 00:00:00 2001 From: dpetzel Date: Fri, 18 Oct 2013 21:10:49 -0400 Subject: [PATCH] add test case around ensuring proper field inference for boolean model field types --- rest_framework/tests/models.py | 1 + rest_framework/tests/test_serializer.py | 32 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/rest_framework/tests/models.py b/rest_framework/tests/models.py index 1598ecd94..32a726c0b 100644 --- a/rest_framework/tests/models.py +++ b/rest_framework/tests/models.py @@ -70,6 +70,7 @@ class Comment(RESTFrameworkModel): class ActionItem(RESTFrameworkModel): title = models.CharField(max_length=200) + started = models.NullBooleanField(default=False) done = models.BooleanField(default=False) info = CustomField(default='---', max_length=12) diff --git a/rest_framework/tests/test_serializer.py b/rest_framework/tests/test_serializer.py index 1f85a4749..a7ea3ac0b 100644 --- a/rest_framework/tests/test_serializer.py +++ b/rest_framework/tests/test_serializer.py @@ -1720,3 +1720,35 @@ class TestSerializerTransformMethods(TestCase): 'b_renamed': None, } ) + +class BoolenFieldTypeTest(TestCase): + ''' + Ensure the various Boolean based model fields are rendered as the proper + field type + + ''' + + def setUp(self): + ''' + Setup an ActionItemSerializer for BooleanTesting + ''' + data = { + 'title': 'b' * 201, + } + self.serializer = ActionItemSerializer(data=data) + + def test_booleanfield_type(self): + ''' + Test that BooleanField is infered from models.BooleanField + ''' + bfield = self.serializer.get_fields()['done'] + self.assertEqual(type(bfield), fields.BooleanField) + + def test_nullbooleanfield_type(self): + ''' + Test that BooleanField is infered from models.NullBooleanField + + https://groups.google.com/forum/#!topic/django-rest-framework/D9mXEftpuQ8 + ''' + bfield = self.serializer.get_fields()['started'] + self.assertEqual(type(bfield), fields.BooleanField)