示例#1
0
 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.')
示例#2
0
 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.')
示例#3
0
    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)
示例#4
0
    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)
示例#5
0
 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)
示例#6
0
 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)