Esempio n. 1
0
    def test_max_min(self):
        int_field = PositiveIntegerField(required=True, max_value=24)
        int_field.set_value(23)
        int_field.validate()
        self.assertEqual(int_field.to_python(), 23)
        self.assertEqual(int_field.to_native(), 23)

        int_field = PositiveIntegerField(required=True, max_value=24)
        int_field.set_value(100)
        self.assertRaises(SerializerFieldValueError, int_field.validate)

        int_field = PositiveIntegerField(required=True, max_value=24)
        int_field.set_value('101')
        self.assertRaises(SerializerFieldValueError, int_field.validate)

        int_field = PositiveIntegerField(required=True, max_value=24)
        int_field.set_value('-101')
        self.assertRaises(SerializerFieldValueError, int_field.validate)
Esempio n. 2
0
 def test_set_value_string(self):
     int_field = PositiveIntegerField(required=True)
     int_field.set_value('24')
     int_field.validate()
     self.assertEqual(int_field.to_python(), 24)
     self.assertEqual(int_field.to_native(), 24)