From 68f55aa218bea49bc4c7da345bf29f1c1c8c4864 Mon Sep 17 00:00:00 2001 From: Brian Citro <67378070+bcitro@users.noreply.github.com> Date: Tue, 11 Apr 2023 09:04:17 -0400 Subject: [PATCH] feat: include owners and longer descriptions for degreed2 content metadata transmissions (#1736) --- CHANGELOG.rst | 4 + enterprise/__init__.py | 2 +- .../degreed2/exporters/content_metadata.py | 28 +++- .../test_exporters/test_content_metadata.py | 142 +++++++++++++++++- 4 files changed, 163 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 8a2b6ad7ec..01bd4f85f5 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -17,6 +17,10 @@ Unreleased ---------- * Nothing +[3.61.11] +--------- +feat: include owners and longer descriptions for degreed2 content metadata transmissions + [3.61.10] --------- feat: new tagging orphaned content tast for integrated channels diff --git a/enterprise/__init__.py b/enterprise/__init__.py index 7f9006d892..3824290857 100644 --- a/enterprise/__init__.py +++ b/enterprise/__init__.py @@ -2,6 +2,6 @@ Your project description goes here. """ -__version__ = "3.61.10" +__version__ = "3.61.11" default_app_config = "enterprise.apps.EnterpriseConfig" diff --git a/integrated_channels/degreed2/exporters/content_metadata.py b/integrated_channels/degreed2/exporters/content_metadata.py index 9e5d2d11cd..27e676d279 100644 --- a/integrated_channels/degreed2/exporters/content_metadata.py +++ b/integrated_channels/degreed2/exporters/content_metadata.py @@ -25,6 +25,7 @@ class Degreed2ContentMetadataExporter(ContentMetadataExporter): CHUNK_PAGE_LENGTH = 1000 SHORT_STRING_LIMIT = 255 LONG_STRING_LIMIT = 2000 + ELLIPSIS = '...' DATA_TRANSFORM_MAPPING = { 'title': 'title', @@ -84,19 +85,32 @@ def transform_description(self, content_metadata_item): Return the transformed version of the course description. We choose one value out of the course's full description, short description, and title - depending on availability and length limits. + depending on availability. """ course_runs = content_metadata_item.get('course_runs') + duration_info = get_course_run_duration_info( get_closest_course_run(course_runs) ) if course_runs else '' - full_description = content_metadata_item.get('full_description') or '' - if full_description and 0 < len(full_description + duration_info) <= self.LONG_STRING_LIMIT: - description = full_description - else: - description = content_metadata_item.get('short_description') or content_metadata_item.get('title') or '' + + owner_names = '' + owners = content_metadata_item.get('owners') + if owners: + owner_names = ', '.join([owner['name'] for owner in owners]) + if owner_names: + owner_names = "[{}]: ".format(owner_names) + + description = ( + content_metadata_item.get('full_description') + or content_metadata_item.get('short_description') + or content_metadata_item.get('title') + or '') + if description: - description = "{duration_info}{description}".format(duration_info=duration_info, description=description) + description = "{}{}{}".format(owner_names, duration_info, description) + if len(description) > self.LONG_STRING_LIMIT: + description = description[:self.LONG_STRING_LIMIT - len(self.ELLIPSIS)] + self.ELLIPSIS + return strip_html_tags(description) def transform_courserun_content_language(self, content_metadata_item): diff --git a/tests/test_integrated_channels/test_degreed2/test_exporters/test_content_metadata.py b/tests/test_integrated_channels/test_degreed2/test_exporters/test_content_metadata.py index c9d30fb7ee..353b3e30cc 100644 --- a/tests/test_integrated_channels/test_degreed2/test_exporters/test_content_metadata.py +++ b/tests/test_integrated_channels/test_degreed2/test_exporters/test_content_metadata.py @@ -31,10 +31,41 @@ def setUp(self): @ddt.data( ( + # full description under length limit { 'title': 'edX Demonstration Course', 'short_description': 'Some short description.', 'full_description': 'Detailed description of edx demo course.', + 'owners': [ + { + 'name': 'edX' + } + ], + 'course_runs': [ + { + 'start': '2018-02-05T05:00:00Z', + 'min_effort': 2, + 'max_effort': 4, + 'weeks_to_complete': 10 + }, + { + 'start': '2017-02-05T05:00:00Z', + 'min_effort': 9, + 'max_effort': 10, + 'weeks_to_complete': 12 + } + ] + }, + + '[edX]: 2-4 hours a week for 10 weeks. Detailed description of edx demo course.', + ), + ( + # no owners + { + 'title': 'edX Demonstration Course', + 'short_description': 'Some short description.', + 'full_description': 'Detailed description of edx demo course.', + 'owners': [], 'course_runs': [ { 'start': '2018-02-05T05:00:00Z', @@ -50,13 +81,52 @@ def setUp(self): } ] }, + '2-4 hours a week for 10 weeks. Detailed description of edx demo course.', ), ( + # multiple owners + { + 'title': 'edX Demonstration Course', + 'short_description': 'Some short description.', + 'full_description': 'Detailed description of edx demo course.', + 'owners': [ + { + 'name': 'edX' + }, + { + 'name': 'MIT' + } + ], + 'course_runs': [ + { + 'start': '2018-02-05T05:00:00Z', + 'min_effort': 2, + 'max_effort': 4, + 'weeks_to_complete': 10 + }, + { + 'start': '2017-02-05T05:00:00Z', + 'min_effort': 9, + 'max_effort': 10, + 'weeks_to_complete': 12 + } + ] + }, + + '[edX, MIT]: 2-4 hours a week for 10 weeks. Detailed description of edx demo course.', + ), + ( + # empty full description { 'title': 'edX Demonstration Course', 'short_description': 'Some short description.', 'full_description': '', + 'owners': [ + { + 'name': 'edX' + } + ], 'course_runs': [ { 'start': '2018-02-05T05:00:00Z', @@ -66,13 +136,19 @@ def setUp(self): } ] }, - '2-4 hours a week for 10 weeks. Some short description.', + '[edX]: 2-4 hours a week for 10 weeks. Some short description.', ), ( + # empty full and short description { 'title': 'edX Demonstration Course', 'short_description': '', 'full_description': '', + 'owners': [ + { + 'name': 'edX' + } + ], 'course_runs': [ { 'start': '2018-02-05T05:00:00Z', @@ -82,13 +158,19 @@ def setUp(self): } ] }, - '2-4 hours a week for 10 weeks. edX Demonstration Course', + '[edX]: 2-4 hours a week for 10 weeks. edX Demonstration Course', ), ( + # empty everything { 'title': '', 'short_description': '', 'full_description': '', + 'owners': [ + { + 'name': 'edX' + } + ], 'course_runs': [ { 'start': '2018-02-05T05:00:00Z', @@ -101,15 +183,43 @@ def setUp(self): '', ), ( + # full_description over limit, with tags { 'title': '', 'short_description': '', - 'full_description': '

This course is part of the ' + 'full_description': '

This description is very long and over the long string limit. This course is ' + 'part of the ' '' '≤Professional Program Certificate in Data Science' ' That doesn’t ' 'only teach us how to build a cloud data science solution using Microsoft Azure ' - 'Machine Learning platform', + 'Machine Learning platform' + 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc vel blandit est. ' + 'Sed a justo maximus, hendrerit tortor quis, dictum purus. Morbi rutrum vitae ' + 'neque at suscipit. Vestibulum sollicitudin porttitor neque sit amet sodales. ' + 'Integer egestas elit sagittis interdum euismod. Maecenas tincidunt, urna ut ' + 'vehicula egestas, urna nisl ultricies felis, sed dignissim orci nisl vel turpis. ' + 'Vivamus efficitur tempus auctor. Nunc mattis, nisi quis gravida vehicula,' + 'massa nisi gravida sapien, vitae interdum sapien erat nec eros. Proin augue elit,' + 'placerat quis sapien eu, gravida auctor orci. Phasellus et mollis neque, congue' + 'tempor ipsum. Morbi dignissim venenatis est. Integer lobortis massa vel aliquet' + 'aliquam. Fusce a lectus mi. Vivamus non commodo libero. Sed bibendum commodo ex' + 'sodales facilisis. Aliquam ac euismod elit, a fringilla enim. Suspendisse ante' + 'erat, malesuada non libero ut, iaculis fermentum nisl. Proin non quam in risus' + 'feugiat facilisis. Pellentesque habitant morbi tristique senectus et netus et' + 'malesuada fames ac turpis egestas. Nulla ac leo massa. Nulla faucibus diam quis' + 'arcu euismod, vel volutpat nulla blandit. In vel consectetur ipsum, in congue' + 'nibh. Mauris fringilla commodo justo. Nullam et placerat velit. Sed in commodo' + 'sapien. Nam non risus congue, rhoncus neque ac, facilisis tortor. Aenean nulla' + 'lacus, pharetra non felis porttitor, scelerisque sagittis magna. Cras tristique,' + 'ante a ultricies gravida, purus orci pulvinar nisi, quis fermentum libero metus' + 'nec mauris. Praesent lectus lectus, condimentum eget augue nec, volutpat rutrum' + 'lacus. Vivamus eget tincidunto', + 'owners': [ + { + 'name': 'edX' + } + ], 'course_runs': [ { 'start': '2018-02-05T05:00:00Z', @@ -120,9 +230,31 @@ def setUp(self): ] }, - '2-4 hours a week for 10 weeks. ' + '[edX]: 2-4 hours a week for 10 weeks. ' + 'This description is very long and over the long string limit. ' 'This course is part of the Professional Program Certificate in Data ScienceThat doesnt ' 'only teach us how to build a cloud data science solution using Microsoft Azure Machine Learning platform' + 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc vel blandit est. ' + 'Sed a justo maximus, hendrerit tortor quis, dictum purus. Morbi rutrum vitae ' + 'neque at suscipit. Vestibulum sollicitudin porttitor neque sit amet sodales. ' + 'Integer egestas elit sagittis interdum euismod. Maecenas tincidunt, urna ut ' + 'vehicula egestas, urna nisl ultricies felis, sed dignissim orci nisl vel turpis. ' + 'Vivamus efficitur tempus auctor. Nunc mattis, nisi quis gravida vehicula,' + 'massa nisi gravida sapien, vitae interdum sapien erat nec eros. Proin augue elit,' + 'placerat quis sapien eu, gravida auctor orci. Phasellus et mollis neque, congue' + 'tempor ipsum. Morbi dignissim venenatis est. Integer lobortis massa vel aliquet' + 'aliquam. Fusce a lectus mi. Vivamus non commodo libero. Sed bibendum commodo ex' + 'sodales facilisis. Aliquam ac euismod elit, a fringilla enim. Suspendisse ante' + 'erat, malesuada non libero ut, iaculis fermentum nisl. Proin non quam in risus' + 'feugiat facilisis. Pellentesque habitant morbi tristique senectus et netus et' + 'malesuada fames ac turpis egestas. Nulla ac leo massa. Nulla faucibus diam quis' + 'arcu euismod, vel volutpat nulla blandit. In vel consectetur ipsum, in congue' + 'nibh. Mauris fringilla commodo justo. Nullam et placerat velit. Sed in commodo' + 'sapien. Nam non risus congue, rhoncus neque ac, facilisis tortor. Aenean nulla' + 'lacus, pharetra non felis porttitor, scelerisque sagittis magna. Cras tristique,' + 'ante a ultricies gravida, purus orci pulvinar nisi, quis fermentum libero metus' + 'nec mauris. Praesent lectus lectus, condimentum eget augue nec, volutpat rutrum' + 'lacus. Vivamus eget tinci...' ), ) @responses.activate