-fix TNL-3556 Instructor tool "View as Specific Student" doesn't work on the course updates page.
-Added test for TNL-3556.
This commit is contained in:
@@ -277,7 +277,7 @@ class CoursesRenderTest(ModuleStoreTestCase):
|
||||
|
||||
def test_get_course_info_section_render(self):
|
||||
# Test render works okay
|
||||
course_info = get_course_info_section(self.request, self.course, 'handouts')
|
||||
course_info = get_course_info_section(self.request, self.request.user, self.course, 'handouts')
|
||||
self.assertEqual(course_info, u"<a href='/c4x/edX/toy/asset/handouts_sample_handout.txt'>Sample</a>")
|
||||
|
||||
# Test when render raises an exception
|
||||
@@ -285,7 +285,7 @@ class CoursesRenderTest(ModuleStoreTestCase):
|
||||
mock_module_render.return_value = mock.MagicMock(
|
||||
render=mock.Mock(side_effect=Exception('Render failed!'))
|
||||
)
|
||||
course_info = get_course_info_section(self.request, self.course, 'handouts')
|
||||
course_info = get_course_info_section(self.request, self.request.user, self.course, 'handouts')
|
||||
self.assertIn("this module is temporarily unavailable", course_info)
|
||||
|
||||
def test_get_course_about_section_render(self):
|
||||
@@ -315,7 +315,7 @@ class XmlCoursesRenderTest(ModuleStoreTestCase):
|
||||
request = get_request_for_user(UserFactory.create())
|
||||
|
||||
# Test render works okay. Note the href is different in XML courses.
|
||||
course_info = get_course_info_section(request, course, 'handouts')
|
||||
course_info = get_course_info_section(request, request.user, course, 'handouts')
|
||||
self.assertEqual(course_info, "<a href='/static/toy/handouts/sample_handout.txt'>Sample</a>")
|
||||
|
||||
# Test when render raises an exception
|
||||
@@ -323,7 +323,7 @@ class XmlCoursesRenderTest(ModuleStoreTestCase):
|
||||
mock_module_render.return_value = mock.MagicMock(
|
||||
render=mock.Mock(side_effect=Exception('Render failed!'))
|
||||
)
|
||||
course_info = get_course_info_section(request, course, 'handouts')
|
||||
course_info = get_course_info_section(request, request.user, course, 'handouts')
|
||||
self.assertIn("this module is temporarily unavailable", course_info)
|
||||
|
||||
|
||||
|
||||
@@ -41,6 +41,11 @@ class MasqueradeTestCase(ModuleStoreTestCase, LoginEnrollmentTestCase):
|
||||
# working properly, we must use start dates and set a start date in the past (otherwise the access
|
||||
# checks exist prematurely).
|
||||
self.course = CourseFactory.create(number='masquerade-test', metadata={'start': datetime.now(UTC())})
|
||||
# Creates info page and puts random data in it for specific student info page test
|
||||
self.info_page = ItemFactory.create(
|
||||
category="course_info", parent_location=self.course.location,
|
||||
data="OOGIE BLOOGIE", display_name="updates"
|
||||
)
|
||||
self.chapter = ItemFactory.create(
|
||||
parent_location=self.course.location,
|
||||
category="chapter",
|
||||
@@ -89,6 +94,18 @@ class MasqueradeTestCase(ModuleStoreTestCase, LoginEnrollmentTestCase):
|
||||
)
|
||||
return self.client.get(url)
|
||||
|
||||
def get_course_info_page(self):
|
||||
"""
|
||||
Returns the server response for course info page.
|
||||
"""
|
||||
url = reverse(
|
||||
'info',
|
||||
kwargs={
|
||||
'course_id': unicode(self.course.id),
|
||||
}
|
||||
)
|
||||
return self.client.get(url)
|
||||
|
||||
def _create_mock_json_request(self, user, body, method='POST', session=None):
|
||||
"""
|
||||
Returns a mock JSON request for the specified user
|
||||
@@ -298,6 +315,24 @@ class TestStaffMasqueradeAsSpecificStudent(StaffMasqueradeTestCase, ProblemSubmi
|
||||
self.login_student()
|
||||
self.assertEqual(self.get_progress_detail(), u'2/2')
|
||||
|
||||
@patch.dict('django.conf.settings.FEATURES', {'DISABLE_START_DATES': False})
|
||||
def test_masquerade_as_specific_student_course_info(self):
|
||||
"""
|
||||
Test masquerading as a specific user for course info page.
|
||||
|
||||
We login with login_staff and check course info page content if it's working and then we
|
||||
set masquerade to view same page as a specific student and test if it's working or not.
|
||||
"""
|
||||
# Log in as staff, and check we can see the info page.
|
||||
self.login_staff()
|
||||
content = self.get_course_info_page().content
|
||||
self.assertIn("OOGIE BLOOGIE", content)
|
||||
|
||||
# Masquerade as the student, and check we can see the info page.
|
||||
self.update_masquerade(role='student', user_name=self.student_user.username)
|
||||
content = self.get_course_info_page().content
|
||||
self.assertIn("OOGIE BLOOGIE", content)
|
||||
|
||||
|
||||
@attr('shard_1')
|
||||
class TestGetMasqueradingGroupId(StaffMasqueradeTestCase):
|
||||
|
||||
@@ -1152,7 +1152,7 @@ class TestHtmlModifiers(ModuleStoreTestCase):
|
||||
|
||||
def test_get_course_info_section(self):
|
||||
self.course.static_asset_path = "toy_course_dir"
|
||||
get_course_info_section(self.request, self.course, "handouts")
|
||||
get_course_info_section(self.request, self.request.user, self.course, "handouts")
|
||||
# NOTE: check handouts output...right now test course seems to have no such content
|
||||
# at least this makes sure get_course_info_section returns without exception
|
||||
|
||||
|
||||
Reference in New Issue
Block a user