Skip to content

Commit

Permalink
Merge pull request #542 from edx/hammad/WL-1952
Browse files Browse the repository at this point in the history
WL-1952 | Handle corner cases for default values in CornerstoneCourseListAPI.
  • Loading branch information
HammadAhmadWaqas authored Aug 1, 2019
2 parents 51a0341 + 905da82 commit bb09fbc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ Change Log
Unreleased
----------

[1.8.8] - 2019-08-01
--------------------

* For CornerstoneCourseListAPI handled corner cases for default values.


[1.8.7] - 2019-07-31
--------------------

Expand Down
2 changes: 1 addition & 1 deletion enterprise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

from __future__ import absolute_import, unicode_literals

__version__ = "1.8.7"
__version__ = "1.8.8"

default_app_config = "enterprise.apps.EnterpriseConfig" # pylint: disable=invalid-name
10 changes: 6 additions & 4 deletions integrated_channels/cornerstone/exporters/content_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class CornerstoneContentMetadataExporter(ContentMetadataExporter): # pylint: di
"""
LONG_STRING_LIMIT = 10000
DEFAULT_SUBJECT = "Industry Specific"
DEFAULT_LANGUAGE = "English"
DEFAULT_OWNER = {
"Name": "edX: edX Inc"
}
Expand All @@ -47,9 +48,10 @@ def transform_organizations(self, content_metadata_item):
"""
Return the transformed version of the course organizations
by converting each organization into cornerstone course owner object.
or default Onwer if no owner found
"""
owners = []
for org in content_metadata_item.get('organizations', []):
for org in content_metadata_item.get('organizations') or []:
org_name = org[:500] if org else ''
owners.append({"Name": org_name})
return owners or [self.DEFAULT_OWNER]
Expand Down Expand Up @@ -100,7 +102,7 @@ def transform_languages(self, content_metadata_item):
"""
Return the languages supported by course or `English` as default if no languages found.
"""
languages = content_metadata_item.get('languages', ['English'])
languages = content_metadata_item.get('languages') or [self.DEFAULT_LANGUAGE]
return [get_language_code(language) for language in languages]

def transform_description(self, content_metadata_item):
Expand All @@ -117,10 +119,10 @@ def transform_description(self, content_metadata_item):

def transform_subjects(self, content_metadata_item):
"""
Return the transformed version of the course subject list.
Return the transformed version of the course subject list or default value if no subject found.
"""
subjects = []
course_subjects = content_metadata_item.get('subjects', [])
course_subjects = content_metadata_item.get('subjects') or []
CornerstoneGlobalConfiguration = apps.get_model( # pylint: disable=invalid-name
'cornerstone',
'CornerstoneGlobalConfiguration'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,18 @@ def test_transform_modified(self, item_course_runs, expected_modified_datetime):
{'languages': ['English']},
['en-US'],
),
(
{'languages': []},
['en-US'],
),
(
{'languages': 'undefined'},
['en-US'],
),
(
{'languages': None},
['en-US'],
),
(
{'languages': ['Spanish', 'English', 'Japanese']},
['es-ES', 'en-US', 'ja'],
Expand All @@ -457,6 +465,10 @@ def test_transform_languages(self, item_languages, expected_languages):
{'organizations': 'undefined'},
[DEFAULT_OWNER],
),
(
{'organizations': None},
[DEFAULT_OWNER],
),
(
None,
[{"Name": "edX: "}],
Expand Down Expand Up @@ -499,6 +511,12 @@ def test_transform_organizations(self, item_organizations, expected_organization
},
["Industry Specific"]
),
(
{
'subjects': None
},
["Industry Specific"]
),
)
@responses.activate
@ddt.unpack
Expand Down

0 comments on commit bb09fbc

Please sign in to comment.