Commit 838d3330 by Renzo Lucioni Committed by GitHub

Exclude hidden runs from search results (#342)

ECOM-5689.
parent 482d0c0c
......@@ -197,6 +197,20 @@ class AggregateSearchViewSet(DefaultPartnerMixin, SerializationMixin, LoginMixin
self.assertListEqual(response_data['objects']['results'],
[self.serialize_course_run(course_run), self.serialize_program(program)])
def test_hidden_runs_excluded(self):
"""Search results should not include hidden runs."""
visible_run = CourseRunFactory(course__partner=self.partner)
hidden_run = CourseRunFactory(course__partner=self.partner, hidden=True)
self.assertEqual(CourseRun.objects.get(hidden=True), hidden_run)
response = self.get_search_response()
data = json.loads(response.content.decode('utf-8'))
self.assertEqual(
data['objects']['results'],
[self.serialize_course_run(visible_run)]
)
def test_results_filtered_by_default_partner(self):
""" Verify the search results only include items related to the default partner if no partner is
specified on the request. If a partner is included, the data should be filtered to the requested partner. """
......
......@@ -572,8 +572,8 @@ class BaseHaystackViewSet(FacetMixin, HaystackViewSet):
facet_serializer_cls = self.get_facet_serializer_class()
field_queries = getattr(facet_serializer_cls.Meta, 'field_queries', {})
# Ensure we only return published items
queryset = queryset.filter(published=True)
# Ensure we only return published, non-hidden items
queryset = queryset.filter(published=True).exclude(hidden=True)
for facet in self.request.query_params.getlist('selected_query_facets'):
query = field_queries.get(facet)
......
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