Exemplo n.º 1
0
def test_error_reuse_column_filter():
    explicit_column_filter = ColumnFilter("foo", operator.eq)
    implicit_column_filter = ColumnFilter(operator.eq)

    Filtering(foo=explicit_column_filter, bar=explicit_column_filter)

    with pytest.raises(TypeError, match="without explicit column name"):
        Filtering(foo=implicit_column_filter, bar=implicit_column_filter)
Exemplo n.º 2
0
    class WidgetColorCustomListView(WidgetViewBase):
        filtering = Filtering(
            color=filter_fields['color_custom'],
        )

        def get(self):
            return self.list()
Exemplo n.º 3
0
    class WidgetListView(WidgetViewBase):
        filtering = Filtering(
            color=operator.eq,
            color_allow_empty=ColumnFilter(
                "color", operator.eq, allow_empty=True
            ),
            size=ColumnFilter(operator.eq, separator="|"),
            size_min=ColumnFilter("size", operator.ge),
            size_divides=ColumnFilter(
                "size", lambda size, value: size % value == 0
            ),
            size_is_odd=ModelFilter(
                fields.Boolean(),
                lambda model, value: model.size % 2 == int(value),
            ),
            size_min_unvalidated=ColumnFilter(
                "size", operator.ge, validate=False
            ),
            size_skip_invalid=ColumnFilter(
                "size", operator.eq, skip_invalid=True
            ),
        )

        def get(self):
            return self.list()
Exemplo n.º 4
0
    class WidgetViewBase(GenericModelView):
        model = models["widget"]
        schema = schemas["widget"]

        filtering = Filtering(
            color=operator.eq,
            color_allow_empty=ColumnFilter(
                "color", operator.eq, allow_empty=True
            ),
            size=ColumnFilter(operator.eq, separator="|"),
            size_min=ColumnFilter("size", operator.ge),
            size_divides=ColumnFilter(
                "size", lambda size, value: size % value == 0
            ),
            size_is_odd=ModelFilter(
                fields.Boolean(),
                lambda model, value: model.size % 2 == int(value),
            ),
            size_min_unvalidated=ColumnFilter(
                "size", operator.ge, validate=False
            ),
            size_skip_invalid=ColumnFilter(
                "size", operator.eq, skip_invalid=True
            ),
        )
Exemplo n.º 5
0
    class WidgetSizeRequiredListView(WidgetViewBase):
        filtering = Filtering(
            size=ColumnFilter(operator.eq, required=True),
        )

        def get(self):
            return self.list()
Exemplo n.º 6
0
    class LimitOffsetWidgetListView(WidgetViewBase):
        filtering = Filtering(size=operator.eq, )
        pagination = LimitOffsetPagination(2, 4)

        def get(self):
            return self.list()

        def post(self):
            return self.create()
Exemplo n.º 7
0
    class OptionalLimitWidgetListView(WidgetViewBase):
        filtering = Filtering(size=operator.eq)
        pagination = LimitPagination()

        def get(self):
            return self.list()

        def post(self):
            return self.create()
Exemplo n.º 8
0
class PeerListView(PeerViewBase):
    filtering = Filtering(name=ColumnFilter(operator.eq, required=True))
    sorting = Sorting("id", default="-id")

    def get(self):
        return self.list()

    def post(self):
        return self.create()
Exemplo n.º 9
0
class BookViewBase(GenericModelView):
    model = models.Book
    schema = schemas.BookSchema()

    authentication = NoOpAuthentication()
    authorization = NoOpAuthorization()

    pagination = PagePagination(page_size=10)
    sorting = Sorting("published_at", default="-published_at")
    filtering = Filtering(author_id=ColumnFilter(operator.eq, required=True))
Exemplo n.º 10
0
    class WidgetDefaultFiltersView(WidgetViewBase):
        filtering = Filtering(
            color=ModelFilter(
                fields.String(missing="red"),
                lambda model, value: model.color == value,
            ),
            size=ColumnFilter(operator.eq, missing=1),
        )

        def get(self):
            return self.list()
Exemplo n.º 11
0
    class FooListView(FooViewBase):
        spec_declaration = ModelViewDeclaration(many=True)

        filtering = Filtering(color=operator.eq, )
        sorting = Sorting('name', 'color')
        pagination = PagePagination(2)

        def get(self):
            pass

        def post(self):
            """test the docstring"""
            pass
Exemplo n.º 12
0
    class FooListView(GenericModelView):
        schema = schemas['foo']()

        spec_declaration = ModelViewDeclaration(many=True)

        filtering = Filtering(color=operator.eq, )
        sorting = Sorting('name', 'color')
        pagination = PagePagination(2)

        def get(self):
            pass

        def post(self):
            """test the docstring"""
            pass
Exemplo n.º 13
0
    class WidgetListView(GenericModelView):
        model = models['widget']
        schema = schemas['widget']

        filtering = Filtering(
            color=operator.eq,
            size=(operator.eq, {
                'separator': '|',
                'empty': sql.false(),
            }),
            size_alt=(operator.eq, {
                'empty': lambda view: view.model.size == 1,
            }),
            size_min=('size', operator.ge),
            size_divides=('size', lambda size, value: size % value == 0),
            size_is_odd=filter_fields['size_is_odd'],
            color_no_separator=filter_fields['color_no_separator'],
        )

        def get(self):
            return self.list()
Exemplo n.º 14
0
    class WidgetListView(WidgetViewBase):
        filtering = Filtering(
            color=operator.eq,
            color_allow_empty=ColumnFilter(
                'color',
                operator.eq,
                allow_empty=True,
            ),
            size=ColumnFilter(operator.eq, separator='|'),
            size_min=ColumnFilter('size', operator.ge),
            size_divides=ColumnFilter(
                'size',
                lambda size, value: size % value == 0,
            ),
            size_is_odd=filter_fields['size_is_odd'],
            size_min_unvalidated=ColumnFilter(
                'size',
                operator.ge,
                validate=False,
            ),
        )

        def get(self):
            return self.list()
Exemplo n.º 15
0
 class LimitOffsetWidgetListView(WidgetListViewBase):
     filtering = Filtering(size=operator.eq)
     pagination = LimitOffsetPagination(2, 4)
Exemplo n.º 16
0
 class OptionalLimitWidgetListView(WidgetListViewBase):
     filtering = Filtering(size=operator.eq)
     pagination = LimitPagination()
Exemplo n.º 17
0
def test_error_combine_filtering_type_error():
    with pytest.raises(TypeError):
        Filtering() | {}