Fixed error on Course Home, when viewed as specific student.
This commit is contained in:
@@ -28,6 +28,7 @@ from xmodule.modulestore.django import modulestore
|
||||
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
|
||||
from xmodule.modulestore.tests.factories import ItemFactory, CourseFactory
|
||||
from xmodule.partitions.partitions import Group, UserPartition
|
||||
from openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration
|
||||
|
||||
|
||||
class MasqueradeTestCase(SharedModuleStoreTestCase, LoginEnrollmentTestCase):
|
||||
@@ -280,6 +281,30 @@ class TestStaffMasqueradeAsSpecificStudent(StaffMasqueradeTestCase, ProblemSubmi
|
||||
"""
|
||||
return json.loads(self.look_at_question(self.problem_display_name).content)['progress_detail']
|
||||
|
||||
@patch.dict('django.conf.settings.FEATURES', {'DISABLE_START_DATES': False})
|
||||
def test_masquerade_as_specific_user_on_self_paced(self):
|
||||
"""
|
||||
Test masquerading as a specific user for course info page when self paced configuration
|
||||
"enable_course_home_improvements" flag is set
|
||||
|
||||
Login as a staff user and visit course info page.
|
||||
set masquerade to view same page as a specific student and revisit the course info page.
|
||||
"""
|
||||
# Log in as staff, and check we can see the info page.
|
||||
self.login_staff()
|
||||
response = self.get_course_info_page()
|
||||
self.assertEqual(response.status_code, 200)
|
||||
content = response.content
|
||||
self.assertIn("OOGIE BLOOGIE", content)
|
||||
|
||||
# Masquerade as the student,enable the self paced configuration, and check we can see the info page.
|
||||
SelfPacedConfiguration(enable_course_home_improvements=True).save()
|
||||
self.update_masquerade(role='student', user_name=self.student_user.username)
|
||||
response = self.get_course_info_page()
|
||||
self.assertEqual(response.status_code, 200)
|
||||
content = response.content
|
||||
self.assertIn("OOGIE BLOOGIE", content)
|
||||
|
||||
@patch.dict('django.conf.settings.FEATURES', {'DISABLE_START_DATES': False})
|
||||
def test_masquerade_as_specific_student(self):
|
||||
"""
|
||||
|
||||
@@ -727,7 +727,7 @@ def course_info(request, course_id):
|
||||
# Get the URL of the user's last position in order to display the 'where you were last' message
|
||||
context['last_accessed_courseware_url'] = None
|
||||
if SelfPacedConfiguration.current().enable_course_home_improvements:
|
||||
context['last_accessed_courseware_url'] = get_last_accessed_courseware(course, request)
|
||||
context['last_accessed_courseware_url'] = get_last_accessed_courseware(course, request, user)
|
||||
|
||||
now = datetime.now(UTC())
|
||||
effective_start = _adjust_start_date_for_beta_testers(user, course, course_key)
|
||||
@@ -742,16 +742,16 @@ def course_info(request, course_id):
|
||||
return render_to_response('courseware/info.html', context)
|
||||
|
||||
|
||||
def get_last_accessed_courseware(course, request):
|
||||
def get_last_accessed_courseware(course, request, user):
|
||||
"""
|
||||
Return the URL the courseware module that this request's user last
|
||||
accessed, or None if it cannot be found.
|
||||
Return the courseware module URL that the user last accessed,
|
||||
or None if it cannot be found.
|
||||
"""
|
||||
field_data_cache = FieldDataCache.cache_for_descriptor_descendents(
|
||||
course.id, request.user, course, depth=2
|
||||
)
|
||||
course_module = get_module_for_descriptor(
|
||||
request.user, request, course, field_data_cache, course.id, course=course
|
||||
user, request, course, field_data_cache, course.id, course=course
|
||||
)
|
||||
chapter_module = get_current_child(course_module)
|
||||
if chapter_module is not None:
|
||||
|
||||
Reference in New Issue
Block a user