示例#1
0
 def test_max_length(self):
     field = serializers.StringField(max_length=3)
     with pytest.raises(serializers.ValidationError) as excinfo:
         field.run_validation('abcd')
     assert isinstance(excinfo.value.message, list)
     e1 = excinfo.value.message[0]
     assert e1.message == 'Ensure this field has maximum 3 characters'
示例#2
0
 def test_allow_null(self):
     field = serializers.StringField(allow_null=True, trim_whitespace=True)
     value = field.run_validation(None)
     assert value is None
示例#3
0
 def test_not_allow_null(self):
     field = serializers.StringField(allow_null=False, trim_whitespace=True)
     with pytest.raises(serializers.ValidationError) as excinfo:
         field.run_validation(None)
     assert excinfo.value.message == 'null is not allowed'
示例#4
0
 def test_allow_blank(self):
     field = serializers.StringField(allow_blank=True, trim_whitespace=True)
     assert field.run_validation(' ') == ''
示例#5
0
 def test_not_allow_blank(self):
     field = serializers.StringField()
     with pytest.raises(serializers.ValidationError) as excinfo:
         field.run_validation('')
     assert excinfo.value.message == 'blank is not allowed'
示例#6
0
 def test_if_trim_whitespace_false(self):
     field = serializers.StringField(trim_whitespace=False)
     assert field.to_internal_value(' abc ') == ' abc '
示例#7
0
 def test_if_stripped_by_default(self):
     field = serializers.StringField()
     assert field.to_internal_value(' abc ') == 'abc'