From 37dfc14993bdc5e14b22a56e064dc2eb67c3604e Mon Sep 17 00:00:00 2001 From: irfanuddinahmad Date: Thu, 24 Oct 2019 12:28:01 +0500 Subject: [PATCH] Updated image url field for cornerstone and degreed --- CHANGELOG.rst | 5 ++ enterprise/__init__.py | 2 +- .../cornerstone/exporters/content_metadata.py | 9 ++- .../degreed/exporters/content_metadata.py | 10 +-- .../exporters/content_metadata.py | 9 +-- integrated_channels/utils.py | 13 ++++ .../test_exporters/test_content_metadata.py | 61 +++++++++++++++++++ .../test_exporters/test_content_metadata.py | 4 +- 8 files changed, 94 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b44e4b45d8..7b86249d44 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -13,6 +13,11 @@ Change Log Unreleased ---------- +[2.0.9] - 2019-10-28 +--------------------- + +* Updated image url field in content metadata export for cornerstone and degreed + [2.0.8] - 2019-10-22 --------------------- diff --git a/enterprise/__init__.py b/enterprise/__init__.py index 2809c114bc..1314fee721 100644 --- a/enterprise/__init__.py +++ b/enterprise/__init__.py @@ -4,6 +4,6 @@ from __future__ import absolute_import, unicode_literals -__version__ = "2.0.8" +__version__ = "2.0.9" default_app_config = "enterprise.apps.EnterpriseConfig" # pylint: disable=invalid-name diff --git a/integrated_channels/cornerstone/exporters/content_metadata.py b/integrated_channels/cornerstone/exporters/content_metadata.py index c0c1c67146..72443c6da3 100644 --- a/integrated_channels/cornerstone/exporters/content_metadata.py +++ b/integrated_channels/cornerstone/exporters/content_metadata.py @@ -15,6 +15,7 @@ from enterprise.utils import get_closest_course_run, get_language_code from integrated_channels.integrated_channel.exporters.content_metadata import ContentMetadataExporter +from integrated_channels.utils import get_image_url LOGGER = getLogger(__name__) @@ -33,7 +34,7 @@ class CornerstoneContentMetadataExporter(ContentMetadataExporter): # pylint: di 'ID': 'key', 'Title': 'title', 'Description': 'description', - 'Thumbnail': 'card_image_url', + 'Thumbnail': 'image', 'URL': 'enrollment_url', 'IsActive': 'is_active', 'LastModifiedUTC': 'modified', @@ -98,6 +99,12 @@ def transform_estimated_hours(self, content_metadata_item): return duration + def transform_image(self, content_metadata_item): + """ + Return the image URI of the content item. + """ + return get_image_url(content_metadata_item) + def transform_languages(self, content_metadata_item): """ Return the languages supported by course or `English` as default if no languages found. diff --git a/integrated_channels/degreed/exporters/content_metadata.py b/integrated_channels/degreed/exporters/content_metadata.py index 8955e665a0..a1831d85b7 100644 --- a/integrated_channels/degreed/exporters/content_metadata.py +++ b/integrated_channels/degreed/exporters/content_metadata.py @@ -9,7 +9,7 @@ from enterprise.utils import get_closest_course_run, get_course_run_duration_info from integrated_channels.integrated_channel.exporters.content_metadata import ContentMetadataExporter -from integrated_channels.utils import strip_html_tags +from integrated_channels.utils import get_image_url, strip_html_tags LOGGER = getLogger(__name__) @@ -78,13 +78,7 @@ def transform_image(self, content_metadata_item): """ Return the image URI of the content item. """ - image_url = '' - if content_metadata_item['content_type'] in ['course', 'program']: - image_url = content_metadata_item.get('card_image_url') - elif content_metadata_item['content_type'] == 'courserun': - image_url = content_metadata_item.get('image_url') - - return image_url + return get_image_url(content_metadata_item) def transform_program_key(self, content_metadata_item): """ diff --git a/integrated_channels/sap_success_factors/exporters/content_metadata.py b/integrated_channels/sap_success_factors/exporters/content_metadata.py index a978018a38..1b9623749f 100644 --- a/integrated_channels/sap_success_factors/exporters/content_metadata.py +++ b/integrated_channels/sap_success_factors/exporters/content_metadata.py @@ -21,6 +21,7 @@ UNIX_MAX_DATE_STRING, UNIX_MIN_DATE_STRING, current_time_is_in_interval, + get_image_url, parse_datetime_to_epoch_millis, ) @@ -112,13 +113,7 @@ def transform_image(self, content_metadata_item): """ Return the image URI of the content item. """ - image_url = '' - if content_metadata_item['content_type'] == 'program': - image_url = content_metadata_item.get('card_image_url') - elif content_metadata_item['content_type'] in ['course', 'courserun']: - image_url = content_metadata_item.get('image_url') - - return image_url + return get_image_url(content_metadata_item) def transform_launch_points(self, content_metadata_item): """ diff --git a/integrated_channels/utils.py b/integrated_channels/utils.py index aa589d3b1c..560b3b4b6f 100644 --- a/integrated_channels/utils.py +++ b/integrated_channels/utils.py @@ -136,3 +136,16 @@ def strfdelta(tdelta, fmt='{D:02}d {H:02}h {M:02}m {S:02}s', input_type='timedel values[field], remainder = divmod(remainder, constants[field]) return f.format(fmt, **values) + + +def get_image_url(content_metadata_item): + """ + Return the image URI of the content item. + """ + image_url = '' + if content_metadata_item['content_type'] == 'program': + image_url = content_metadata_item.get('card_image_url') + elif content_metadata_item['content_type'] in ['course', 'courserun']: + image_url = content_metadata_item.get('image_url') + + return image_url diff --git a/tests/test_integrated_channels/test_cornerstone/test_exporters/test_content_metadata.py b/tests/test_integrated_channels/test_cornerstone/test_exporters/test_content_metadata.py index 5cffe49bca..9bc585bce3 100644 --- a/tests/test_integrated_channels/test_cornerstone/test_exporters/test_content_metadata.py +++ b/tests/test_integrated_channels/test_cornerstone/test_exporters/test_content_metadata.py @@ -536,3 +536,64 @@ def test_transform_subjects(self, item_subjects, expected_subjects): item_content_metadata = self._merge_dicts(FAKE_SEARCH_ALL_COURSE_RESULT_3, item_subjects) exporter = CornerstoneContentMetadataExporter('fake-user', self.config) assert sorted(exporter.transform_subjects(item_content_metadata)) == sorted(expected_subjects) + + @ddt.data( + ( + { + 'aggregation_key': 'course:edX+DemoX', + 'title': 'edX Demonstration Course', + 'key': 'edX+DemoX', + 'content_type': 'course', + 'image_url': 'https://edx.devstack.lms:18000/' + 'asset-v1:edX+DemoX+Demo_Course+type@asset+block@images_course_image.jpg', + 'short_description': 'Some short description.', + 'full_description': 'Detailed description of edx demo course.', + }, + 'https://edx.devstack.lms:18000/asset-v1:edX+DemoX+Demo_Course+type@asset+block@images_course_image.jpg' + ), + ( + { + 'number': 'DemoX', + 'org': 'edX', + 'seat_types': ['verified', 'audit'], + 'key': 'course-v1:edX+DemoX+Demo_Course', + 'availability': 'Current', + 'title': 'edX Demonstration Course', + 'content_type': 'courserun', + 'image_url': 'https://edx.devstack.lms:18000/' + 'asset-v1:edX+DemoX+Demo_Course+type@asset+block@images_course_image.jpg', + }, + 'https://edx.devstack.lms:18000/asset-v1:edX+DemoX+Demo_Course+type@asset+block@images_course_image.jpg' + ), + ( + { + + 'uuid': '5742ec8d-25ce-43b7-a158-6dad82034ca2', + 'title': 'edX Demonstration program', + 'published': True, + 'language': [], + 'type': 'Verified Certificate', + 'status': 'active', + 'content_type': 'program', + 'card_image_url': 'https://edx.devstack.discovery/' + 'media/programs/banner_images/5742ec8d-25ce-43b7-a158-6dad82034ca2.jpg', + }, + 'https://edx.devstack.discovery/media/programs/banner_images/5742ec8d-25ce-43b7-a158-6dad82034ca2.jpg', + ), + ( + { + 'title': 'INVALID COURSE', + 'content_type': 'INVALID-CONTENT_TYPE', + }, + '', + ), + ) + @responses.activate + @ddt.unpack + def test_transform_image(self, content_metadata_item, expected_thumbnail_url): + """ + Transforming a image gives back the thumbnail URI by checking the + content type of the provided `content_metadata_item`. + """ + exporter = CornerstoneContentMetadataExporter('fake-user', self.config) + assert exporter.transform_image(content_metadata_item) == expected_thumbnail_url diff --git a/tests/test_integrated_channels/test_degreed/test_exporters/test_content_metadata.py b/tests/test_integrated_channels/test_degreed/test_exporters/test_content_metadata.py index 1c3ffe3838..dc76d989fb 100644 --- a/tests/test_integrated_channels/test_degreed/test_exporters/test_content_metadata.py +++ b/tests/test_integrated_channels/test_degreed/test_exporters/test_content_metadata.py @@ -59,8 +59,8 @@ def test_content_exporter_export(self): 'title': 'edX Demonstration Course', 'key': 'edX+DemoX', 'content_type': 'course', - 'card_image_url': 'https://edx.devstack.lms:18000/' - 'asset-v1:edX+DemoX+Demo_Course+type@asset+block@images_course_image.jpg', + 'image_url': 'https://edx.devstack.lms:18000/' + 'asset-v1:edX+DemoX+Demo_Course+type@asset+block@images_course_image.jpg', 'short_description': 'Some short description.', 'full_description': 'Detailed description of edx demo course.', },