Created
February 27, 2015 00:55
-
-
Save hirokiky/ab7819429901193d3d8f to your computer and use it in GitHub Desktop.
BooleanField with Django 1.7
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__.RequiredForm'> | |
======== Should be True: True ========== | |
is_valid: True | |
cleaned_data: {'is_test': True} | |
======== Should be True: true ========== | |
is_valid: True | |
cleaned_data: {'is_test': True} | |
======== Should be True: 1 ========== | |
is_valid: True | |
cleaned_data: {'is_test': True} | |
======== Should be False: False ========== | |
is_valid: False | |
cleaned_data: {} | |
======== Should be False: false ========== | |
is_valid: False | |
cleaned_data: {} | |
======== Should be False: 0 ========== | |
is_valid: True | |
cleaned_data: {'is_test': True} | |
======== Should be False: ========== | |
is_valid: False | |
cleaned_data: {} | |
Testitg: <class '__main__.NotrequiredForm'> | |
======== Should be True: True ========== | |
is_valid: True | |
cleaned_data: {'is_test': True} | |
======== Should be True: true ========== | |
is_valid: True | |
cleaned_data: {'is_test': True} | |
======== Should be True: 1 ========== | |
is_valid: True | |
cleaned_data: {'is_test': True} | |
======== Should be False: False ========== | |
is_valid: True | |
cleaned_data: {'is_test': False} | |
======== Should be False: false ========== | |
is_valid: True | |
cleaned_data: {'is_test': False} | |
======== Should be False: 0 ========== | |
is_valid: True | |
cleaned_data: {'is_test': True} | |
======== Should be False: ========== | |
is_valid: True | |
cleaned_data: {'is_test': False} |
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 | |
from django import forms | |
class RequiredForm(forms.Form): | |
is_test = forms.BooleanField(required=True) | |
class NotrequiredForm(forms.Form): | |
is_test = forms.BooleanField(required=False) | |
if __name__ == "__main__": | |
settings.configure() | |
django.setup() | |
trues = ( | |
"True", | |
"true", | |
"1", | |
) | |
falses = ( | |
"False", | |
"false", | |
"0", | |
"", | |
) | |
for form_class in (RequiredForm, NotrequiredForm): | |
print("Testitg:", form_class) | |
for tr in trues: | |
f = form_class({"is_test": tr}) | |
print("======== Should be True:", tr, "==========") | |
print("is_valid:", f.is_valid()) | |
print("cleaned_data:", f.cleaned_data) | |
for fl in falses: | |
f = form_class({"is_test": fl}) | |
print("======== Should be False:", fl, "==========") | |
print("is_valid:", f.is_valid()) | |
print("cleaned_data:", f.cleaned_data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment