Skip to content

Commit

Permalink
🐛(api/client) fix has_listed_course_runs course filter
Browse files Browse the repository at this point in the history
The filter `has_listed_course_runs` return non distinct course. So when
filtering course whose have listed course runs it returns the resource as many
as it has listed course runs.
  • Loading branch information
jbpenrath committed Jul 20, 2023
1 parent 16a9fa3 commit 1664c62
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/backend/joanie/core/filters/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def filter_has_listed_course_runs(self, queryset, _name, value):
Filter resource by looking for course runs which are listed.
"""
if value is True:
return queryset.filter(course_runs__is_listed=True)
filtered_queryset = queryset.filter(course_runs__is_listed=True)
else:
filtered_queryset = queryset.exclude(course_runs__is_listed=True)

return queryset.exclude(course_runs__is_listed=True)
return filtered_queryset.distinct()
2 changes: 2 additions & 0 deletions src/backend/joanie/tests/core/test_api_course.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ def test_api_course_list_filter_has_listed_course_runs(self):
courses = factories.CourseFactory.create_batch(3)
factories.CourseRunFactory(course=courses[0], is_listed=False)
factories.CourseRunFactory(course=courses[0], is_listed=True)
factories.CourseRunFactory(course=courses[0], is_listed=True)
factories.CourseRunFactory(course=courses[1], is_listed=False)
factories.CourseRunFactory(course=courses[1], is_listed=False)

# Give user access to all courses
Expand Down

0 comments on commit 1664c62

Please sign in to comment.