def test_required(self): field = IntegerField(required=True) try: field.validate() except SerializerFieldValueError as e: self.assertEqual(repr(e), 'This field is required.') self.assertEqual(str(e), '[field]: This field is required.') else: self.fail('SerializerFieldValueError not raised.')
def test_max_min(self): int_field = IntegerField(required=True, max_value=24, min_value=22) int_field.set_value(23) int_field.validate() self.assertEqual(int_field.to_python(), 23) self.assertEqual(int_field.to_native(), 23) int_field = IntegerField(required=True, max_value=24, min_value=22) int_field.set_value(100) self.assertRaises(SerializerFieldValueError, int_field.validate)
def test_set_value_string(self): int_field = IntegerField(required=True) int_field.set_value('24') int_field.validate() self.assertEqual(int_field.to_python(), 24) self.assertEqual(int_field.to_native(), 24)