Skip to content

Commit

Permalink
populate file extensions for ocw (#1891)
Browse files Browse the repository at this point in the history
  • Loading branch information
abeglova authored Dec 11, 2024
1 parent 22d1f8c commit b5760d6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions learning_resources/etl/ocw.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,12 @@ def transform_contentfile(
content_type = CONTENT_TYPE_VIDEO
file_s3_path = contentfile_data.get("transcript_file")
image_src = contentfile_data.get("thumbnail_file")
file_extension = Path(contentfile_data.get("file")).suffix
else:
content_type = get_content_type(file_type)
file_s3_path = contentfile_data.get("file")
image_src = None
file_extension = Path(file_s3_path).suffix

title = contentfile_data.get("title")

Expand All @@ -274,6 +276,7 @@ def transform_contentfile(
"key": s3_path,
"content_tags": contentfile_data.get("learning_resource_types"),
"published": True,
"file_extension": file_extension,
}

if not file_s3_path.startswith("courses"):
Expand Down
6 changes: 4 additions & 2 deletions learning_resources/etl/ocw_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
@pytest.mark.parametrize("base_ocw_url", ["http://test.edu/", "http://test.edu"])
def test_transform_content_files(settings, mocker, base_ocw_url):
"""
Test transform_content_files
Test that ocw.transform_content_files returns the expected data
"""
settings.OCW_BASE_URL = base_ocw_url
ocw_url = base_ocw_url.rstrip("/")
Expand Down Expand Up @@ -94,6 +94,7 @@ def test_transform_content_files(settings, mocker, base_ocw_url):
"title": "Resource Title",
"content_title": "Resource Title",
"url": f"{ocw_url}/courses/16-01-unified-engineering-i-ii-iii-iv-fall-2005-spring-2006/resources/resource/",
"file_extension": ".pdf",
}

assert content_data[3] == {
Expand All @@ -108,13 +109,14 @@ def test_transform_content_files(settings, mocker, base_ocw_url):
"content_title": None,
"url": f"{ocw_url}/courses/16-01-unified-engineering-i-ii-iii-iv-fall-2005-spring-2006/resources/video/",
"image_src": "https://img.youtube.com/vi/vKer2U5W5-s/default.jpg",
"file_extension": ".mp4",
}


@mock_aws
def test_transform_content_files_exceptions(settings, mocker):
"""
Test transform_content_files
Test that ocw.transform_content_files logs exceptions
"""

setup_s3_ocw(settings)
Expand Down

0 comments on commit b5760d6

Please sign in to comment.