Ejemplo n.º 1
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'))
Ejemplo n.º 2
0
class FriendSchema(ApiSchema):
    name = StringField(max_length=100)
    relationship_type = StringField(max_length=10)
    resource_uri = ResourceUriField(entity_attribute='name')

    class Meta:
        schema_name = 'friends'
Ejemplo n.º 3
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
Ejemplo n.º 4
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'))
Ejemplo n.º 5
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"
Ejemplo n.º 6
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"
Ejemplo n.º 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'))
Ejemplo n.º 8
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'))
Ejemplo n.º 9
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'))
Ejemplo n.º 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'))
Ejemplo n.º 11
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
Ejemplo n.º 12
0
    class TestSchema(ApiSchema):
        name = StringField(max_length=5, required=True)
        is_active = BooleanField(required=True)
        country = StringField(required=False, max_length=5)

        class Meta:
            schema_name = 'asdf'
Ejemplo n.º 13
0
        class TestSchema(ApiSchema):
            name = StringField(max_length=5, required=True)
            is_active = BooleanField(required=True)
            country = StringField(required=False, max_length=5)
            related = SchemaField(of_type=self.RelatedSchema)

            class Meta:
                schema_name = 'asdf'
Ejemplo n.º 14
0
class CompanySchema(ApiSchema):
    name = StringField(max_length=100)
    registration_number = IntegerField()
    resource_uri = ResourceUriField(entity_attribute='name')

    class Meta:
        schema_name = 'companies'
Ejemplo n.º 15
0
    def test_return_success_if_validation_passes(self):

        field = ListField(field=StringField(), nullable=True)

        result = field.validate(request=None, value=['foo', None])

        assert result.is_success
Ejemplo n.º 16
0
        class TestSchema(ApiSchema):
            email = EmailField(max_length=50)
            char = StringField(required=True, max_length=100)
            boolean = BooleanField()

            class Meta:
                schema_name = 'asdf'
Ejemplo n.º 17
0
class PersonSchema(ApiSchema):
    name = StringField(max_length=100, required=True, nullable=False)
    email = EmailField(max_length=100, nullable=True)
    phone = StringField(max_length=10, field_type=FieldTypes.READONLY)
    address = SchemaField(of_type=AddressSchema, nullable=True)
    company = SubResourceField(resource_cls=CompanyResource,
                               entity_attribute='name',
                               related_filter='person_name',
                               show_in_list=False)
    friends = ListSubResourceField(resource_cls=FriendResource,
                                   entity_attribute='name',
                                   related_filter='friend_name',
                                   show_in_list=False)
    nick_names = ListField(field=StringField())

    class Meta:
        schema_name = 'persons'
Ejemplo n.º 18
0
    def test_return_success_if_validation_fails_on_child_field(self):

        field = ListField(field=StringField(), nullable=False)

        result = field.validate(request=None, value=['foo', None])

        assert not result.is_success
        assert isinstance(result.reason, list)
        assert len(result.reason) == 1
Ejemplo n.º 19
0
    def test_should_strip_value_for_given_characters(self):
        string_field = StringField(trim=' ')

        result = string_field.clean(request=None, value=' asd ')

        assert result == 'asd'
Ejemplo n.º 20
0
class BlankTestSchema(ApiSchema):
    name = StringField(blank=False)
Ejemplo n.º 21
0
    def test_should_not_strip_value(self):
        string_field = StringField()

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

        assert result == ' asd '
Ejemplo n.º 22
0
    def test_should_strip_value(self):
        string_field = StringField(trim=True)

        result = string_field.clean(request=None, value=' asd ')

        assert result == 'asd'
Ejemplo n.º 23
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))
Ejemplo n.º 24
0
 class NameLessSchema(ApiSchema):
     email = EmailField(max_length=50)
     char = StringField(required=True, max_length=100)
     boolean = BooleanField()
Ejemplo n.º 25
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))
Ejemplo n.º 26
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))
Ejemplo n.º 27
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))
Ejemplo n.º 28
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))
Ejemplo n.º 29
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))
Ejemplo n.º 30
0
 class RelatedSchema(ApiSchema):
     email = StringField(max_length=10)
Ejemplo n.º 31
0
        class TestSchema(ApiSchema):
            class Meta:
                schema_name = 'test_schema'

            name = StringField(max_length=10)
Ejemplo n.º 32
0
class AddressSchema(ApiSchema):
    city = StringField(max_length=20, field_type=FieldTypes.READONLY)
    country = StringField(max_length=20)

    class Meta:
        schema_name = 'Person_Address'
Ejemplo n.º 33
0
    def test_return_success_if_nullable_and_value_is_none(self):
        field = ListField(field=StringField(), nullable=True)

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

        assert result.is_success
Ejemplo n.º 34
0
        class TestSchema(ApiSchema):
            name = StringField(max_length=32)
            is_active = BooleanField()

            class Meta:
                schema_name = 'asdf'
Ejemplo n.º 35
0
        class TestSchema(ApiSchema):
            name = StringField(max_length=100)

            class Meta:
                schema_name = 'test_objs'