diff --git a/learning_resources/etl/ocw.py b/learning_resources/etl/ocw.py index 56850a9e48..f8c845a615 100644 --- a/learning_resources/etl/ocw.py +++ b/learning_resources/etl/ocw.py @@ -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") @@ -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"): diff --git a/learning_resources/etl/ocw_test.py b/learning_resources/etl/ocw_test.py index 476cbcd503..4ee05ceabb 100644 --- a/learning_resources/etl/ocw_test.py +++ b/learning_resources/etl/ocw_test.py @@ -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("/") @@ -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] == { @@ -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)