Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update MITx Online ETL to not parse the readable ID for departments #908

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
11 changes: 8 additions & 3 deletions learning_resources/etl/mitxonline.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
)
from learning_resources.etl.constants import ETLSource
from learning_resources.etl.utils import (
extract_valid_department_from_id,
generate_course_numbers_json,
parse_certification,
transform_topics,
Expand Down Expand Up @@ -72,6 +71,12 @@ def parse_page_attribute(
return default_value


def parse_mitxonline_departments(departments):
"""Map the MITx Online departments to Open ones"""

return [mxo_dept["name"] for mxo_dept in departments]


def extract_programs():
"""Loads the MITx Online catalog data""" # noqa: D401
if settings.MITX_ONLINE_PROGRAMS_API_URL:
Expand Down Expand Up @@ -171,7 +176,7 @@ def _transform_course(course):
"title": course["title"],
"offered_by": copy.deepcopy(OFFERED_BY),
"topics": transform_topics(course.get("topics", [])),
"departments": extract_valid_department_from_id(course["readable_id"]),
"departments": parse_mitxonline_departments(course["departments"]),
"runs": [
_transform_run(course_run, course) for course_run in course["courseruns"]
],
Expand Down Expand Up @@ -218,7 +223,7 @@ def transform_programs(programs):
"offered_by": OFFERED_BY,
"etl_source": ETLSource.mitxonline.name,
"resource_type": LearningResourceType.program.name,
"departments": extract_valid_department_from_id(program["readable_id"]),
"departments": parse_mitxonline_departments(program["departments"]),
"platform": PlatformType.mitxonline.name,
"professional": False,
"certification": bool(parse_page_attribute(program, "page_url")),
Expand Down
8 changes: 4 additions & 4 deletions learning_resources/etl/mitxonline_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
_transform_image,
extract_courses,
extract_programs,
parse_mitxonline_departments,
parse_page_attribute,
parse_program_prices,
transform_courses,
transform_programs,
)
from learning_resources.etl.utils import (
UCC_TOPIC_MAPPINGS,
extract_valid_department_from_id,
parse_certification,
)
from main.test_utils import any_instance_of
Expand Down Expand Up @@ -162,8 +162,8 @@ def test_mitxonline_transform_programs(mock_mitxonline_programs_data):
"resource_type": LearningResourceType.course.name,
"professional": False,
"etl_source": ETLSource.mitxonline.value,
"departments": extract_valid_department_from_id(
course_data["readable_id"]
"departments": parse_mitxonline_departments(
course_data["departments"]
),
"title": course_data["title"],
"image": _transform_image(course_data),
Expand Down Expand Up @@ -247,7 +247,7 @@ def test_mitxonline_transform_courses(settings, mock_mitxonline_courses_data):
"platform": PlatformType.mitxonline.name,
"etl_source": ETLSource.mitxonline.name,
"resource_type": LearningResourceType.course.name,
"departments": extract_valid_department_from_id(course_data["readable_id"]),
"departments": parse_mitxonline_departments(course_data["departments"]),
"title": course_data["title"],
"image": _transform_image(course_data),
"description": course_data.get("page", {}).get("description", None),
Expand Down
Loading
Loading