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
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
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'
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
def test_return_failure_if_value_is_not_a_list(self): field = ListField(field=StringField(), nullable=False) result = field.validate(request=None, value='blah') assert not result.is_success