Example #1
0
    def test_get_raise_exception(self):
        view = ViewClass()
        view.raise_filter_exception = True

        self.assertTrue(FilterMapBackend().get_raise_exception(view))

        view.raise_filter_exception = False
        self.assertFalse(FilterMapBackend().get_raise_exception(view))

        view.get_raise_filter_exception = lambda *a: True
        self.assertTrue(FilterMapBackend().get_raise_exception(view))

        view.get_raise_filter_exception = lambda *a: False
        self.assertFalse(FilterMapBackend().get_raise_exception(view))
Example #2
0
    def test_get_filterset(self):
        fil_map = {'foo': 'bar'}
        request = Request(HttpRequest())
        queryset = ProfileQuerySet()
        view = ViewClass()
        filterset_kwargs = {
            'data': {},
            'queryset': queryset,
            'request': request
        }

        with patch(
                'filter_map.backends.FilterMapBackend.get_filterset_class',
                return_value=FilterMapFilterSet
        ) as get_filterset_class, patch(
                'filter_map.backends.FilterMapBackend.get_filter_map',
                return_value=fil_map
        ) as get_filter_map, patch(
                'filter_map.backends.FilterMapBackend.get_filterset_kwargs',
                return_value=filterset_kwargs) as get_filterset_kwargs:
            filterset = FilterMapBackend().get_filterset(
                request, queryset, view)
            self.assertTrue(isinstance(filterset, FilterMapFilterSet))

            self.assertEqual(get_filter_map.call_count, 1)
            self.assertEqual(get_filter_map.call_args.args, (view, ))

            self.assertEqual(get_filterset_class.call_count, 1)
            self.assertEqual(get_filterset_class.call_args.args,
                             (view, fil_map))

            self.assertEqual(get_filterset_kwargs.call_count, 1)
            self.assertEqual(get_filterset_kwargs.call_args.args,
                             (request, queryset))
Example #3
0
    def test_filter_queryset(self):
        request = Request(HttpRequest())
        queryset = ProfileQuerySet([1, 2, 3])
        new_queryset = ProfileQuerySet([1, 2])

        view = ViewClass()

        with patch('filter_map.backends.FilterMapFilterSet.filter_queryset',
                   return_value=new_queryset) as filter_queryset:
            qs = FilterMapBackend().filter_queryset(request, queryset, view)
            self.assertEqual(qs, new_queryset)

            self.assertEqual(filter_queryset.call_count, 1)
            self.assertEqual(filter_queryset.call_args.args, (queryset, ))