Test deserialising data including None fk

This commit is contained in:
Carlton Gibson 2016-02-10 10:07:11 +01:00
parent 20d1fdba69
commit cbb8d8d254

View File

@ -49,7 +49,7 @@ class NullableUUIDForeignKeySourceSerializer(serializers.ModelSerializer):
target = serializers.PrimaryKeyRelatedField(
pk_field=serializers.UUIDField(),
queryset=UUIDForeignKeyTarget.objects.all(),
allow_empty=True)
allow_null=True)
class Meta:
model = NullableUUIDForeignKeySource
@ -451,6 +451,11 @@ class PKNullableForeignKeyTests(TestCase):
data = serializer.data
self.assertEqual(data["target"], None)
def test_nullable_uuid_foreign_key_is_valid_when_none(self):
data = {"name": "Source", "target": None}
serializer = NullableUUIDForeignKeySourceSerializer(data=data)
self.assertTrue(serializer.is_valid(), serializer.errors)
class PKNullableOneToOneTests(TestCase):
def setUp(self):