Commit 4133155a by Nimisha Asthagiri

Update CourseDetails support for Course About information

parent bb53c03e
...@@ -60,10 +60,13 @@ class CourseDetails(object): ...@@ -60,10 +60,13 @@ class CourseDetails(object):
self.self_paced = None self.self_paced = None
@classmethod @classmethod
def _fetch_about_attribute(cls, course_key, attribute): def fetch_about_attribute(cls, course_key, attribute):
""" """
Retrieve an attribute from a course's "about" info Retrieve an attribute from a course's "about" info
""" """
if attribute not in ABOUT_ATTRIBUTES + ['video']:
raise ValueError("'{0}' is not a valid course about attribute.".format(attribute))
usage_key = course_key.make_usage_key('about', attribute) usage_key = course_key.make_usage_key('about', attribute)
try: try:
value = modulestore().get_item(usage_key).data value = modulestore().get_item(usage_key).data
...@@ -96,7 +99,7 @@ class CourseDetails(object): ...@@ -96,7 +99,7 @@ class CourseDetails(object):
course_details.intro_video = cls.fetch_youtube_video_id(course_key) course_details.intro_video = cls.fetch_youtube_video_id(course_key)
for attribute in ABOUT_ATTRIBUTES: for attribute in ABOUT_ATTRIBUTES:
value = cls._fetch_about_attribute(course_key, attribute) value = cls.fetch_about_attribute(course_key, attribute)
if value is not None: if value is not None:
setattr(course_details, attribute, value) setattr(course_details, attribute, value)
...@@ -107,7 +110,7 @@ class CourseDetails(object): ...@@ -107,7 +110,7 @@ class CourseDetails(object):
""" """
Returns the course about video ID. Returns the course about video ID.
""" """
raw_video = cls._fetch_about_attribute(course_key, 'video') raw_video = cls.fetch_about_attribute(course_key, 'video')
if raw_video: if raw_video:
return cls.parse_video_tag(raw_video) return cls.parse_video_tag(raw_video)
...@@ -121,13 +124,6 @@ class CourseDetails(object): ...@@ -121,13 +124,6 @@ class CourseDetails(object):
return "http://www.youtube.com/watch?v={0}".format(video_id) return "http://www.youtube.com/watch?v={0}".format(video_id)
@classmethod @classmethod
def fetch_effort(cls, course_key):
"""
Returns the hours per week of effort for the course.
"""
return cls._fetch_about_attribute(course_key, 'effort')
@classmethod
def update_about_item(cls, course, about_key, data, user_id, store=None): def update_about_item(cls, course, about_key, data, user_id, store=None):
""" """
Update the about item with the new data blob. If data is None, Update the about item with the new data blob. If data is None,
......
...@@ -3,6 +3,7 @@ Tests for CourseDetails ...@@ -3,6 +3,7 @@ Tests for CourseDetails
""" """
import datetime import datetime
import ddt
from django.utils.timezone import UTC from django.utils.timezone import UTC
from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore import ModuleStoreEnum
...@@ -10,9 +11,10 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase ...@@ -10,9 +11,10 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
from openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration from openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration
from openedx.core.djangoapps.models.course_details import CourseDetails from openedx.core.djangoapps.models.course_details import CourseDetails, ABOUT_ATTRIBUTES
@ddt.ddt
class CourseDetailsTestCase(ModuleStoreTestCase): class CourseDetailsTestCase(ModuleStoreTestCase):
""" """
Tests the first course settings page (course dates, overview, etc.). Tests the first course settings page (course dates, overview, etc.).
...@@ -111,11 +113,19 @@ class CourseDetailsTestCase(ModuleStoreTestCase): ...@@ -111,11 +113,19 @@ class CourseDetailsTestCase(ModuleStoreTestCase):
) )
self.assertFalse(updated_details.self_paced) self.assertFalse(updated_details.self_paced)
def test_fetch_effort(self): @ddt.data(*ABOUT_ATTRIBUTES)
effort_value = 'test_hours_of_effort' def test_fetch_about_attribute(self, attribute_name):
attribute_value = 'test_value'
with self.store.branch_setting(ModuleStoreEnum.Branch.draft_preferred, self.course.id): with self.store.branch_setting(ModuleStoreEnum.Branch.draft_preferred, self.course.id):
CourseDetails.update_about_item(self.course, 'effort', effort_value, self.user.id) CourseDetails.update_about_item(self.course, attribute_name, attribute_value, self.user.id)
self.assertEqual(CourseDetails.fetch_effort(self.course.id), effort_value) self.assertEqual(CourseDetails.fetch_about_attribute(self.course.id, attribute_name), attribute_value)
def test_fetch_about_attribute_error(self):
attribute_name = 'not_an_about_attribute'
with self.store.branch_setting(ModuleStoreEnum.Branch.draft_preferred, self.course.id):
CourseDetails.update_about_item(self.course, attribute_name, 'test_value', self.user.id)
with self.assertRaises(ValueError):
CourseDetails.fetch_about_attribute(self.course.id, attribute_name)
def test_fetch_video(self): def test_fetch_video(self):
video_value = 'test_video_id' video_value = 'test_video_id'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment