django-rest-framework/tests/test_write_only_fields.py
Mads Jensen 6defb8da47 lookup_type is deprecated in favor of lookup_expr (#4259)
* lookup_type is deprecated in favor of lookup_expr
* assertEquals is deprecated in favor of assertEqual
* app_name is a required keyword as of Django 1.10
2016-07-13 14:40:42 +01:00

33 lines
994 B
Python

from django.test import TestCase
from rest_framework import serializers
class WriteOnlyFieldTests(TestCase):
def setUp(self):
class ExampleSerializer(serializers.Serializer):
email = serializers.EmailField()
password = serializers.CharField(write_only=True)
def create(self, attrs):
return attrs
self.Serializer = ExampleSerializer
def write_only_fields_are_present_on_input(self):
data = {
'email': 'foo@example.com',
'password': '123'
}
serializer = self.Serializer(data=data)
self.assertTrue(serializer.is_valid())
self.assertEqual(serializer.validated_data, data)
def write_only_fields_are_not_present_on_output(self):
instance = {
'email': 'foo@example.com',
'password': '123'
}
serializer = self.Serializer(instance)
self.assertEqual(serializer.data, {'email': 'foo@example.com'})