Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions learning_resources/etl/mitxonline.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def extract_courses():
params={
"page__live": True,
"live": True,
"courserun_is_enrollable": True,
},
)
)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions learning_resources/etl/mitxonline_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
{
Expand Down Expand Up @@ -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",
Expand Down