Skip to content

Commit

Permalink
fix: return empty list when no courses are found for request
Browse files Browse the repository at this point in the history
  • Loading branch information
mariajgrimaldi committed Dec 2, 2024
1 parent 139b416 commit 6b687c6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cms/djangoapps/contentstore/rest_api/v2/views/tests/test_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,25 @@ def test_api_v2_is_disabled(self, mock_modulestore, mock_course_overview):
self.assertEqual(response.status_code, status.HTTP_200_OK)
mock_modulestore().get_course_summaries.assert_called_once()
mock_course_overview.get_all_courses.assert_not_called()

@ddt.data(
("active_only", "true"),
("archived_only", "true"),
("search", "sample"),
("order", "org"),
("page", 1),
)
@ddt.unpack
def test_if_empty_list_of_courses(self, query_param, value):
"""Get list of courses when no courses are available.
Expected result:
- An empty list of courses available to the logged in user.
"""
self.active_course.delete()
self.archived_course.delete()

response = self.client.get(self.api_v2_url, {query_param: value})

self.assertEqual(len(response.data['results']['courses']), 0)
self.assertEqual(response.status_code, status.HTTP_200_OK)
3 changes: 3 additions & 0 deletions cms/djangoapps/contentstore/views/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,9 @@ def filter_ccx(course_access):
if course_keys:
courses_list = CourseOverview.get_all_courses(filter_={'id__in': course_keys})

if not courses_list:
return [], []

search_query, order, active_only, archived_only = get_query_params_if_present(request)
courses_list = get_filtered_and_ordered_courses(
courses_list,
Expand Down

0 comments on commit 6b687c6

Please sign in to comment.