Skip to content

Commit

Permalink
feat: marke course as active is is_marketable_external
Browse files Browse the repository at this point in the history
  • Loading branch information
hamzawaleed01 committed Jan 27, 2025
1 parent 6983739 commit fe08f97
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 2 deletions.
50 changes: 50 additions & 0 deletions enterprise_catalog/apps/api/v1/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from enterprise_catalog.apps.curation.tests.factories import (
HighlightedContentFactory,
)
from enterprise_catalog.apps.api.v1.utils import is_course_run_active


class ApiUtilsTests(TestCase):
Expand Down Expand Up @@ -82,3 +83,52 @@ def test_get_archived_content_count(self):
[highlighted_content_1, highlighted_content_2, highlighted_content_3]
)
assert archived_content_count == 2

def test_is_course_run_active(self):
"""
Test that the is_course_run_active function correctly identifies active course runs.
"""
# Test case where course run is active
active_course_run = {
'is_enrollable': True,
'is_marketable_external': True,
'status': 'published',
'is_marketable': True
}
assert is_course_run_active(active_course_run) is True

# Test case where course run is not active due to not being enrollable
not_enrollable_course_run = {
'is_enrollable': False,
'is_marketable_external': True,
'status': 'published',
'is_marketable': True
}
assert is_course_run_active(not_enrollable_course_run) is False

# Test case where course is not is_marketable but is_marketable_external
not_marketable_course_run = {
'is_enrollable': True,
'is_marketable_external': True,
'status': 'published',
'is_marketable': False
}
assert is_course_run_active(not_marketable_course_run) is True

# Test case where course run is not active due to not being published
not_published_course_run = {
'is_enrollable': False,
'is_marketable_external': False,
'status': 'archived',
'is_marketable': True
}
assert is_course_run_active(not_published_course_run) is False

# Test case where course run is active due to being marketable externally
marketable_external_course_run = {
'is_enrollable': True,
'is_marketable_external': True,
'status': 'reviewed',
'is_marketable': False
}
assert is_course_run_active(marketable_external_course_run) is True
4 changes: 3 additions & 1 deletion enterprise_catalog/apps/api/v1/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ def is_course_run_active(course_run):
Returns:
bool: True if course run is "active"
"""
is_enrollable = course_run.get('is_enrollable', False)
if course_run.get("is_marketable_external") and is_enrollable:
return True
course_run_status = course_run.get('status') or ''
is_published = course_run_status.lower() == 'published'
is_enrollable = course_run.get('is_enrollable', False)
is_marketable = course_run.get('is_marketable', False)

return is_published and is_enrollable and is_marketable
Expand Down
4 changes: 3 additions & 1 deletion enterprise_catalog/apps/catalog/content_metadata_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ def is_course_run_active(course_run):
Returns:
bool: True if course run is "active"
"""
is_enrollable = course_run.get('is_enrollable', False)
if course_run.get("is_marketable_external") and is_enrollable:
return True
course_run_status = course_run.get('status') or ''
is_published = course_run_status.lower() == 'published'
is_enrollable = course_run.get('is_enrollable', False)
is_marketable = course_run.get('is_marketable', False)

return is_published and is_enrollable and is_marketable
Expand Down
26 changes: 26 additions & 0 deletions enterprise_catalog/apps/catalog/tests/test_algolia_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,18 @@ class AlgoliaUtilsTests(TestCase):
'enrollment_end': days_from_now(30),
'restriction_type': RESTRICTION_FOR_B2B,
},
# A Exec-Ed course, not is_marketable but is_marketable_external.
{
'expected_result': True,
'course_type': EXEC_ED_2U_COURSE_TYPE,
'start': days_from_now(1),
'end': days_from_now(30),
'enrollment_end': days_from_now(1),
'is_marketable': False,
'is_marketable_external': True,
'advertised_course_run_status': 'reviewed',
'course_run_availability': 'Upcoming'
},
)
@ddt.unpack
def test_should_index_course(
Expand All @@ -130,6 +142,7 @@ def test_should_index_course(
advertised_course_run_status='published',
is_enrollable=True,
is_marketable=True,
is_marketable_external=True,
course_run_availability='current',
seats=None,
course_type=COURSE,
Expand All @@ -155,6 +168,7 @@ def test_should_index_course(
'status': advertised_course_run_status,
'is_enrollable': is_enrollable,
'is_marketable': is_marketable,
'is_marketable_external': is_marketable_external,
'availability': course_run_availability,
'seats': seats or [],
'start': start,
Expand Down Expand Up @@ -783,6 +797,18 @@ def test_get_course_runs(self, searchable_course, expected_course_runs):
},
['Archived'],
),
(
{
'course_runs': [{
'status': 'reviewed',
'is_enrollable': True,
'is_marketable': False,
'is_marketable_external': True,
'availability': 'Upcoming'
}]
},
['Upcoming'],
),
)
@ddt.unpack
def test_get_course_availability(self, course_metadata, expected_availability):
Expand Down

0 comments on commit fe08f97

Please sign in to comment.