Пример #1
0
 def test_allow_null(self):
     field = serializers.IntegerField(allow_null=True)
     assert field.to_internal_value(None) is None
Пример #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'
Пример #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'
Пример #4
0
 def test_default(self):
     field = serializers.IntegerField(default=-1, allow_null=True)
     assert field.to_internal_value(None) == -1
Пример #5
0
 def test_required(self):
     field = serializers.IntegerField(required=False)
     assert field.to_internal_value(None) is None
Пример #6
0
 def test_integer_value(self):
     field = serializers.IntegerField()
     field.run_validation(0)
Пример #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'