Commit 80246abd by Ahsan Ulhaq Committed by GitHub

Merge pull request #496 from edx/ahsan/Add-searchable-courserun-filter

Added searchable courseruns filter
parents f8189381 5a2a9322
......@@ -150,7 +150,7 @@ class CourseRunFilter(FilterSetMixin, django_filters.FilterSet):
class Meta:
model = CourseRun
fields = ['keys']
fields = ['keys', 'hidden']
class ProgramFilter(FilterSetMixin, django_filters.FilterSet):
......
......@@ -173,6 +173,16 @@ class CourseRunViewSetTests(SerializationMixin, ElasticsearchTestMixin, APITestC
url = reverse('api:v1:course_run-list') + '?marketable=1'
self.assert_list_results(url, expected)
def test_filter_by_hidden(self):
""" Verify the endpoint filters course runs that are hidden. """
CourseRun.objects.all().delete()
course_runs = CourseRunFactory.create_batch(3, course__partner=self.partner)
hidden_course_runs = CourseRunFactory.create_batch(3, hidden=True, course__partner=self.partner)
url = reverse('api:v1:course_run-list')
self.assert_list_results(url, course_runs + hidden_course_runs)
url = reverse('api:v1:course_run-list') + '?hidden=False'
self.assert_list_results(url, course_runs)
def test_filter_by_active(self):
""" Verify the endpoint filters course runs to those that are active. """
CourseRun.objects.all().delete()
......
......@@ -81,6 +81,12 @@ class CourseRunViewSet(PartnerMixin, viewsets.ReadOnlyModelViewSet):
type: string
paramType: query
multiple: false
- name: hidden
description: Filter based on wether the course run is hidden from search.
required: false
type: Boolean
paramType: query
multiple: false
- name: active
description: Retrieve active course runs. A course is considered active if its end date has not passed,
and it is open for enrollment.
......
......@@ -127,6 +127,7 @@ class CourseRunFactory(factory.DjangoModelFactory):
max_effort = FuzzyInteger(10, 20)
pacing_type = FuzzyChoice([name for name, __ in CourseRunPacing.choices])
slug = FuzzyText()
hidden = False
weeks_to_complete = FuzzyInteger(1)
@factory.post_generation
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment