diff --git a/enterprise_catalog/apps/catalog/algolia_utils.py b/enterprise_catalog/apps/catalog/algolia_utils.py index 795fd181e..fc6fa8b49 100644 --- a/enterprise_catalog/apps/catalog/algolia_utils.py +++ b/enterprise_catalog/apps/catalog/algolia_utils.py @@ -67,6 +67,7 @@ 'prices', 'course_details', 'banner_image_url', + 'visible_via_association', ] # default configuration for the index @@ -109,6 +110,7 @@ 'enterprise_customer_uuids', ], 'customRanking': [ + 'asc(visible_via_association)', 'desc(recent_enrollment_count)', ], } @@ -455,6 +457,19 @@ def get_pathway_card_image_url(pathway): return None +def get_pathway_association(pathway): + """ + Gets the pathway association + + Arguments: + pathway (dict): a dictionary representing a pathway. + + Returns: + bool: True if available via association else False + """ + return bool(pathway.get('visible_via_association', False)) + + def get_pathway_partners(pathway): """ Gets the partners for a pathway. Used for the "partners.name" facet in Algolia. @@ -1080,6 +1095,7 @@ def _algolia_object_from_product(product, algolia_fields): 'card_image_url': get_pathway_card_image_url(searchable_product), 'partners': get_pathway_partners(searchable_product), 'subjects': get_pathway_subjects(searchable_product), + 'visible_via_association': get_pathway_association(searchable_product), }) algolia_object = {} diff --git a/enterprise_catalog/apps/catalog/tests/test_algolia_utils.py b/enterprise_catalog/apps/catalog/tests/test_algolia_utils.py index 64dbf946b..d064009a1 100644 --- a/enterprise_catalog/apps/catalog/tests/test_algolia_utils.py +++ b/enterprise_catalog/apps/catalog/tests/test_algolia_utils.py @@ -21,6 +21,7 @@ get_course_skill_names, get_course_subjects, get_initialized_algolia_client, + get_pathway_association, get_pathway_availability, get_pathway_card_image_url, get_pathway_course_keys, @@ -1196,6 +1197,28 @@ def test_get_pathway_card_image(self, pathway_metadata, expected_type): image_url = get_pathway_card_image_url(pathway_metadata) self.assertEqual(expected_type, image_url) + @ddt.data( + ( + {'visible_via_association': False}, + False, + ), + ( + {'visible_via_association': True}, + True, + ), + ( + {'visible_via_association': None}, + False, + ), + ) + @ddt.unpack + def test_get_pathway_association(self, pathway_metadata, expected_value): + """ + Assert that the visible via association is properly parsed. + """ + pathway_association = get_pathway_association(pathway_metadata) + self.assertEqual(expected_value, pathway_association) + @ddt.data( ( {'steps': [