aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_serializer.py
diff options
context:
space:
mode:
authorXavier Ordoquy2014-05-01 08:01:38 +0200
committerXavier Ordoquy2014-05-01 08:01:38 +0200
commit7b4463f73983e36f228e6af0ff8c921d4698a9b3 (patch)
treec26fd01425a3754e65a0b2c48694ca734278745f /tests/test_serializer.py
parent2aca69a94601858a462060bc55154c812f70fb91 (diff)
parentc9e6f31166ebccc5c3bf2f27e12a6d6c87f5cf22 (diff)
downloaddjango-rest-framework-7b4463f73983e36f228e6af0ff8c921d4698a9b3.tar.bz2
Merge remote-tracking branch 'reference/2.4.0' into feature/pytest
Conflicts: rest_framework/runtests/urls.py tests/test_response.py tox.ini
Diffstat (limited to 'tests/test_serializer.py')
-rw-r--r--tests/test_serializer.py28
1 files changed, 25 insertions, 3 deletions
diff --git a/tests/test_serializer.py b/tests/test_serializer.py
index 73eb5c79..98936ae8 100644
--- a/tests/test_serializer.py
+++ b/tests/test_serializer.py
@@ -30,6 +30,7 @@ if PIL is not None:
image_field = models.ImageField(upload_to='test', max_length=1024, blank=True)
slug_field = models.SlugField(max_length=1024, blank=True)
url_field = models.URLField(max_length=1024, blank=True)
+ nullable_char_field = models.CharField(max_length=1024, blank=True, null=True)
class DVOAFModel(RESTFrameworkModel):
positive_integer_field = models.PositiveIntegerField(blank=True)
@@ -660,7 +661,7 @@ class ModelValidationTests(TestCase):
second_serializer = AlbumsSerializer(data={'title': 'a'})
self.assertFalse(second_serializer.is_valid())
self.assertEqual(second_serializer.errors, {'title': ['Album with this Title already exists.'],})
- third_serializer = AlbumsSerializer(data=[{'title': 'b', 'ref': '1'}, {'title': 'c'}])
+ third_serializer = AlbumsSerializer(data=[{'title': 'b', 'ref': '1'}, {'title': 'c'}], many=True)
self.assertFalse(third_serializer.is_valid())
self.assertEqual(third_serializer.errors, [{'ref': ['Album with this Ref already exists.']}, {}])
@@ -1257,6 +1258,20 @@ class BlankFieldTests(TestCase):
serializer = self.model_serializer_class(data={})
self.assertEqual(serializer.is_valid(), True)
+ def test_create_model_null_field_save(self):
+ """
+ Regression test for #1330.
+
+ https://github.com/tomchristie/django-rest-framework/pull/1330
+ """
+ serializer = self.model_serializer_class(data={'title': None})
+ self.assertEqual(serializer.is_valid(), True)
+
+ try:
+ serializer.save()
+ except Exception:
+ self.fail('Exception raised on save() after validation passes')
+
#test for issue #460
class SerializerPickleTests(TestCase):
@@ -1491,7 +1506,7 @@ class NestedSerializerContextTests(TestCase):
model = Album
fields = ("photo_set", "callable")
- photo_set = PhotoSerializer(source="photo_set")
+ photo_set = PhotoSerializer(source="photo_set", many=True)
callable = serializers.SerializerMethodField("_callable")
def _callable(self, instance):
@@ -1503,7 +1518,7 @@ class NestedSerializerContextTests(TestCase):
albums = None
class AlbumCollectionSerializer(serializers.Serializer):
- albums = AlbumSerializer(source="albums")
+ albums = AlbumSerializer(source="albums", many=True)
album1 = Album.objects.create(title="album 1")
album2 = Album.objects.create(title="album 2")
@@ -1660,6 +1675,10 @@ class AttributeMappingOnAutogeneratedFieldsTests(TestCase):
'url_field': [
('max_length', 1024),
],
+ 'nullable_char_field': [
+ ('max_length', 1024),
+ ('allow_none', True),
+ ],
}
def field_test(self, field):
@@ -1696,6 +1715,9 @@ class AttributeMappingOnAutogeneratedFieldsTests(TestCase):
def test_url_field(self):
self.field_test('url_field')
+ def test_nullable_char_field(self):
+ self.field_test('nullable_char_field')
+
@unittest.skipUnless(PIL is not None, 'PIL is not installed')
class DefaultValuesOnAutogeneratedFieldsTests(TestCase):