Created
February 27, 2015 01:37
-
-
Save hirokiky/e7374066cc7d6e1c65bb to your computer and use it in GitHub Desktop.
BooleanField djangorestframework 3.0.3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Testitg: <class '__main__.RequiredSerializer'> | |
======== Should be True: True ========== | |
is_valid: True | |
data: ReturnDict([('is_test', True)]) | |
======== Should be True: true ========== | |
is_valid: True | |
data: ReturnDict([('is_test', True)]) | |
======== Should be True: 1 ========== | |
is_valid: True | |
data: ReturnDict([('is_test', True)]) | |
======== Should be False: False ========== | |
is_valid: True | |
data: ReturnDict([('is_test', False)]) | |
======== Should be False: false ========== | |
is_valid: True | |
data: ReturnDict([('is_test', False)]) | |
======== Should be False: 0 ========== | |
is_valid: True | |
data: ReturnDict([('is_test', False)]) | |
======== Should be False: ========== | |
is_valid: False | |
data: ReturnDict([('is_test', '')]) | |
Testitg: <class '__main__.NotrequiredSerializer'> | |
======== Should be True: True ========== | |
is_valid: True | |
data: ReturnDict([('is_test', True)]) | |
======== Should be True: true ========== | |
is_valid: True | |
data: ReturnDict([('is_test', True)]) | |
======== Should be True: 1 ========== | |
is_valid: True | |
data: ReturnDict([('is_test', True)]) | |
======== Should be False: False ========== | |
is_valid: True | |
data: ReturnDict([('is_test', False)]) | |
======== Should be False: false ========== | |
is_valid: True | |
data: ReturnDict([('is_test', False)]) | |
======== Should be False: 0 ========== | |
is_valid: True | |
data: ReturnDict([('is_test', False)]) | |
======== Should be False: ========== | |
is_valid: False | |
data: ReturnDict([('is_test', '')]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import django | |
from django.conf import settings | |
settings.configure( | |
INSTALLED_APPS=["rest_framework"], | |
) | |
django.setup() | |
from rest_framework import serializers | |
class RequiredSerializer(serializers.Serializer): | |
is_test = serializers.BooleanField(required=True) | |
class NotrequiredSerializer(serializers.Serializer): | |
is_test = serializers.BooleanField(required=False) | |
if __name__ == "__main__": | |
trues = ( | |
"True", | |
"true", | |
"1", | |
) | |
falses = ( | |
"False", | |
"false", | |
"0", | |
"", | |
) | |
for s_class in (RequiredSerializer, NotrequiredSerializer): | |
print("Testitg:", s_class) | |
for tr in trues: | |
s = s_class(data={"is_test": tr}) | |
print("======== Should be True:", tr, "==========") | |
print("is_valid:", s.is_valid()) | |
print("data:", s.data) | |
for fl in falses: | |
s = s_class(data={"is_test": fl}) | |
print("======== Should be False:", fl, "==========") | |
print("is_valid:", s.is_valid()) | |
print("data:", s.data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment