Skip to content

Commit

Permalink
fix: [WS-4468] update learning type experiment filter
Browse files Browse the repository at this point in the history
  • Loading branch information
bseverino committed Apr 26, 2024
1 parent 6e7dcef commit f117a6f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 42 deletions.
60 changes: 26 additions & 34 deletions course_discovery/apps/course_metadata/algolia_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
'''
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit f117a6f

Please sign in to comment.