From 454cb990d7262e3153e2c07c70335b2024e00b91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jochen=20Wersd=C3=B6rfer?= Date: Tue, 22 Aug 2023 08:37:40 +0200 Subject: [PATCH] #100 bring coverage back to 100% --- cast/filters.py | 6 ++++-- tests/filter_test.py | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cast/filters.py b/cast/filters.py index ddcfce95..132082dd 100644 --- a/cast/filters.py +++ b/cast/filters.py @@ -19,7 +19,7 @@ from django.utils.safestring import SafeText, mark_safe from django.utils.translation import gettext as _ from django_filters.fields import ChoiceField as FilterChoiceField -from wagtail.models import PageQuerySet +from wagtail.models import Page, PageQuerySet from cast import appsettings from cast.models.pages import PostTag @@ -328,9 +328,11 @@ def __init__( *, fetch_facet_counts: bool = False, ): - super().__init__(data=data, queryset=queryset) if data is None: data = QueryDict("") + if queryset is None: + queryset = Page.objects.none() + super().__init__(data=data, queryset=queryset) # Remove filters which are not configured in the settings configured_filters = set(appsettings.CAST_FILTERSET_FACETS) for filter_name in self.filters.copy().keys(): diff --git a/tests/filter_test.py b/tests/filter_test.py index ed638bc2..31c4fcec 100644 --- a/tests/filter_test.py +++ b/tests/filter_test.py @@ -98,6 +98,14 @@ def test_only_filter_specified_fields(field_name, facet_count_key): @pytest.mark.django_db class TestPostFilterset: + def test_data_is_none(self): + filterset = PostFilterset(None) + assert filterset.data == QueryDict("") + + def test_queryset_is_none(self): + filterset = PostFilterset(None, queryset=None) + assert filterset.qs.count() == 0 + def test_no_posts_no_date_facets(self): # given a filterset with no posts queryset = Post.objects.none()