Skip to content

Commit

Permalink
feat: log when we CAN index a course, not just when we cannot
Browse files Browse the repository at this point in the history
  • Loading branch information
pwnage101 committed Dec 12, 2024
1 parent 1c654e1 commit 15633eb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
14 changes: 13 additions & 1 deletion enterprise_catalog/apps/catalog/algolia_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
from enterprise_catalog.apps.catalog.constants import (
ALGOLIA_DEFAULT_TIMESTAMP,
COURSE,
COURSE_RUN_RESTRICTION_TYPE_KEY,
EXEC_ED_2U_COURSE_TYPE,
EXEC_ED_2U_READABLE_COURSE_TYPE,
LATE_ENROLLMENT_THRESHOLD_DAYS,
LEARNER_PATHWAY,
PROGRAM,
PROGRAM_TYPES_MAP,
RESTRICTION_FOR_B2B,
VIDEO,
)
from enterprise_catalog.apps.catalog.content_metadata_utils import (
Expand Down Expand Up @@ -256,9 +258,19 @@ def deadline_passed_checker():
):
should_not_index = should_not_index_function()
if should_not_index:
logger.info(f'Not indexing {course_metadata.content_key}, reason: {log_message}')
logger.info(f'Not indexing course {course_metadata.content_key}, reason: {log_message}')
return False

all_runs = course_json_metadata.get('course_runs', [])
num_runs_total = len(all_runs)
num_runs_restricted = len([
run for run in all_runs
if run.get(COURSE_RUN_RESTRICTION_TYPE_KEY) == RESTRICTION_FOR_B2B
])
logger.info(
f'Indexing course {course_metadata.content_key} with {num_runs_total} '
f'total runs, of which {num_runs_restricted} are restricted for enterprise.'
)
return True


Expand Down
34 changes: 28 additions & 6 deletions enterprise_catalog/apps/catalog/tests/test_algolia_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,26 +87,34 @@ class AlgoliaUtilsTests(TestCase):
],
},
{
'course_type': EXEC_ED_2U_COURSE_TYPE,
'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)
},
{
'course_type': EXEC_ED_2U_COURSE_TYPE,
'expected_result': False,
'course_type': EXEC_ED_2U_COURSE_TYPE,
'start': days_from_now(-30),
'end': days_from_now(-1),
'enrollment_end': days_from_now(-30)
},
{
'course_type': EXEC_ED_2U_COURSE_TYPE,
'expected_result': True,
'course_type': EXEC_ED_2U_COURSE_TYPE,
'start': days_from_now(-30),
'end': days_from_now(-1),
'enrollment_end': None
},
# A standard indexable Exec Ed course, but with a restricted run.
{
'expected_result': True,
'course_type': EXEC_ED_2U_COURSE_TYPE,
'start': days_from_now(1),
'enrollment_end': days_from_now(30),
'restriction_type': RESTRICTION_FOR_B2B,
},
)
@ddt.unpack
def test_should_index_course(
Expand All @@ -123,7 +131,8 @@ def test_should_index_course(
course_type=COURSE,
start='2023-01-29T23:59:59Z',
end='2023-02-28T23:59:59Z',
enrollment_end='2023-01-29T23:59:59Z'
enrollment_end='2023-01-29T23:59:59Z',
restriction_type=None,
):
"""
Verify that only a course that has a non-hidden advertised course run, at least one owner, and a marketing slug
Expand All @@ -146,7 +155,8 @@ def test_should_index_course(
'seats': seats or [],
'start': start,
'end': end,
'enrollment_end': enrollment_end
'enrollment_end': enrollment_end,
'restriction_type': restriction_type,
},
],
'owners': owners,
Expand All @@ -159,7 +169,19 @@ def test_should_index_course(
_json_metadata=json_metadata,
)
# pylint: disable=protected-access
assert utils._should_index_course(course_metadata) is expected_result
with self.assertLogs(level='INFO') as info_logs:
assert utils._should_index_course(course_metadata) is expected_result

if expected_result:
indexing_course_log_records = [
record for record
in info_logs.output
if (
f'Indexing course {course_metadata.content_key} with 1 total runs, '
f'of which {"1" if restriction_type else "0"} are restricted'
) in record
]
assert len(indexing_course_log_records) == 1

def test_is_course_archived(self):
"""
Expand Down

0 comments on commit 15633eb

Please sign in to comment.