def test_not_required_false(self): f = RestBooleanField(required=False) self.assertEqual(False, f.clean('false'))
def test_None(self): f = RestBooleanField() with self.assertRaises(ValidationError): f.clean(None)
def test_not_required_1(self): f = RestBooleanField(required=False) self.assertEqual(True, f.clean('1'))
def test_empty_string(self): f = RestBooleanField() self.assertEqual(False, f.clean(''))
def test_not_empty_string(self): f = RestBooleanField() self.assertEqual(True, f.clean('some_text'))
def test_false(self): f = RestBooleanField() self.assertEqual(False, f.clean('false'))
def test_0(self): f = RestBooleanField() self.assertEqual(False, f.clean('0'))
def test_true(self): f = RestBooleanField() self.assertEqual(True, f.clean('true'))
def test_1(self): f = RestBooleanField() self.assertEqual(True, f.clean('1'))
def test_empty_value_validators(self): # By default django skips run_validators methods, if value is in empty_values # It's not correct for REST, as empty value is not equal to None value now f = RestBooleanField(validators=[TestErrorValidator(0)]) with self.assertRaises(ValidationError): f.clean('')
def test_initial_false(self): f = RestBooleanField(required=False, initial=False) self.assertEqual(False, f.clean(None))
def test_not_required_None(self): f = RestBooleanField(required=False) self.assertEqual(None, f.clean(None))
def test_not_required_not_empty_string(self): f = RestBooleanField(required=False) self.assertEqual(True, f.clean('some_text'))
def test_not_required_empty_string(self): f = RestBooleanField(required=False) self.assertEqual(False, f.clean(''))