django-rest-framework/tests/test_write_only_fields.py

32 lines
995 B
Python
Raw Permalink Normal View History

2014-09-08 17:24:05 +04:00
from django.test import TestCase
from rest_framework import serializers
2014-09-08 17:24:05 +04:00
class WriteOnlyFieldTests(TestCase):
def setUp(self):
class ExampleSerializer(serializers.Serializer):
email = serializers.EmailField()
password = serializers.CharField(write_only=True)
2014-09-08 17:24:05 +04:00
def create(self, attrs):
return attrs
2014-09-08 17:24:05 +04:00
self.Serializer = ExampleSerializer
2014-09-08 17:24:05 +04:00
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.assertEquals(serializer.validated_data, data)
2014-09-08 17:24:05 +04:00
def write_only_fields_are_not_present_on_output(self):
instance = {
'email': 'foo@example.com',
'password': '123'
}
serializer = self.Serializer(instance)
self.assertEquals(serializer.data, {'email': 'foo@example.com'})