Skip to content

Commit

Permalink
#100 bring coverage back to 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
ephes committed Aug 22, 2023
1 parent 8849aa1 commit 454cb99
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cast/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down
8 changes: 8 additions & 0 deletions tests/filter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 454cb99

Please sign in to comment.