From f117a6fe91fa3c20f8c7f7922ad5e50aa6f28dc9 Mon Sep 17 00:00:00 2001 From: Bianca Severino Date: Fri, 26 Apr 2024 10:59:40 -0400 Subject: [PATCH] fix: [WS-4468] update learning type experiment filter --- .../apps/course_metadata/algolia_models.py | 60 ++++++++----------- .../tests/test_algolia_models.py | 16 ++--- 2 files changed, 34 insertions(+), 42 deletions(-) diff --git a/course_discovery/apps/course_metadata/algolia_models.py b/course_discovery/apps/course_metadata/algolia_models.py index 51bb48ad8b5..43fbcc142b0 100644 --- a/course_discovery/apps/course_metadata/algolia_models.py +++ b/course_discovery/apps/course_metadata/algolia_models.py @@ -49,6 +49,27 @@ def get_owners(entry): for o in entry.authoring_organizations.all()] return list(filter(lambda owner: owner['logoImageUrl'] is not None, all_owners)) +def process_learning_type(product_type): + CERTIFICATES = _('Certificates') + PATHWAYS_TO_DEGREES = _('Pathways to Degrees') + + product_map = { + 'Boot Camp': _('Boot Camps'), + 'Executive Education': _('Exec Ed'), + 'Certificate': CERTIFICATES, + 'License': CERTIFICATES, + 'Professional Certificate': CERTIFICATES, + 'XSeries': CERTIFICATES, + 'MicroBachelors': PATHWAYS_TO_DEGREES, + 'MicroMasters': PATHWAYS_TO_DEGREES, + 'Bachelors': _('Bachelor’s'), + 'Masters': _('Master’s') + } + + try: + return product_map[product_type] + except KeyError: + return product_type def delegate_attributes(cls): ''' @@ -300,26 +321,12 @@ def learning_type_exp(self): Temporary field used as a variant of `learning_type` for an experiment. If the experiment is successful, this will replace `learning_type`. """ - if self.type.slug == CourseType.EXECUTIVE_EDUCATION_2U: - return [_('Certificate courses')] - + course_type = process_learning_type(self.product_type) processed_program_types = [] for program_type in self.program_types: - if program_type in [ - 'Certificate', - 'License', - 'Professional Certificate', - 'XSeries' - ]: - processed_program_types.append(_('Certificate courses')) - elif program_type in ['Bachelors', 'Doctorate', 'Masters']: - processed_program_types.append(_('Degrees')) - elif program_type in ['MicroBachelors', 'MicroMasters']: - processed_program_types.append(_('Paths to degrees')) - else: - processed_program_types.append(program_type) - - return [self.product_type, *processed_program_types] + processed_program_types.append(process_learning_type(program_type)) + + return [course_type, *processed_program_types] @property def product_card_image_url(self): @@ -572,22 +579,7 @@ def learning_type_exp(self): this will replace `learning_type`. """ if self.type: - if self.type.slug in [ - ProgramType.CERTIFICATE, - ProgramType.LICENSE, - ProgramType.PROFESSIONAL_CERTIFICATE, - ProgramType.XSERIES - ]: - return [_('Certificate courses')] - if self.type.slug in [ - ProgramType.BACHELORS, - ProgramType.DOCTORATE, - ProgramType.MASTERS - ]: - return [_('Degrees')] - if self.type.slug in [ProgramType.MICROBACHELORS, ProgramType.MICROMASTERS]: - return [_('Paths to degrees')] - return [self.type.name_t] + return [process_learning_type(self.type.name_t)] return [] @property diff --git a/course_discovery/apps/course_metadata/tests/test_algolia_models.py b/course_discovery/apps/course_metadata/tests/test_algolia_models.py index 5658fe43891..501e88ffc82 100644 --- a/course_discovery/apps/course_metadata/tests/test_algolia_models.py +++ b/course_discovery/apps/course_metadata/tests/test_algolia_models.py @@ -524,9 +524,9 @@ def test_learning_type_open_course(self, has_program): assert course.learning_type == ['Course'] @ddt.data( - (ProgramType.PROFESSIONAL_CERTIFICATE, 'Certificate courses'), - (ProgramType.MASTERS, 'Degrees'), - (ProgramType.MICROBACHELORS, 'Paths to degrees'), + (ProgramType.XSERIES, 'Certificates'), + (ProgramType.MASTERS, 'Master’s'), + (ProgramType.MICROMASTERS, 'Pathways to Degrees'), ) @ddt.unpack def test_learning_type_exp_open_course(self, program_type_slug, learning_type): @@ -548,8 +548,8 @@ def test_learning_type_non_open_course(self, course_type_slug, expected_result): assert course.learning_type == [expected_result] @ddt.data( - (CourseType.EXECUTIVE_EDUCATION_2U, 'Certificate courses'), - (CourseType.BOOTCAMP_2U, 'Boot Camp'), + (CourseType.EXECUTIVE_EDUCATION_2U, 'Exec Ed'), + (CourseType.BOOTCAMP_2U, 'Boot Camps'), ) @ddt.unpack def test_learning_type_exp_non_open_course(self, course_type_slug, expected_result): @@ -875,9 +875,9 @@ def test_learning_type(self): assert program.learning_type == [program_type.name_t] @ddt.data( - (ProgramType.PROFESSIONAL_CERTIFICATE, 'Certificate courses'), - (ProgramType.MASTERS, 'Degrees'), - (ProgramType.MICROBACHELORS, 'Paths to degrees'), + (ProgramType.PROFESSIONAL_CERTIFICATE, 'Certificates'), + (ProgramType.MASTERS, 'Master’s'), + (ProgramType.MICROBACHELORS, 'Pathways to Degrees'), ) @ddt.unpack def test_learning_type_exp(self, program_type_slug, learning_type):