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_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)
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)
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')
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')
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")
def test_bind(self): backend = DjangoFilterBackend(Place.objects.all()) assert backend.specs == [] backend.bind([1, 2]) assert backend.specs == [1, 2]