def test_excludes(self):
        backend = DjangoFilterBackend(Place.objects.all())
        backend.bind([
            FilterSpec(['name'], 'exact', 'value', False),
            FilterSpec(['address'], 'contains', 'value', True),
        ])

        assert list(backend.excludes) == [
            FilterSpec(['address'], 'contains', 'value', True),
        ]
示例#2
0
    def test_excludes(self):
        backend = DjangoFilterBackend(Place.objects.all())
        backend.bind([
            FilterSpec(["name"], "exact", "value", False),
            FilterSpec(["address"], "contains", "value", True),
        ])

        assert list(backend.excludes) == [
            FilterSpec(["address"], "contains", "value", True)
        ]
示例#3
0
    def test_excludes(self):
        backend = DjangoFilterBackend(Place.objects.all())
        backend.bind([
            FilterSpec(['name'], 'exact', 'value', False),
            FilterSpec(['address'], 'contains', 'value', True),
        ])

        assert list(backend.excludes) == [
            FilterSpec(['address'], 'contains', 'value', True),
        ]
    def test_filter_to_many(self):
        qs = mock.Mock()

        backend = DjangoFilterBackend(qs)
        backend.model = Place
        backend.bind([
            FilterSpec(['restaurant', 'waiter', 'name'], 'exact', 'value', False),
        ])

        result = backend.filter()

        assert result == qs.filter.return_value.distinct.return_value
        qs.filter.assert_called_once_with(restaurant__waiter__name__exact='value')
    def test_filter_callable_specs(self):
        qs = mock.Mock()

        def foo(queryset, spec):
            return queryset.filter(spec)

        spec = FilterSpec(['name'], 'exact', 'value', False, foo)
        backend = DjangoFilterBackend(qs)
        backend.bind([spec])

        result = backend.filter()

        assert result == qs.filter.return_value
        qs.filter.assert_called_once_with(spec)
示例#6
0
    def test_filter_callable_specs(self):
        qs = mock.Mock()

        def foo(queryset, spec):
            return queryset.filter(spec)

        spec = FilterSpec(["name"], "exact", "value", False, foo)
        backend = DjangoFilterBackend(qs)
        backend.bind([spec])

        result = backend.filter()

        assert result == qs.filter.return_value
        qs.filter.assert_called_once_with(spec)
示例#7
0
    def test_filter(self):
        qs = mock.Mock()

        backend = DjangoFilterBackend(qs)
        backend.bind([
            FilterSpec(['name'], 'exact', 'value', False),
            FilterSpec(['address'], 'contains', 'value', True),
        ])

        result = backend.filter()

        assert result == qs.filter.return_value.exclude.return_value
        qs.filter.assert_called_once_with(name__exact='value')
        qs.filter.return_value.exclude.assert_called_once_with(address__contains='value')
示例#8
0
    def test_filter_to_many(self):
        qs = mock.Mock()

        backend = DjangoFilterBackend(qs)
        backend.model = Place
        backend.bind([
            FilterSpec(["restaurant", "waiter", "name"], "exact", "value",
                       False)
        ])

        result = backend.filter()

        assert result == qs.filter.return_value.distinct.return_value
        qs.filter.assert_called_once_with(
            restaurant__waiter__name__exact="value")
    def test_filter_to_many(self):
        qs = mock.Mock()

        backend = DjangoFilterBackend(qs)
        backend.model = Place
        backend.bind([
            FilterSpec(['restaurant', 'waiter', 'name'], 'exact', 'value',
                       False),
        ])

        result = backend.filter()

        assert result == qs.filter.return_value.distinct.return_value
        qs.filter.assert_called_once_with(
            restaurant__waiter__name__exact='value')
示例#10
0
    def test_filter(self):
        qs = mock.Mock()

        backend = DjangoFilterBackend(qs)
        backend.model = Place
        backend.bind([
            FilterSpec(["name"], "exact", "value", False),
            FilterSpec(["address"], "contains", "value", True),
        ])

        result = backend.filter()

        assert result == qs.filter.return_value.exclude.return_value
        qs.filter.assert_called_once_with(name__exact="value")
        qs.filter.return_value.exclude.assert_called_once_with(
            address__contains="value")
示例#11
0
    def test_bind(self):
        backend = DjangoFilterBackend(Place.objects.all())

        assert backend.specs == []
        backend.bind([1, 2])
        assert backend.specs == [1, 2]
示例#12
0
    def test_bind(self):
        backend = DjangoFilterBackend(Place.objects.all())

        assert backend.specs == []
        backend.bind([1, 2])
        assert backend.specs == [1, 2]