Ejemplo n.º 1
0
 def test_allow_null(self):
     field = serializers.IntegerField(allow_null=True)
     assert field.to_internal_value(None) is None
Ejemplo n.º 2
0
 def test_max_value(self):
     field = serializers.IntegerField(max_value=10)
     with pytest.raises(serializers.ValidationError) as excinfo:
         field.run_validation(11)
     obj = excinfo.value.message[0]
     assert obj.message == 'Ensure maximum value is 10'
Ejemplo n.º 3
0
 def test_if_not_allow_null(self):
     field = serializers.IntegerField()
     with pytest.raises(serializers.ValidationError) as excinfo:
         field.run_validation(None)
     assert excinfo.value.message == 'null is not allowed'
Ejemplo n.º 4
0
 def test_default(self):
     field = serializers.IntegerField(default=-1, allow_null=True)
     assert field.to_internal_value(None) == -1
Ejemplo n.º 5
0
 def test_required(self):
     field = serializers.IntegerField(required=False)
     assert field.to_internal_value(None) is None
Ejemplo n.º 6
0
 def test_integer_value(self):
     field = serializers.IntegerField()
     field.run_validation(0)
Ejemplo n.º 7
0
 def test_non_integer(self):
     field = serializers.IntegerField()
     with pytest.raises(serializers.ValidationError) as excinfo:
         field.run_validation(0.1)
     assert excinfo.value.message == 'Must be an integer value'