-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ability to include unlisted courses in catalogs
- Loading branch information
Showing
5 changed files
with
141 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
""" | ||
Utility functions for manipulating content metadata. | ||
""" | ||
|
||
from logging import getLogger | ||
|
||
from .constants import FORCE_INCLUSION_METADATA_TAG_KEY | ||
|
||
|
||
LOGGER = getLogger(__name__) | ||
|
||
|
||
def tansform_force_included_courses(courses): | ||
""" | ||
Transform a list of forced/unlisted course metadata | ||
ENT-8212 | ||
""" | ||
results = [] | ||
for course_metadata in courses: | ||
results += transform_course_metadata_to_visible(course_metadata) | ||
return results | ||
|
||
|
||
def transform_course_metadata_to_visible(course_metadata): | ||
""" | ||
Transform an individual forced/unlisted course metadata | ||
so that it is visible/available/published in our metadata | ||
ENT-8212 | ||
""" | ||
course_metadata[FORCE_INCLUSION_METADATA_TAG_KEY] = True | ||
advertised_course_run_uuid = course_metadata.get('advertised_course_run_uuid') | ||
course_run_statuses = [] | ||
for course_run in course_metadata.get('course_runs', []): | ||
if course_run.get('uuid') == advertised_course_run_uuid: | ||
course_run['status'] = 'published' | ||
course_run['availability'] = 'Current' | ||
course_run_statuses.append(course_run.get('status')) | ||
course_metadata['course_run_statuses'] = course_run_statuses | ||
return course_metadata |
28 changes: 28 additions & 0 deletions
28
enterprise_catalog/apps/catalog/tests/test_content_metadata_utils.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from uuid import uuid4 | ||
|
||
from django.test import TestCase | ||
|
||
from enterprise_catalog.apps.catalog.content_metadata_utils import ( | ||
transform_course_metadata_to_visible, | ||
) | ||
|
||
|
||
class ContentMetadataUtilsTests(TestCase): | ||
""" | ||
Tests for content metadata utils. | ||
""" | ||
|
||
def test_transform_course_metadata_to_visible(self): | ||
advertised_course_run_uuid = str(uuid4()) | ||
content_metadata = { | ||
'advertised_course_run_uuid': advertised_course_run_uuid, | ||
'course_runs': [ | ||
{ | ||
'uuid': advertised_course_run_uuid, | ||
'status': 'unpublished', | ||
'availability': 'Coming Soon', | ||
} | ||
] | ||
} | ||
transform_course_metadata_to_visible(content_metadata) | ||
assert content_metadata['course_runs'][0]['status'] == 'published' |