def test_default(self): field = BooleanField(required=True, default=True) field.validate() self.assertEqual(field.to_python(), True) self.assertEqual(field.to_native(), True) field = BooleanField(required=True, default=False) field.validate() self.assertEqual(field.to_python(), False) self.assertEqual(field.to_native(), False)
def test_hide_on_null(self): field = BooleanField(required=False, on_null=HIDE_FIELD) self.assertRaises(IgnoreField, field.to_native) self.assertIsNone(field.to_python())
def test_validate_raises(self): field = BooleanField(required=True) self.assertRaises(SerializerFieldValueError, field.validate)
def test_set_value(self): field = BooleanField(required=True) field.set_value(False) field.validate() self.assertEqual(field.to_python(), False) self.assertEqual(field.to_native(), False)