From 85c0b1883cd50a2cc5ce4afb63a2c3ef0676240e Mon Sep 17 00:00:00 2001 From: Matt Bertrand Date: Mon, 8 Jul 2024 11:55:25 -0400 Subject: [PATCH] Only publish enrollable mitxonline courses --- learning_resources/etl/mitxonline.py | 6 ++++-- learning_resources/etl/mitxonline_test.py | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/learning_resources/etl/mitxonline.py b/learning_resources/etl/mitxonline.py index 3e8be5c938..2e9c71b0b5 100644 --- a/learning_resources/etl/mitxonline.py +++ b/learning_resources/etl/mitxonline.py @@ -114,6 +114,7 @@ def extract_courses(): params={ "page__live": True, "live": True, + "courserun_is_enrollable": True, }, ) ) @@ -171,7 +172,7 @@ def _transform_run(course_run: dict, course: dict) -> dict: "enrollment_start": _parse_datetime(course_run.get("enrollment_start")), "enrollment_end": _parse_datetime(course_run.get("enrollment_end")), "url": parse_page_attribute(course, "page_url", is_url=True), - "published": bool(parse_page_attribute(course, "page_url")), + "published": bool(course_run["is_enrollable"] and course["page"]["live"]), "description": clean_data(parse_page_attribute(course_run, "description")), "image": _transform_image(course_run), "prices": sorted( @@ -227,7 +228,8 @@ def _transform_course(course): "published": bool( parse_page_attribute(course, "page_url") and parse_page_attribute(course, "live") - ), # a course is only considered published if it has a page url + and len([run for run in runs if run["published"]]) > 0 + ), # a course is only published if it has a live url and published runs "professional": False, "certification": has_certification, "certification_type": CertificationType.completion.name diff --git a/learning_resources/etl/mitxonline_test.py b/learning_resources/etl/mitxonline_test.py index 18aa49ef44..c7db475ba1 100644 --- a/learning_resources/etl/mitxonline_test.py +++ b/learning_resources/etl/mitxonline_test.py @@ -195,6 +195,14 @@ def test_mitxonline_transform_programs( "published": bool( course_data.get("page", {}).get("page_url", None) and course_data.get("page", {}).get("live", None) + and len( + [ + run + for run in course_data["courseruns"] + if run["is_enrollable"] + ] + ) + > 0 ), "certification": True, "certification_type": CertificationType.completion.name, @@ -222,7 +230,8 @@ def test_mitxonline_transform_programs( ), "description": any_instance_of(str, type(None)), "published": bool( - parse_page_attribute(course_data, "page_url") + course_run_data["is_enrollable"] + and course_data["page"]["live"] ), "prices": sorted( { @@ -362,7 +371,9 @@ def test_mitxonline_transform_courses(settings, mock_mitxonline_courses_data): "end_date": any_instance_of(datetime, type(None)), "enrollment_start": any_instance_of(datetime, type(None)), "enrollment_end": any_instance_of(datetime, type(None)), - "published": bool(course_data.get("page", {}).get("page_url")), + "published": bool( + course_run_data["is_enrollable"] and course_data["page"]["live"] + ), "prices": sorted( { "0.00",