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_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_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')