def test_allow_null(self): field = serializers.IntegerField(allow_null=True) assert field.to_internal_value(None) is None
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'
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'
def test_default(self): field = serializers.IntegerField(default=-1, allow_null=True) assert field.to_internal_value(None) == -1
def test_required(self): field = serializers.IntegerField(required=False) assert field.to_internal_value(None) is None
def test_integer_value(self): field = serializers.IntegerField() field.run_validation(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'