Skip to content

Commit

Permalink
Test (and fix) raising error on Django 4.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
carltongibson committed Aug 2, 2024
1 parent af84991 commit ba88cb0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion django_filters/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ def __init__(self, choices=None, filters=None, *args, **kwargs):
if DJANGO_50:
self.choices = normalize_choices(self.choices)
else:
assert not DJANGO_50, "Django 5.0 or later is required for dict choices"
raise ValueError("Django 5.0 or later is required for dict choices")

all_choices = list(
chain.from_iterable(
Expand Down
10 changes: 10 additions & 0 deletions tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,16 @@ def test_grouped_choices_as_dictionary(self):
choices={"group": {"a": "a", "b": "b"}}, filters={"a": None, "b": None}
)

@unittest.skipUnless(django.VERSION <= (4, 2), "Django 5.0 introduced new dictionary choices option")
def test_grouped_choices_error(self):
with self.assertRaisesMessage(
ValueError,
"Django 5.0 or later is required for dict choices"
):
DateRangeFilter(
choices={"group": {"a": "a", "b": "b"}}, filters={"a": None, "b": None}
)

def test_filtering_for_this_year(self):
qs = mock.Mock(spec=["filter"])
with mock.patch("django_filters.filters.now") as mock_now:
Expand Down

0 comments on commit ba88cb0

Please sign in to comment.