diff --git a/enterprise_catalog/apps/catalog/algolia_utils.py b/enterprise_catalog/apps/catalog/algolia_utils.py index e19bb82f..684e217f 100644 --- a/enterprise_catalog/apps/catalog/algolia_utils.py +++ b/enterprise_catalog/apps/catalog/algolia_utils.py @@ -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 ( @@ -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 diff --git a/enterprise_catalog/apps/catalog/tests/test_algolia_utils.py b/enterprise_catalog/apps/catalog/tests/test_algolia_utils.py index d4513d95..5309f5c5 100644 --- a/enterprise_catalog/apps/catalog/tests/test_algolia_utils.py +++ b/enterprise_catalog/apps/catalog/tests/test_algolia_utils.py @@ -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( @@ -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 @@ -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, @@ -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): """