示例#1
0
    def test_should_return_true_when_blank_is_false_and_value_is_not_blank(
            self):
        string_field = StringField(blank=False)

        result = string_field.validate(request=None, value="asd")

        assert result.is_success is True
示例#2
0
    def test_validate_returns_error_for_invalid_type(self):
        string_field = StringField(10, required=True)

        result = string_field.validate(None, 1212)

        assert_that(result.is_success, equal_to(False))
        assert_that(result.reason, equal_to('Expected type string'))
示例#3
0
    def test_should_return_false_when_blank_is_false_and_value_is_blank(self):
        string_field = StringField(blank=False)

        result = string_field.validate(request=None, value="")

        assert result.is_success is False
        assert result.reason == "This field is required"
示例#4
0
    def test_validate_returns_error_if_max_length_exceeds(self):
        string_field = StringField(max_length=1, required=True)

        result = string_field.validate(None, '1212')

        assert_that(result.is_success, equal_to(False))
        assert_that(result.reason, equal_to('Maxlength of 1 exceeded'))
示例#5
0
    def test_should_return_true_when_blank_is_false_and_value_is_not_blank(
            self):
        string_field = StringField(blank=False)

        result = string_field.validate(request=None, value="asd")

        assert result.is_success is True
示例#6
0
    def test_validate_returns_error_if_required_and_value_is_default(self):
        string_field = StringField(10, required=True)

        result = string_field.validate(None, DEFAULT_FIELD_VALUE)

        assert_that(result.is_success, equal_to(False))
        assert_that(result.reason, equal_to('This field is required'))
示例#7
0
    def test_validate_returns_error_if_max_length_exceeds(self):
        string_field = StringField(max_length=1, required=True)

        result = string_field.validate(None, '1212')

        assert_that(result.is_success, equal_to(False))
        assert_that(result.reason, equal_to('Maxlength of 1 exceeded'))
示例#8
0
    def test_should_return_false_when_blank_is_false_and_value_is_blank(self):
        string_field = StringField(blank=False)

        result = string_field.validate(request=None, value="")

        assert result.is_success is False
        assert result.reason == "This field is required"
示例#9
0
    def test_validate_returns_error_for_invalid_type(self):
        string_field = StringField(10, required=True)

        result = string_field.validate(None, 1212)

        assert_that(result.is_success, equal_to(False))
        assert_that(result.reason, equal_to('Expected type string'))
示例#10
0
    def test_validate_returns_error_if_required_and_value_is_default(self):
        string_field = StringField(10, required=True)

        result = string_field.validate(None, DEFAULT_FIELD_VALUE)

        assert_that(result.is_success, equal_to(False))
        assert_that(result.reason, equal_to('This field is required'))
示例#11
0
    def test_should_return_true_when_nullable_and_value_is_none(self):
        string_field = StringField(max_length=100, nullable=True)

        result = string_field.validate(request=None, value=None)

        assert_that(result.is_success, equal_to(True))
示例#12
0
    def test_should_not_raise_if_not_a_required_field(self):
        string_field = StringField(max_length=100, required=False)

        result = string_field.validate(request=None, value=DEFAULT_FIELD_VALUE)

        assert_that(result.is_success, equal_to(True))
示例#13
0
    def test_validate_returns_no_error_when_max_length_is_none(self):
        string_field = StringField(max_length=None, required=True)

        result = string_field.validate(None, '1212'* 1000)

        assert_that(result.is_success, equal_to(True))
示例#14
0
    def test_should_return_true_when_nullable_and_value_is_none(self):
        string_field = StringField(max_length=100, nullable=True)

        result = string_field.validate(request=None, value=None)

        assert_that(result.is_success, equal_to(True))
示例#15
0
    def test_should_not_raise_if_not_a_required_field(self):
        string_field = StringField(max_length=100, required=False)

        result = string_field.validate(request=None, value=DEFAULT_FIELD_VALUE)

        assert_that(result.is_success, equal_to(True))
示例#16
0
    def test_validate_returns_no_error_when_max_length_is_none(self):
        string_field = StringField(max_length=None, required=True)

        result = string_field.validate(None, '1212' * 1000)

        assert_that(result.is_success, equal_to(True))