Update CourseDetails support for Course About information
This commit is contained in:
@@ -60,10 +60,13 @@ class CourseDetails(object):
|
||||
self.self_paced = None
|
||||
|
||||
@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
|
||||
"""
|
||||
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)
|
||||
try:
|
||||
value = modulestore().get_item(usage_key).data
|
||||
@@ -96,7 +99,7 @@ class CourseDetails(object):
|
||||
course_details.intro_video = cls.fetch_youtube_video_id(course_key)
|
||||
|
||||
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:
|
||||
setattr(course_details, attribute, value)
|
||||
|
||||
@@ -107,7 +110,7 @@ class CourseDetails(object):
|
||||
"""
|
||||
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:
|
||||
return cls.parse_video_tag(raw_video)
|
||||
|
||||
@@ -120,13 +123,6 @@ class CourseDetails(object):
|
||||
if video_id:
|
||||
return "http://www.youtube.com/watch?v={0}".format(video_id)
|
||||
|
||||
@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):
|
||||
"""
|
||||
|
||||
@@ -3,6 +3,7 @@ Tests for CourseDetails
|
||||
"""
|
||||
|
||||
import datetime
|
||||
import ddt
|
||||
from django.utils.timezone import UTC
|
||||
|
||||
from xmodule.modulestore import ModuleStoreEnum
|
||||
@@ -10,9 +11,10 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
|
||||
from xmodule.modulestore.tests.factories import CourseFactory
|
||||
|
||||
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):
|
||||
"""
|
||||
Tests the first course settings page (course dates, overview, etc.).
|
||||
@@ -111,11 +113,19 @@ class CourseDetailsTestCase(ModuleStoreTestCase):
|
||||
)
|
||||
self.assertFalse(updated_details.self_paced)
|
||||
|
||||
def test_fetch_effort(self):
|
||||
effort_value = 'test_hours_of_effort'
|
||||
@ddt.data(*ABOUT_ATTRIBUTES)
|
||||
def test_fetch_about_attribute(self, attribute_name):
|
||||
attribute_value = 'test_value'
|
||||
with self.store.branch_setting(ModuleStoreEnum.Branch.draft_preferred, self.course.id):
|
||||
CourseDetails.update_about_item(self.course, 'effort', effort_value, self.user.id)
|
||||
self.assertEqual(CourseDetails.fetch_effort(self.course.id), effort_value)
|
||||
CourseDetails.update_about_item(self.course, attribute_name, attribute_value, self.user.id)
|
||||
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):
|
||||
video_value = 'test_video_id'
|
||||
|
||||
Reference in New Issue
Block a user