def test_is_valid(self): field = BooleanField('', required=False) field.value = True self.assertTrue(field.is_valid) field.value = "yes" self.assertTrue(field.is_valid) field.value = 0 self.assertTrue(field.is_valid) field.value = False self.assertTrue(field.is_valid)
def test_cleaned_data_false(self): field = BooleanField('', required=False) for value in [0, False, 'no', 'false', 'FALSE', 'False', '0', 'null']: field.value = value self.assertIsNone( field.cleaned_value, "invalid value for %r" % (value,) )
def test_cleaned_data_true(self): field = BooleanField('', required=False) for value in [1, True, 'yes', 'true', 'TRUE', 'True', 'LOL', '1', object(), type('', (), {})]: field.value = value self.assertTrue( field.cleaned_value, "invalid value for %s" % value )
def test_cleaned_data_none(self): field = BooleanField('', required=False) field.value = None self.assertIsNone(field.cleaned_value)